Being an unabashedly lazy bastard I would just use something like Mail::Builder, Mail::Sender, Mail::Sender::Easy. Why grovel in the bits-and-bytes of SMTP when someone else has done it for you, and done it so very well? (At the very least, look at their source code and steal how they did it.)