Timothy E. Archer

System.out.println("Hello World!");

Browsing Posts tagged javamail

Last night I presented my article discussing how to use JavaMail to check a POP3 mail account and retrieve its messages. Tonight I am going to follow that up with a summary of my EmailDelivery class. This is a simple class I wrote to help me easily send emails from my Java applications. A few highlights of the class are that it:

  • Supports relaying through SMTP servers that require authentication.
  • Has convenience methods for easily adding file attachments.
  • Has a method to set the message priority (high, normal, low).
  • Allows you to easily set the to, from, cc, and bcc email addresses. Also supports passing in a comma separated list into any of these methods and have it parsed automatically for easy sending to multiple recipients.
  • Allows you to easily add header name/value pairs in the message.
  • Suppports easily setting the value stored in the Message-ID header tag of the message.

continue reading…

Recently I wrote a java daemon process that monitors a POP3 email box for messages, automatically downloads the messages, and then processes them. Basically my daemon process looks for returned and bounced emails in a POP3 mailbox and then updates certain flags in our ERP system so we don’t send to that email address again. In some cases people reply to the messages our ERP system sends out, and in that case my daemon process forwards those messages to an appropriate user for manual review and handling.

I’m not going to go into the details of how this daemon process work since it goes far beyond the scope of this post (and it is a huge piece of software in itself). However, I am going to share the basic java class that I use to check the POP3 mail account, download messages, and then loop through them for processing.

For this example to work, you will need to download the JavaBeans Activation Framework, and the Javamail libraries. Unzip the downloaded archives and put the appropriate jar file into your classpath. This example was tested with JavaMail 1.3.1 (mail-1.3.1.jar) and the Javabeans Activation Framework 1.0.2 (activation-1.0.2.jar).

My example also uses Log4j to log its output. If you don’t want to configure log4j, then replace all of my log.info and log.debug calls with a call to System.out.println.

Once you get your classpath setup, take the class I present below and compile it. The only thing you’ll have to modify to run the example is a few lines in the main() method. Once you get that running, you should be able to take the code, pick it apart, and make it do what you need for your own applications.
continue reading…

Powered by WordPress Web Design by SRS Solutions © 2013 Timothy E. Archer Design by SRS Solutions