datawookie/emayili

[FEAT]: email error log/switch

kenkoonwong opened this issue · 1 comments

Description

Hi,

Thanks for this awesome package! I'm not sure about you but sometimes I have intermittent problem sending email due to gmail server issue. Username and password are correct and most of the time the emails get sent, but occasionally it doesn't. Maybe it's my internet or maybe it's something else.

Is there a way to setup a switch/code to return whether email was sent or not... so that I can write another code to resend it after x amount of time.

Thoughts?

thanks

ken

Hi @kenkoonwong,

Maybe it's my internet or maybe it's something else.

Well, I'm pretty sure that it's not a problem with {emayili}! 😄

I have replicated an internet issue and then tried to send an email. This is what happened:

> smtp(msg, verbose = TRUE)
DEBUG   [2023-04-12 06:19:56.053] Sending email to smtp://smtp.gmail.com:587/.
Found bundle for host: 0x5609ba92f9d0 [serially]
Re-using existing connection #0 with host smtp.gmail.com
server response timeout
QUIT
server response timeout
Closing connection 0
Error in curl_fetch_memory(smtp_server, handle = h) : 
  Timeout was reached: [smtp.gmail.com:587] server response timeout

You can see that if it's unable to make a connection to the server then it raises an error. You can catch this error and handle it in your code. This would be the approach taken to handle failure in any other function.

However, {emayili} has a builtin approach to handle this situation via the max_times and pause_base arguments, which apply exponential backoff if a message fails to be sent. I set max_times = 1 to get the above output. If you set it to a larger value then {emayili} will automatically attempt to resend the email. I believe that this would help you mitigate intermittent network problems.

Regards, Andrew.