Sending Emails with Attachments

Sending emails with attachments is simply a matter of creating a multi-part email. The first part will be the email itself and subsequent parts will be the attachments. Each attachment will be MIME encoded so that binary, as well as textual, data can be sent with the message. Listing 11.5 shows an example of a multi-part email with a MIME header and footer that identifies the attached part of the message.

Listing 11.5. Email with MIME Attachment
 Return-Path: <agency@localhost> Received: from localhost ([127.0.0.1]) by XXXX (JAMES SMTP Server 2.1) with SMTP ID 788 for <juliet@localhost>; Thu, 8 Jan 2004 10:04:33 +0000 (GMT) Message-ID: <12014584.1073556273610.JavaMail.xx@XXXX> From: agency To: juliet@localhost ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.