My program works with a small number of messages, but with a large number it fails with the message
"Failed to connect to mailserver at..."
Then some iterations later it gets one through, and then fails again.
I saw a suggestion to open the SMTP server once for the whole program, instead of mail() doing it repeatedly, but I have no idea how to do that.

