Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials

jGuru: Fundamentals of the JavaMail API

 


[Help | API Docs | Short Course| Exercises]

In this exercise, create a program that creates a canned reply message and attaches the original message if it's plain text.

Prerequisites

Skeleton Code

Tasks


  1. The skeleton code already includes the code to get the list of messages from the folder and prompt you to create a reply.

  2. When answered affirmitively, create a new MimeMessage from the original message.

  3. Set the from field to your email address.

  4. Create the text for the reply. Include a canned message to start. When the original message is plain text, add each line of the original message, prefix each line with the "" characters.

  5. Set the message's content, once the message content is fully determined.

  6. Send the message.

  7. Compile and run the program, passing your mail server, SMTP server, username, password, and from address on the command line. Answer YES to the messages you want to send replies. Just hit ENTER if you don't. If you want to stop going through your mail before making your way through all the messages, enter QUIT.

  8. 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 mail server, SMTP server, username, password, and from address):

java ReplyExample POP.Server SMTP.Server username 
    password from@address

You'll be prompted to reply to each of the messages in your INBOX. Enter YES to have a reply sent.

0: president@whitehouse.gov     Thanks.
Do you want to reply to the message? [YES to reply/QUIT to end]
YES
1: billg@microsoft.com     No Thanks.
Do you want to reply to the message? [YES to reply/QUIT to end]
YES
..

Next Exercise

Exercises

About This Short Course

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