rstudio / blastula

Easily send great-looking HTML email messages from R
https://pkgs.rstudio.com/blastula
Other
548 stars 85 forks source link

Determine that mail has been sent successfully #253

Open domsle opened 3 years ago

domsle commented 3 years ago

Is there a way to determine that the email has been sent successfully? The smpt_send function does not return any value. Maybe this should be tweaked?

jnolis commented 3 years ago

I agree that this it would be great to have smtp_send() return a value for if it's successful or not (and I ended up on this issue since I have the same problem myself).

Digging into the code, it looks like in the event that smtp_send isn't successful it will stop with an error, so you could use a try catch as a workaround for now. In this example result is TRUE or FALSE depending on if the send was successful. Hope this helps!

result <- tryCatch({
    test_message %>%
      smtp_send(
        ...
      )
    TRUE
  },
  error=function(cond) FALSE
)
rich-iannone commented 3 years ago

I do like the idea of returning a logical (and always returning something once getting to curl::send_mail(), thanks @jnolis for the code example). This will be changed in smtp_send() but for now this workaround is really good.