Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andresimi opened this issue Jan 10, 2023 · 6 comments
Open

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

andresimi opened this issue Jan 10, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@andresimi
Copy link

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

@andresimi andresimi added the bug Something isn't working label Jan 10, 2023
@andresimi andresimi changed the title [BUG]: [BUG]: can't send email through shiny Jan 10, 2023
@datawookie
Copy link
Owner

@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
Copy link
Owner

You might also find this blog post useful.

@andresimi
Copy link
Author

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
Copy link
Owner

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

@andresimi
Copy link
Author

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
Copy link
Owner

Please provide your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants