# WebObjects/Project WONDER/Frameworks/ERJavaMail
### Overview

ERJavaMail provides a simple and powerful API for sending component-based emails from a WebObjects application. ERJavaMail does not depend on any other pieces of Project Wonder, and is a good way to get your feet wet using Wonder.

### Configuration

* er.javamail.centralize = true
Centralize sends all emails to the er.javamail.adminEmail user.
* er.javamail.debugEnabled = true
Determines whether or not email debugging is displayed. This contains protocol-level debug information.
* er.javamail.adminEmail = user@domain.com
The email address of the admin user to send centralized emails to. This is a required property.
* er.javamail.smtpHost = smtp.domain.com
The SMTP host name to use. If this isn't set, mail.smtp.host will be checked and ultimately WOHost will be used.
* er.javamail.senderQueue.size = 50
The number of messages that the sender queue can hold. Defaults to 50.
* er.javamail.milliSecondsWaitIfSenderOverflowed = 6000
The number of milliseconds to wait if the sender queue is full. Default is 6000.
* er.javamail.smtpAuth = true
Sets whether or not Authenticated SMTP is used to send outgoing mail. If set, er.javamail.smtpUser MUST also be set (and preferably er.javamail.smtpPassword).
* er.javamail.smtpUser = smtpusername
The username to use to login to the authenticated SMTP server.
* er.javamail.smtpPassword = smtppassword
The password to use to login to the authenticated SMTP server.
* er.javamail.XMailerHeader =
The X-Mailer header to put into all outgoing mail messages. Defaults to nothing.
* er.javamail.defaultEncoding = UTF-8
The default character encoding to use for message content. Defaults to ???.
* er.javamail.WhiteListEmailAddressPatterns =
A comma-separated list of whitelisted email address patterns. If set, then only addresses that match one of the whitelisted patterns will delivered to. Pattern syntax is the same as EOQualifier's caseInsensitiveLike.
* er.javamail.BlackListEmailAddressPatterns =
A comma-separated list of blacklisted email address patterns. If set, then any email addresses that match a blacklist pattern will not be delivered to. Pattern syntax is the same as EOQualifier's caseInsensitiveLike. The blacklist filter is processed last, so a blacklist pattern beats a whitelist pattern.

### Example of sending Mail with Attachments

The subclasses of ERMailDelivery will not only deliver the mail for you, but also will create the message. So ERMailDelivery is in some way more like a message than a delivery mechanism. For each message you want to sent instantiate a concrete subclass of ERMailDelivery (e.g. ERMailDeliveryPlainText). You can then add attachments to it. Below a simple code snippet sending of a mail with an attachment. The MimeType of the attachment is parsed out of the extension of the filename.
Sending mail is per default asynchronous, you can specify a flag (true == shouldBlock, false == should not block) to influence the behaviour.

### Gotchas

Be careful of the WOContext that contains the component you are sending. If you use ERMailDeliveryHTML inside of the normal request-response loop with the default WOContext, it is very likely that the next page that is sent to the user will be the emailed component rather than the page you WANTED to send. There are several possible workarounds for this. One is to return a specific component rather than null from your action method. I have had better and more consistent success with the following code:
This seems to properly isolate the email to a clone of the current context rather than the actual active context. Your mileage may vary.