Sending E-mails with Attachments

In the previous example, you used MIME multi-part messages to send a HTML message that displays an image. Another use of MIME is to send message attachments, such as MPEG videos, JPEG images, and plain text files. In this example, you will create a small command line application that sends a message with an attached XML file to a named recipient.

The code for this application is very similar to the previous applications. Today's lesson only explores those sections of code that differ from the previous examples, but you can still find a full listing at the end of this section or on the CD-ROM that accompanies this book.

This application starts by creating Properties, Session, and MimeMessage objects. It also adds ...

Get Sams Teach Yourself J2EE™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.