#The following works fine:
library(httr) #http
library(emayili) #email
library(stringr) #string manipulation
smtp_server <- Sys.getenv("SMTP_SERVER")
smtp_port <- Sys.getenv("SMTP_PORT")
smtp_username <- Sys.getenv("SMTP_USERNAME")
IP <- content(GET("https://api.ipify.org?format=json"))$ip
smtp <- server(
host = smtp_server,
port = smtp_port,
username = smtp_username,
password = Sys.getenv("SMTP_PASSWORD"),
max_times = 1
)
envelope(
to = "[email protected]",
from = smtp_username,
subject = str_c("This is a plain text message!", IP, Sys.time()),
text = "Hello!"
) |>
smtp()
#The following results in a fatal error though, aborting the r Studio session
library(shiny)
library(httr)
library(emayili)
smtp_server <- Sys.getenv("SMTP_SERVER")
smtp_port <- Sys.getenv("SMTP_PORT")
smtp_username <- Sys.getenv("SMTP_USERNAME")
IP <- content(GET("https://api.ipify.org?format=json"))$ip
smtp <- server(
host = smtp_server,
port = smtp_port,
username = smtp_username,
password = Sys.getenv("SMTP_PASSWORD"),
max_times = 1
)
ui <- fluidPage(
titlePanel("{emayili} & Shiny"),
tags$head(
tags$style(HTML("
body {
background-color: black;
color: white;
}
td {
padding-left: 10px;
}
"))
),
fluidRow(
column(
width = 6,
tags$table(
tags$tr(
tags$th("{emayili version}:"),
tags$td(as.character(packageVersion("emayili")))
),
tags$tr(
tags$th("IP address:"),
tags$td(IP)
),
tags$tr(
tags$th("SMTP server:"),
tags$td(smtp_server)
),
tags$tr(
tags$th("SMTP port:"),
tags$td(smtp_port)
)
)
),
column(
width = 6,
class = "text-center",
actionButton(
"send",
"Send Message",
icon = icon("envelope"),
class = "btn-primary"
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$send, {
message("Sending message to ", smtp_username, ".")
envelope(
to = smtp_username,
from = smtp_username,
subject = strftime(Sys.time(), "{emayili} & Shiny [%F %X]")
) %>%
text("This message was sent from Shiny on {{ IP }} using {emayili}.") %>%
smtp()
})
}
shinyApp(ui = ui, server = server)
#Both use the same .Renviron file.
#R 4.4, R Studio 2024.04.2 Build 764
Running the script works ok, but the shiny app crashes.
I tried reinstalling R and reinstalling all libraries.
I have a large app that sends results to the user using emayily. This worked flawlessly until lately, also when deployed on shinyapps.io. Now, it crashes, and I managed to isolate it. Sending the mail from the app, locally on my macbook Apple M3 Pro, 36GB results in the error. The deployed version works fine.
Peter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.