There are a whole host of email handling packages on CPAN, and they really are the easiest way.
If you don't want to use modules, you're asking for a World of Pain, but the RFCs are there to help.
Look at RFCs 822 and more importantly 2822 for a detailed description of Internet Messages (i.e. email).
Once again, I really suggest you use the robust modules from CPAN, rather than try it yourself.
If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>