In my app, I need to send a confirmation e-mail to some customers every time some operation is finished.
How should I design, or what's best practice, the logic behind the smtp connection?
Should I connect authenticate the mail account and keep this connection open while the app is running (sometimes a couple of hours, with sometimes 20-30 minutes without any mail
Or should I close connection every time a mail is sent? Eventhough a mail can be sent multiple times a second on some operations...
I'm sending mails simply by telnetting to a remote webserver mail app. This app can be used be multiple users at the same time using the same e-mail account.
So I need advice from people with experience in smtp behaviour and habits, How does a simple mail app works on this point?
You may keep SMTP connections open for a few minutes.
e.g. Default Sendmail configuration caches 2 connections for up to 5 minutes when processing queued messages. Sendmail issues RSET
command to check cached connections before reuse. Issuing RSET
is a good way to reset SMTP session to known state.