Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials

jGuru: Fundamentals of the JavaMail API

 


[Help | API Docs | Short Course| Exercises]

In the last exercise you sent a mail message using the demonstration program provided with the JavaMail implementation. In this exercise, you'll create the program yourself.

Prerequisites

Skeleton Code

Tasks


  1. Starting with the skeleton code, get the system Properties.

  2. Add the name of your SMTP server to the properties for the mail.smtp.host key.

  3. Get a Session object based on the Properties.

  4. Create a MimeMessage from the session.

  5. Set the from field of the message.

  6. Set the to field of the message.

  7. Set the subject of the message.

  8. Set the content of the message.

  9. Use a Transport to send the message.

  10. Compile and run the program, passing your SMTP server, from address, and to address on the command line.

  11. Check to make sure you received the message with your normal mail reader (Eudora, Outlook Express, pine, ...).

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

After executing the following command (replacing the email addresses and specifying your SMTP server):

java MailExample SMTP.Server from@address to@address

your program will send a mail message.

Next Exercise

Exercises

About This Short Course

Copyright 1996-2001 jGuru.com. All Rights Reserved.