blastula icon indicating copy to clipboard operation
blastula copied to clipboard

Determine that mail has been sent successfully

Open domsle opened this issue 3 years ago • 2 comments

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?

domsle avatar Feb 24 '21 09:02 domsle

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
)

jnolis avatar Mar 13 '21 17:03 jnolis

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.

rich-iannone avatar Mar 16 '21 19:03 rich-iannone