Bulk mail server times out - Best way to keep trying

I have a go program that sends a personalised email with a password protected attachment from a long list of recipients.
The smtp server throws an error every so often causing the program to panic, so not all mails are sent.
Can anyone suggest the best way to queue the mails so that the program keeps trying without just failing midway through execution.

How are you currently queuing the mails?

Does “panic” mean crashing or? You should be able to handle broken connections without crash, so just retry again after some time. Maybe you have some rate limiter on the SMTP server, so some wait time between mails may help.

1 Like

Not currently queueing, just panics if an error is thrown after DialandSend

Not currently queueing, just panics if an error is thrown after DialandSend. Have tried putting in a delay, and retrying a few times after error is thrown.

Handle the error instead of panicing, and retry those mails later? You should not have panics in your code, unless it’s something fatal at start up and even then you would probably want to handle the error to present a better error message to your users.

2 Likes

Have a look at exponential backoff algorithms - here is an article I found:

backoff and retry in go

And a few Go packages (sorted by Github stars—I have not used any of them yet so the stars are the best indicator I can provide.).

1 Like

Thanks for this suggestion! I will try it out and let you know…

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.