datawookie / emayili

An R package for sending email messages.
https://datawookie.github.io/emayili/
176 stars 26 forks source link

[BUG]: can't send email through shiny #144

Open andresimi opened 1 year ago

andresimi commented 1 year ago

Description of the bug

I want to create a shinyapp that sends a report via email. However I am not being able to do so. So i tried this simple code to test and it isn't working when I run the app. It works if I run the code or in normal r studio session.

I am getting this error in the console:

runApp()

Listening on http://127.0.0.1:5287
Warning: Error in server: unused arguments (host = "smtp.gmail.com", port = 465, username = "username", password = "password")
  1: runApp

Than you very much!

Steps To Reproduce

library(shiny); library(emayili)

# Define UI for application that draws a histogram
ui <- fluidPage(

  titlePanel("Emayili Shiny test"),

  sidebarLayout(
    sidebarPanel(
      actionButton("SendEmail", "Send Email"),
    ),

    mainPanel(
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  observeEvent(input$SendEmail,{
    smtp <- server(
      host = "smtp.gmail.com",
      port = 465,
      username = "myemail",
      password = "pass"
    )

    emayili<- envelope()
    emayili<- emayili%>%
      from("my gmail account") %>%
      to("recipient")%>% 
      subject(paste("Test email"))%>% 
      text("I can now deploy my app to shinyapps.io")

    smtp(emayili, verbose = TRUE)
  })

}

# Run the application 
shinyApp(ui = ui, server = server)

Additional Information

Fedora 37 R version 4.2.2 (2022-10-31) emayili 0.7.13 shiny 1.7.4

datawookie commented 1 year ago

@andresimi please try changing your call server() to emayili::server(). The problem with your existing code is that you have a global variable called server which is smashing the server() function defined in {emayili}.

datawookie commented 1 year ago

You might also find this blog post useful.

andresimi commented 1 year ago

Oh Great! Thanks. At least now I know it is possible to send emails. However, I would like to build reactive report. Is that possible? When I change observeEvent to reactiveEvent it not work.

datawookie commented 1 year ago

@andresimi this seems to be a Shiny issue rather than an {emayili} issue.

andresimi commented 1 year ago

Ok, but I am not sure what is the issue: If I interpolate text body like "{{greetings_text()}}" is it supposed to work with observeEvent or it should be possible to work with reactiveEvent?

datawookie commented 1 year ago

Please provide your code.