WebObjects/Web Applications/Development/Sending Emails

Overview
Sending emails is a very common requirement in a web application. There are several methods you can choose from, each with varying levels of complexity and power.

JavaMail
JavaMail is Sun's API definition and open-source reference implementation of various methods of sending and receiving mail. All of the other WO mail-sending techniques are based on JavaMail, but you can choose to use it directly rather than use the higher level API's described below. If you would like to use JavaMail on your own, you will need to download and install the following jars and put them into your WOA's classpath:


 * JavaMail
 * Java Activation Framework

WOMailDelivery
Built into WebObjects is the WOMailDelivery class. It provides a very simple API for sending mails, but lacks the power of Project Wonder's version. To use WOMailDelivery, you will need to set your SMTP server in one of the following ways:


 * Add -DWOSMTPHost=smtp.yourmailserver as a launch parameter
 * Set WOSMTPHost=smtp.yourmailserver.com in your Properties file
 * Hardcode it with WOApplication.application.setSMTPHost("smtp.yourmailserver.com");

Refer to the WOMailDelivery API for more information, but to simply send an email, you can use the following command:

WOMailDelivery.sharedInstance.composePlainTextEmail(   fromAddress,    toAddresses,    bccAddresses,    subject,    body,    WOMailDelivery.SEND_NOW );

By default, WOMailDelivery with use Sun's old SMTP implementation. However, if you install JavaMail (as described above) into your WOA or /Library/WebObjects/Extensions, WOMailDelivery will use it instead.

ERJavaMail
ERJavaMail is part of Project Wonder and provides an API for sending component-based emails. ERJavaMail also uses the JavaMail API's underneath, but it includes the jars inside its framework, so you don't need to manually install JavaMail to use it. Because it does not have any external dependencies on other Project Wonder frameworks, you can use it without bringing in any other Project Wonder frameworks. For more information on ERJavaMail, see the ERJavaMail page.