How do I send an email in a shiny app in R?

333 Views Asked by At

I'm trying to send an email from my shiny app using the library mailR. My code is:

      send.mail(from,to,subject=subject,body=msg,smtp=
list(host.name = "smtp.gmail.com",port=465,user.name="name",passwd='psswd',ssl=TRUE),
authenticate = TRUE, send=TRUE)

(from,to,name,password... are not shown for privacy reasons).

When I run this code, I get the following error:

Error mailR

Can anyone help me?

1

There are 1 best solutions below

10
rEbbasta On

After many tries I think that the best option is sending emails using "emayili" through a mailgun account

library(shiny)
library(emayili)


ui <- fluidPage(

actionButton("buttonId", "Send email")

)

server <- function(input, output, session) {

observeEvent(input$buttonId, {
    
    smtp <- emayili::mailgun(
        username = "SMTP username ([email protected])",
        password = "SMTP password"
    )
    
    emayili <- envelope()
    emayili <- emayili %>%
        from("sender_email") %>%
        to("receiver_email") %>%
        subject("subject here") %>%
        text("text here")
    
    smtp(emayili, verbose = TRUE)

   })
}

shinyApp(ui, server)