datawookie / emayili

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

app works great when deployed, but crashes on my mac (fatal error, aborted) #156

Closed pieterprins2 closed 4 months ago

pieterprins2 commented 4 months ago

Hello, I have the following app, which I got from the emayili package. My question is, it runs fine when deployed, but why does it crash on my mac? (I use emayili in a larger app to send mail to the user with a report attached. But the following reproduces the same error. This makes further development very difficult)

Here is the code I use both locally and on shinyapps.io. As said, it crashes on my mac, but works great when deployed.

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 <- emayili::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, ".") emayili::envelope( to = smtp_username, from = smtp_username, subject = strftime(Sys.time(), "{emayili} & Shiny [%F %X]") ) %>% emayili::text("This message was sent from Shiny on {{ IP }} using {emayili}.") %>% smtp(verbose = TRUE) }) }

shinyApp(ui = ui, server = server)

datawookie commented 4 months ago

Hi @pieterprins2, I'm happy to try and help debug this. However, I do not work on a Mac and without further information about the "crash" it's hard for me to know where to start. Please can you add a stack trace to your issue? Thanks, Andrew.

pieterprins2 commented 4 months ago

Hi Andrew, thanks for taking a look. I'd love to send you a "stack trace", but how do I do that?

pieterprins2 commented 4 months ago

In the console, first time run: Listening on http://127.0.0.1:3800 Sending message to pieterprins2@gmail.com. Host smtp.gmail.com:587 was resolved. IPv6: (none) IPv4: 142.250.102.109 Trying 142.250.102.109:587... Connected to smtp.gmail.com (142.250.102.109) port 587 220 smtp.gmail.com ESMTP a640c23a62f3a-a77b2b3a412sm61530266b.204 - gsmtp EHLO macbook-pro 250-smtp.gmail.com at your service, [77.173.87.132] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 STARTTLS 220 2.0.0 Ready to start TLS (304) (OUT), TLS handshake, Client hello (1): (304) (IN), TLS handshake, Server hello (2): (304) (IN), TLS handshake, Unknown (8):(304) (IN), TLS handshake, Certificate (11): (304) (IN), TLS handshake, CERT verify (15): (304) (IN), TLS handshake, Finished (20): (304) (OUT), TLS handshake, Finished (20): SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF Server certificate: subject: CN=smtp.gmail.com start date: Jun 13 16:29:38 2024 GMT expire date: Sep 5 16:29:37 2024 GMT subjectAltName: host "smtp.gmail.com" matched cert's "smtp.gmail.com" issuer: C=US; O=Google Trust Services; CN=WR2 SSL certificate verify ok. EHLO macbook-pro 250-smtp.gmail.com at your service, [77.173.87.132] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 AUTH PLAIN 334 AHBpZXRlcnByaW5zMkBnbWFpbC5jb20AdG5qandqcG9jdnNsaGZ1cg== 235 2.7.0 Accepted MAIL FROM:pieterprins2@gmail.com 250 2.1.0 OK a640c23a62f3a-a77b2b3a412sm61530266b.204 - gsmtp RCPT TO:pieterprins2@gmail.com 250 2.1.5 OK a640c23a62f3a-a77b2b3a412sm61530266b.204 - gsmtp DATA 354 Go ahead a640c23a62f3a-a77b2b3a412sm61530266b.204 - gsmtp Uploaded 618 bytes...Date: Thu, 04 Jul 2024 09:28:32 GMT X-Mailer: {emayili}-0.9.1 MIME-Version: 1.0 To: pieterprins2@gmail.com From: pieterprins2@gmail.com Subject: {emayili} & Shiny [2024-07-04 11:28:32] Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-MD5: aLk4TPSNmzYml1KoKayaTg==

Uploaded 618 bytes... all done!y on 77.173.87.132 using {emayili}. 250 2.0.0 OK 1720085313 a640c23a62f3a-a77b2b3a412sm61530266b.204 - gsmtp Connection #3 to host smtp.gmail.com left intact

Second time it crashes (Session aborted, the popup with the bomb in it)

datawookie commented 4 months ago

@pieterprins2 please take a look at this: https://stat.ethz.ch/R-manual/R-patched/RHOME/library/base/html/traceback.html.

pieterprins2 commented 4 months ago

Thanks, it returns NULL, maybe because I can only hit "Start new session" after the crash with the popup with the bomb ... and the new session is empty and doesn't have the history.

pieterprins2 commented 4 months ago

just using a local script works well by the way, like:

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 = "pieterprins2@gmail.com", from = "pieterprins2@gmail.com", subject = str_c("This is a plain text message!", IP, Sys.time()), text = "Hello!" ) |> smtp()

datawookie commented 4 months ago

Try putting this into your ~/.Rprofile:

options(
        error = rlang::entrace,
        rlang_backtrace_on_error = "branch",
        tidyverse.quiet = TRUE
)

That should automatically dump a stack trace on error.

pieterprins2 commented 4 months ago

Great I'll try right away

pieterprins2 commented 4 months ago

Where can I find the stack trace? rlang::last_error() gives Error: Can't show last error because no error was recorded yet. Of course this is after the restart.

datawookie commented 4 months ago

I missed this before:

Second time it crashes (Session aborted, the popup with the bomb in it)

Do you mean that RStudio itself crashes? Hmmm. That's probably not an {emayili} issue then.

Please try running the app outside of RStudio. Suppose it's called app.R then you can run it from the console like this:

Rscript shiny.R

Once running it will give you the URL to open in your browser (port will be different):

Listening on http://127.0.0.1:6140
pieterprins2 commented 4 months ago

Yes RStudio crashes, this is the popup when it crashes.

Screenshot 2024-07-04 at 11 03 04 AM

I'll try to run it outside of Rstudio, never heard of that. Thanks again!

pieterprins2 commented 4 months ago

Hello Andrew,

I tried running Rscript shiny.R in the Rstudio console, but it does not recognize the command.

Them I looked at this link from Rstudio (Posit as it's called now): https://support.posit.co/hc/en-us/articles/200554776-RStudio-Desktop-IDE-crash-reports

I did as it suggests: it runs the app with emayili as it should, but when I run it afterwards it crashes again, so there is no crash log.

I'm at a loss.

Pieter On Friday, July 5, 2024 at 07:15:42 AM GMT+2, Andrew Collier @.***> wrote:

I missed this before:

Second time it crashes (Session aborted, the popup with the bomb in it)

Do you mean that RStudio itself crashes? Hmmm. That's probably not an {emayili} issue then.

Please try running the app outside of RStudio. Suppose it's called app.R then you can run it from the console like this: Rscript shiny.R Once running it will give you the URL to open in your browser (port will be different): Listening on http://127.0.0.1:6140 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

datawookie commented 4 months ago

Screenshot from 2024-07-06 05-15-04

pieterprins2 commented 4 months ago

Thanks Andrew. I got it working (listening) but unfortunately I don't see the window with the app in it. So I can't push the button. Any idea?  Thanks again. Pieter

datawookie commented 4 months ago

Post a screenshot of the terminal. You need to open in a browser window. The URL is given in terminal (see my screenshot).

datawookie commented 4 months ago

Hi @pieterprins2, I didn't get any further feedback from you on this, so I'm going to close the issue. Feel free to reopen it if you wish to continue debugging this issue. Thanks, Andrew.