A JavaMail Example

Let's walk through a simple example of sending a message using JavaMail.


The JavaMail API provides an interface to perform many more complex tasks, including sending MIME-encoded attachments to your mail. And, as we discussed earlier, you can retrieve and manipulate messages from your mailboxes. The demo code that accompanies JavaMail gives good examples of some of the other features that you can use. With a little creativity, you are not limited to what you can accomplish.

Listing 17.1 contains our JavaMail example.

Code Listing 17.1. SimpleSendMessage.java
 import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SimpleSendMessage { public static void main(String[] ...

Get Pure Java Server Pages™ 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.