When should I send QUIT to SMTP server? and how long should I keep a session?

networking, smtp, sockets

Solution

Connect, send X emails for target, disconnect. X should IMHO be somewhere around 16 to 64 - someemail servers dont like too many in one connection and will throw you out otherwise.

You should / can order by destination so you dont ahve to keep sessions open too long, and you MUST properly handle forced disconnects.

Use MX records as you please. There is no need to split your emails to multiple target servers.

Problem

I am programming a smtp sender to send large number of distinct emails (not spam). As there are many destination addresses which are from common provider like hotmail.com/gmail.com. I would like to pool the TCP connections in order to reuse the session. Is this a good practise? Or should I disconnect and connect to send distinct mails instead? As the subscribers are in large amount, the pooled connection might be kept for a long time (e.g. 1 hour), should I actively release the connection at some point? Last thing confused me is the destination IPs, as I find out that hotmail.com has a lot of mx servers(at least 12). Does it make any different if I send most of emails to only one of the server or separate them and send to all servers? Sorry to ask several questions at a time, and do appreciate your view and answer.

Original source