diff --git a/javadoc/developers/allclasses-frame.html b/javadoc/developers/allclasses-frame.html index 77dd333e6..e8ce3181a 100644 --- a/javadoc/developers/allclasses-frame.html +++ b/javadoc/developers/allclasses-frame.html @@ -1,45 +1,27 @@ - - - - - -All Classes (Simple Java Mail API) - - - - - - - - - - - -All Classes -
- - - - - -
AttachmentResource -
-Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-MailException -
-Recipient -
-TransportStrategy -
-
- - - + + + + +All Classes (Simple Java Mail API) + + + + + +

All Classes

+
+ +
+ + diff --git a/javadoc/developers/allclasses-noframe.html b/javadoc/developers/allclasses-noframe.html index 238b04729..f103fe479 100644 --- a/javadoc/developers/allclasses-noframe.html +++ b/javadoc/developers/allclasses-noframe.html @@ -1,45 +1,27 @@ - - - - - -All Classes (Simple Java Mail API) - - - - - - - - - - - -All Classes -
- - - - - -
AttachmentResource -
-Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-MailException -
-Recipient -
-TransportStrategy -
-
- - - + + + + +All Classes (Simple Java Mail API) + + + + + +

All Classes

+
+ +
+ + diff --git a/javadoc/developers/constant-values.html b/javadoc/developers/constant-values.html index af4602ed2..c4878cc45 100644 --- a/javadoc/developers/constant-values.html +++ b/javadoc/developers/constant-values.html @@ -1,250 +1,241 @@ - - - - - -Constant Field Values (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Constant Field Values

-
-
-Contents - - - - - - -
-org.codemonkey.*
- -

- - - - - - - - - - - - -
org.codemonkey.simplejavamail.Mailer
-private static final java.lang.StringCHARACTER_ENCODING"UTF-8"
- -

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
org.codemonkey.simplejavamail.MailException
-protected static final java.lang.StringGENERIC_ERROR"Generic error: %s"
-protected static final java.lang.StringINVALID_ENCODING"Encoding not accepted: %s"
-protected static final java.lang.StringINVALID_RECIPIENT"Invalid TO address: %s"
-protected static final java.lang.StringINVALID_REPLYTO"Invalid REPLY TO address: %s"
-protected static final java.lang.StringINVALID_SENDER"Invalid FROM address: %s"
-protected static final java.lang.StringMISSING_CONTENT"Email is not valid: missing content body"
-protected static final java.lang.StringMISSING_HOST"Can\'t send an email without host"
-protected static final java.lang.StringMISSING_RECIPIENT"Email is not valid: missing recipients"
-protected static final java.lang.StringMISSING_SENDER"Email is not valid: missing sender"
-protected static final java.lang.StringMISSING_SUBJECT"Email is not valid: missing subject"
-protected static final java.lang.StringMISSING_USERNAME"Can\'t have a password without username"
- -

- -

-


- - +
+

Constant Field Values

+

Contents

+ +
+
+ + +

org.codemonkey.*

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/deprecated-list.html b/javadoc/developers/deprecated-list.html index c3292c3e0..ffa2183bf 100644 --- a/javadoc/developers/deprecated-list.html +++ b/javadoc/developers/deprecated-list.html @@ -1,144 +1,123 @@ - - - - - -Deprecated List (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Deprecated API

-
-
-Contents - -
- - +
+

Deprecated API

+

Contents

+
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/help-doc.html b/javadoc/developers/help-doc.html index 6276215af..681a9c8e1 100644 --- a/javadoc/developers/help-doc.html +++ b/javadoc/developers/help-doc.html @@ -1,215 +1,224 @@ - - - - - -API Help (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. -
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+ +This help file applies to API documentation generated using the standard doclet.
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/index-all.html b/javadoc/developers/index-all.html index 4c6a86234..bb1579680 100644 --- a/javadoc/developers/index-all.html +++ b/javadoc/developers/index-all.html @@ -1,524 +1,722 @@ - - - - - -Index (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -A B C D E F G H I L M N O P R S T V
-

-A

-
-
addAttachment(String, byte[], String) - -Method in class org.codemonkey.simplejavamail.Email -
Adds an attachment to the email message and generates the necessary DataSource with the given byte data. -
addAttachment(String, DataSource) - -Method in class org.codemonkey.simplejavamail.Email -
Overloaded method which sets an attachment on account of name and DataSource. -
addEmbeddedImage(String, byte[], String) - -Method in class org.codemonkey.simplejavamail.Email -
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte - data. -
addEmbeddedImage(String, DataSource) - -Method in class org.codemonkey.simplejavamail.Email -
Overloaded method which sets an embedded image on account of name and DataSource. -
addHeader(String, Object) - -Method in class org.codemonkey.simplejavamail.Email -
Adds a header to the Email.headers list. -
addRecipient(String, String, Message.RecipientType) - -Method in class org.codemonkey.simplejavamail.Email -
Adds a new Recipient to the list on account of name, address and recipient type (eg. -
address - -Variable in class org.codemonkey.simplejavamail.Recipient -
  -
allowDomainLiterals - -Variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
allowQuotedIdentifiers - -Variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
AttachmentResource - Class in org.codemonkey.simplejavamail
A named immutable email attachment information object.
AttachmentResource(String, DataSource) - -Constructor for class org.codemonkey.simplejavamail.AttachmentResource -
Constructor; initializes the attachment resource with a name and data. -
attachments - -Variable in class org.codemonkey.simplejavamail.Email -
List of AttachmentResource. -
-
-

-B

-
-
buildValidEmailPattern(EmailAddressValidationCriteria) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
  -
-
-

-C

-
-
CHARACTER_ENCODING - -Static variable in class org.codemonkey.simplejavamail.Mailer -
Encoding used for setting body text, email address, headers, reply-to fields etc. -
createMailSession(String, Integer, String, String) - -Method in class org.codemonkey.simplejavamail.Mailer -
Actually instantiates and configures the Session instance. -
-
-

-D

-
-
dataSource - -Variable in class org.codemonkey.simplejavamail.AttachmentResource -
  -
-
-

-E

-
-
Email - Class in org.codemonkey.simplejavamail
Email message with all necessary data for an effective mailing action, including attachments etc.
Email() - -Constructor for class org.codemonkey.simplejavamail.Email -
Constructor, creates all internal lists. -
EmailAddressValidationCriteria - Class in org.codemonkey.simplejavamail
Defines a set of restriction flags for email address validation.
EmailAddressValidationCriteria(boolean, boolean) - -Constructor for class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
emailAddressValidationCriteria - -Variable in class org.codemonkey.simplejavamail.Mailer -
Email address restriction flags set either by constructor or overridden by getter by user. -
EmailValidationUtil - Class in org.codemonkey.simplejavamail
Validates an email address according to RFC 2822, using regular expressions.
EmailValidationUtil() - -Constructor for class org.codemonkey.simplejavamail.EmailValidationUtil -
Private constructor; this is a utility class with static methods only, not designed for extension. -
embeddedImages - -Variable in class org.codemonkey.simplejavamail.Email -
List of AttachmentResource. -
-
-

-F

-
-
fromRecipient - -Variable in class org.codemonkey.simplejavamail.Email -
The sender of the email. -
-
-

-G

-
-
generateProperties() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
Base implementation that simply returns an empty list of properties. -
GENERIC_ERROR - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
getAddress() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.address; -
getAttachments() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.attachments as unmodifiable list. -
getBodyPartFromDatasource(AttachmentResource, String) - -Method in class org.codemonkey.simplejavamail.Mailer -
Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition - type (Part.INLINE or Part.ATTACHMENT). -
getDataSource() - -Method in class org.codemonkey.simplejavamail.AttachmentResource -
Bean getter for dataSource. -
getEmbeddedImages() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.embeddedImages as unmodifiable list. -
getFromRecipient() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.fromRecipient. -
getHeaders() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.headers as unmodifiable map. -
getName() - -Method in class org.codemonkey.simplejavamail.AttachmentResource -
Bean getter for name. -
getName() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.name; -
getRecipients() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.recipients as unmodifiable list. -
getReplyToRecipient() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.replyToRecipient. -
getSubject() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.subject. -
getText() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.text. -
getTextHTML() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for Email.textHTML. -
getType() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.type; -
-
-

-H

-
-
headers - -Variable in class org.codemonkey.simplejavamail.Email -
Map of header name and values, such as X-Priority etc. -
-
-

-I

-
-
INVALID_ENCODING - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_RECIPIENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_REPLYTO - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_SENDER - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
isAllowDomainLiterals() - -Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
isAllowQuotedIdentifiers() - -Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
isValid(String) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
Validates an e-mail with default validation flags that remains true to RFC 2822. -
isValid(String, EmailAddressValidationCriteria) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
Validates an e-mail with given validation flags. -
-
-

-L

-
-
logger - -Static variable in class org.codemonkey.simplejavamail.Mailer -
  -
logSession(Session, TransportStrategy) - -Method in class org.codemonkey.simplejavamail.Mailer -
Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used. -
-
-

-M

-
-
Mailer - Class in org.codemonkey.simplejavamail
Mailing tool aimed for simplicity, for sending e-mails of any complexity.
Mailer(Session) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Default constructor, stores the given mail session for later use. -
Mailer(String, Integer, String, String, TransportStrategy) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Overloaded constructor which produces a new Session on the fly. -
Mailer(String, Integer, String, String) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol. -
Mailer.MimeEmailMessageWrapper - Class in org.codemonkey.simplejavamail
This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc.
Mailer.MimeEmailMessageWrapper() - -Constructor for class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper -
Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly. -
MailException - Exception in org.codemonkey.simplejavamail
This exception is used to communicate errors during the sending of email.
MailException(String) - -Constructor for exception org.codemonkey.simplejavamail.MailException -
  -
MailException(String, MessagingException) - -Constructor for exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_CONTENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_HOST - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_RECIPIENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_SENDER - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_SUBJECT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_USERNAME - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
multipartAlternativeMessages - -Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper -
  -
multipartRelated - -Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper -
  -
multipartRoot - -Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper -
  -
-
-

-N

-
-
name - -Variable in class org.codemonkey.simplejavamail.AttachmentResource -
  -
name - -Variable in class org.codemonkey.simplejavamail.Recipient -
  -
-
-

-O

-
-
org.codemonkey.simplejavamail - package org.codemonkey.simplejavamail
 
-
-

-P

-
-
prepareMessage(Email, Mailer.MimeEmailMessageWrapper) - -Method in class org.codemonkey.simplejavamail.Mailer -
Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send. -
propertyNameAuthenticate() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
  -
propertyNameHost() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
  -
propertyNamePort() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
  -
propertyNameUsername() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
  -
-
-

-R

-
-
Recipient - Class in org.codemonkey.simplejavamail
An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
Recipient(String, String, Message.RecipientType) - -Constructor for class org.codemonkey.simplejavamail.Recipient -
Constructor; initializes this recipient object. -
recipients - -Variable in class org.codemonkey.simplejavamail.Email -
List of Recipient. -
replyToRecipient - -Variable in class org.codemonkey.simplejavamail.Email -
The reply-to-address, optional. -
-
-

-S

-
-
sendMail(Email) - -Method in class org.codemonkey.simplejavamail.Mailer -
Processes an Email instance into a completely configured Message. -
session - -Variable in class org.codemonkey.simplejavamail.Mailer -
Used to actually send the email. -
setAttachments(Email, MimeMultipart) - -Method in class org.codemonkey.simplejavamail.Mailer -
Fills the Message instance with the attachments from the Email. -
setDebug(boolean) - -Method in class org.codemonkey.simplejavamail.Mailer -
Actually sets Session.setDebug(boolean) so that it generates debug information. -
setEmailAddressValidationCriteria(EmailAddressValidationCriteria) - -Method in class org.codemonkey.simplejavamail.Mailer -
Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance. -
setEmbeddedImages(Email, MimeMultipart) - -Method in class org.codemonkey.simplejavamail.Mailer -
Fills the Message instance with the embedded images from the Email. -
setFromAddress(String, String) - -Method in class org.codemonkey.simplejavamail.Email -
Sets the sender address. -
setHeaders(Email, Message) - -Method in class org.codemonkey.simplejavamail.Mailer -
Sets all headers on the Message instance. -
setRecipients(Email, Message) - -Method in class org.codemonkey.simplejavamail.Mailer -
Fills the Message instance with recipients from the Email. -
setReplyTo(Email, Message) - -Method in class org.codemonkey.simplejavamail.Mailer -
Fills the Message instance with reply-to address. -
setReplyToAddress(String, String) - -Method in class org.codemonkey.simplejavamail.Email -
Sets the reply-to address (optional). -
setSubject(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for Email.subject. -
setText(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for Email.text. -
setTextHTML(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for Email.textHTML. -
setTexts(Email, MimeMultipart) - -Method in class org.codemonkey.simplejavamail.Mailer -
Fills the Message instance with the content bodies (text and html). -
subject - -Variable in class org.codemonkey.simplejavamail.Email -
The subject of the email message. -
-
-

-T

-
-
text - -Variable in class org.codemonkey.simplejavamail.Email -
The email message body in plain text. -
textHTML - -Variable in class org.codemonkey.simplejavamail.Email -
The email message body in html. -
transportStrategy - -Variable in class org.codemonkey.simplejavamail.Mailer -
The transport protocol strategy enum that actually handles the session configuration. -
TransportStrategy - Enum in org.codemonkey.simplejavamail
Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
TransportStrategy() - -Constructor for enum org.codemonkey.simplejavamail.TransportStrategy -
  -
type - -Variable in class org.codemonkey.simplejavamail.Recipient -
  -
-
-

-V

-
-
validate(Email) - -Method in class org.codemonkey.simplejavamail.Mailer -
Validates an Email instance. -
valueOf(String) - -Static method in enum org.codemonkey.simplejavamail.TransportStrategy -
Returns the enum constant of this type with the specified name. -
values() - -Static method in enum org.codemonkey.simplejavamail.TransportStrategy -
Returns an array containing the constants of this enum type, in -the order they are declared. -
-
-A B C D E F G H I L M N O P R S T V - +
A B C D E F G H I L M N O P R S T V  + + +

A

+
+
addAttachment(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds an attachment to the email message and generates the necessary DataSource with the given byte data.
+
+
addAttachment(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email
+
+
Overloaded method which sets an attachment on account of name and DataSource.
+
+
addAttachment(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds an attachment to the email message and generates the necessary DataSource with the given byte data.
+
+
addAttachment(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Overloaded method which sets an attachment on account of name and DataSource.
+
+
addEmbeddedImage(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte + data.
+
+
addEmbeddedImage(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email
+
+
Overloaded method which sets an embedded image on account of name and DataSource.
+
+
addHeader(String, Object) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds a header to the Email.headers list.
+
+
addHeader(String, Object) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a header to the Email.Builder.headers list.
+
+
addRecipient(String, String, Message.RecipientType) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds a new Recipient to the list on account of name, address and recipient type (eg.
+
+
address - Variable in class org.codemonkey.simplejavamail.Recipient
+
 
+
allowDomainLiterals - Variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
allowQuotedIdentifiers - Variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
applyProperties(Properties) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Copies all property entries into the Session using Session.getProperties().
+
+
AttachmentResource - Class in org.codemonkey.simplejavamail
+
+
A named immutable email attachment information object.
+
+
AttachmentResource(String, DataSource) - Constructor for class org.codemonkey.simplejavamail.AttachmentResource
+
+
Constructor; initializes the attachment resource with a name and data.
+
+
attachments - Variable in class org.codemonkey.simplejavamail.Email
+
+ +
+
attachments - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+ +
+
+ + + +

B

+
+
bcc(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.BCC.
+
+
bcc(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.BCC.
+
+
build() - Method in class org.codemonkey.simplejavamail.Email.Builder
+
 
+
Builder() - Constructor for class org.codemonkey.simplejavamail.Email.Builder
+
 
+
buildValidEmailPattern(EmailAddressValidationCriteria) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
 
+
+ + + +

C

+
+
cc(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.CC.
+
+
cc(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.CC.
+
+
CHARACTER_ENCODING - Static variable in class org.codemonkey.simplejavamail.Mailer
+
+
Encoding used for setting body text, email address, headers, reply-to fields etc.
+
+
createMailSession(String, Integer, String, String) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Actually instantiates and configures the Session instance.
+
+
+ + + +

D

+
+
dataSource - Variable in class org.codemonkey.simplejavamail.AttachmentResource
+
 
+
+ + + +

E

+
+
Email - Class in org.codemonkey.simplejavamail
+
+
Email message with all necessary data for an effective mailing action, including attachments etc.
+
+
Email() - Constructor for class org.codemonkey.simplejavamail.Email
+
+
Constructor, creates all internal lists.
+
+
Email(Email.Builder) - Constructor for class org.codemonkey.simplejavamail.Email
+
+
Constructor for the Builder class
+
+
email - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
 
+
Email.Builder - Class in org.codemonkey.simplejavamail
+
+
Fluent interface Builder for Emails
+
+
EmailAddressValidationCriteria - Class in org.codemonkey.simplejavamail
+
+
Defines a set of restriction flags for email address validation.
+
+
EmailAddressValidationCriteria(boolean, boolean) - Constructor for class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
emailAddressValidationCriteria - Variable in class org.codemonkey.simplejavamail.Mailer
+
+
Email address restriction flags set either by constructor or overridden by getter by user.
+
+
EmailValidationUtil - Class in org.codemonkey.simplejavamail
+
+
Validates an email address according to RFC 2822, using regular expressions.
+
+
EmailValidationUtil() - Constructor for class org.codemonkey.simplejavamail.EmailValidationUtil
+
+
Private constructor; this is a utility class with static methods only, not designed for extension.
+
+
embeddedImages - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+ +
+
embeddedImages - Variable in class org.codemonkey.simplejavamail.Email
+
+ +
+
embedImage(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte + data.
+
+
embedImage(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Overloaded method which sets an embedded image on account of name and DataSource.
+
+
+ + + +

F

+
+
from(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the sender address.
+
+
fromRecipient - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
 
+
fromRecipient - Variable in class org.codemonkey.simplejavamail.Email
+
+
The sender of the email.
+
+
+ + + +

G

+
+
generateProperties() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Base implementation that simply returns an empty list of properties.
+
+
GENERIC_ERROR - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
getAddress() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.address;
+
+
getAttachments() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.attachments as unmodifiable list.
+
+
getBodyPartFromDatasource(AttachmentResource, String) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition + type (Part.INLINE or Part.ATTACHMENT).
+
+
getDataSource() - Method in class org.codemonkey.simplejavamail.AttachmentResource
+
+
Bean getter for dataSource.
+
+
getEmbeddedImages() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.embeddedImages as unmodifiable list.
+
+
getFromRecipient() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.fromRecipient.
+
+
getHeaders() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.headers as unmodifiable map.
+
+
getName() - Method in class org.codemonkey.simplejavamail.AttachmentResource
+
+
Bean getter for name.
+
+
getName() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.name;
+
+
getRecipients() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.recipients as unmodifiable list.
+
+
getReplyToRecipient() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.replyToRecipient.
+
+
getSession() - Method in class org.codemonkey.simplejavamail.Mailer
+
+
In case Simple Java Mail falls short somehow, you can get a hold of the internal Session instance to debug or tweak.
+
+
getSubject() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.subject.
+
+
getText() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.text.
+
+
getTextHTML() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.textHTML.
+
+
getType() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.type;
+
+
+ + + +

H

+
+
headers - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
Map of header name and values, such as X-Priority etc.
+
+
headers - Variable in class org.codemonkey.simplejavamail.Email
+
+
Map of header name and values, such as X-Priority etc.
+
+
+ + + +

I

+
+
INVALID_ENCODING - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_RECIPIENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_REPLYTO - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_SENDER - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
isAllowDomainLiterals() - Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
isAllowQuotedIdentifiers() - Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
isValid(String) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
+
Validates an e-mail with default validation flags that remains true to RFC 2822.
+
+
isValid(String, EmailAddressValidationCriteria) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
+
Validates an e-mail with given validation flags.
+
+
+ + + +

L

+
+
logger - Static variable in class org.codemonkey.simplejavamail.Mailer
+
 
+
logSession(Session, TransportStrategy) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
+
+
+ + + +

M

+
+
Mailer - Class in org.codemonkey.simplejavamail
+
+
Mailing tool aimed for simplicity, for sending e-mails of any complexity.
+
+
Mailer(Session) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Default constructor, stores the given mail session for later use.
+
+
Mailer(String, Integer, String, String, TransportStrategy) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Overloaded constructor which produces a new Session on the fly.
+
+
Mailer(String, Integer, String, String) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
+
+
Mailer.MimeEmailMessageWrapper - Class in org.codemonkey.simplejavamail
+
+
This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc.
+
+
MailException - Exception in org.codemonkey.simplejavamail
+
+
This exception is used to communicate errors during the sending of email.
+
+
MailException(String) - Constructor for exception org.codemonkey.simplejavamail.MailException
+
 
+
MailException(String, MessagingException) - Constructor for exception org.codemonkey.simplejavamail.MailException
+
 
+
MimeEmailMessageWrapper() - Constructor for class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper
+
+
Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
+
+
MISSING_CONTENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_HOST - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_RECIPIENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_SENDER - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_SUBJECT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_USERNAME - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
multipartAlternativeMessages - Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper
+
 
+
multipartRelated - Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper
+
 
+
multipartRoot - Variable in class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper
+
 
+
+ + + +

N

+
+
name - Variable in class org.codemonkey.simplejavamail.AttachmentResource
+
 
+
name - Variable in class org.codemonkey.simplejavamail.Recipient
+
 
+
+ + + +

O

+
+
org.codemonkey.simplejavamail - package org.codemonkey.simplejavamail
+
 
+
+ + + +

P

+
+
prepareMessage(Email, Mailer.MimeEmailMessageWrapper) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send.
+
+
propertyNameAuthenticate() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
 
+
propertyNameHost() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
 
+
propertyNamePort() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
 
+
propertyNameUsername() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
 
+
+ + + +

R

+
+
Recipient - Class in org.codemonkey.simplejavamail
+
+
An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
+
+
Recipient(String, String, Message.RecipientType) - Constructor for class org.codemonkey.simplejavamail.Recipient
+
+
Constructor; initializes this recipient object.
+
+
recipients - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
List of Recipient.
+
+
recipients - Variable in class org.codemonkey.simplejavamail.Email
+
+
List of Recipient.
+
+
replyTo(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the reply-to address (optional).
+
+
replyToRecipient - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
The reply-to-address, optional.
+
+
replyToRecipient - Variable in class org.codemonkey.simplejavamail.Email
+
+
The reply-to-address, optional.
+
+
RFC_COMPLIANT - Static variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
+
Criteria which is most RFC 2822 compliant and allows all compiant address forms, including the more exotic ones.
+
+
+ + + +

S

+
+
sendMail(Email) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Processes an Email instance into a completely configured Message.
+
+
session - Variable in class org.codemonkey.simplejavamail.Mailer
+
+
Used to actually send the email.
+
+
setAttachments(Email, MimeMultipart) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Fills the Message instance with the attachments from the Email.
+
+
setDebug(boolean) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Actually sets Session.setDebug(boolean) so that it generates debug information.
+
+
setEmailAddressValidationCriteria(EmailAddressValidationCriteria) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Overrides the default email address validation restrictions when validating and sending emails using the current Mailer + instance.
+
+
setEmbeddedImages(Email, MimeMultipart) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Fills the Message instance with the embedded images from the Email.
+
+
setFromAddress(String, String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Sets the sender address.
+
+
setHeaders(Email, Message) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Sets all headers on the Message instance.
+
+
setRecipients(Email, Message) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Fills the Message instance with recipients from the Email.
+
+
setReplyTo(Email, Message) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Fills the Message instance with reply-to address.
+
+
setReplyToAddress(String, String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Sets the reply-to address (optional).
+
+
setSubject(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.subject.
+
+
setText(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.text.
+
+
setTextHTML(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.textHTML.
+
+
setTexts(Email, MimeMultipart) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Fills the Message instance with the content bodies (text and html).
+
+
subject - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
The subject of the email message.
+
+
subject(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+ +
+
subject - Variable in class org.codemonkey.simplejavamail.Email
+
+
The subject of the email message.
+
+
+ + + +

T

+
+
text - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
The email message body in plain text.
+
+
text(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+ +
+
text - Variable in class org.codemonkey.simplejavamail.Email
+
+
The email message body in plain text.
+
+
textHTML - Variable in class org.codemonkey.simplejavamail.Email.Builder
+
+
The email message body in html.
+
+
textHTML(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+ +
+
textHTML - Variable in class org.codemonkey.simplejavamail.Email
+
+
The email message body in html.
+
+
to(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.TO.
+
+
to(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.TO.
+
+
transportStrategy - Variable in class org.codemonkey.simplejavamail.Mailer
+
+
The transport protocol strategy enum that actually handles the session configuration.
+
+
TransportStrategy - Enum in org.codemonkey.simplejavamail
+
+
Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a + TransportStrategy implementation.
+
+
TransportStrategy() - Constructor for enum org.codemonkey.simplejavamail.TransportStrategy
+
 
+
type - Variable in class org.codemonkey.simplejavamail.Recipient
+
 
+
+ + + +

V

+
+
validate(Email) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Validates an Email instance.
+
+
valueOf(String) - Static method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Returns the enum constant of this type with the specified name.
+
+
values() - Static method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Returns an array containing the constants of this enum type, in +the order they are declared.
+
+
+A B C D E F G H I L M N O P R S T V 
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/index.html b/javadoc/developers/index.html index 91609a90f..c8cacfc8e 100644 --- a/javadoc/developers/index.html +++ b/javadoc/developers/index.html @@ -1,36 +1,71 @@ - - - - - -Simple Java Mail API - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="org/codemonkey/simplejavamail/package-summary.html">Non-frame version.</A> - - - + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/codemonkey/simplejavamail/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/AttachmentResource.html b/javadoc/developers/org/codemonkey/simplejavamail/AttachmentResource.html index bdab26b77..1701b7c83 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/AttachmentResource.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/AttachmentResource.html @@ -1,343 +1,367 @@ - - - - - -AttachmentResource (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class AttachmentResource

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.AttachmentResource
-
-
-
-
final class AttachmentResource
extends java.lang.Object
- - -

-A named immutable email attachment information object. The name can be a simple name, a filename or a named embedded - image (eg. <cid:footer>). Contains a DataSource that is compatible with the javax.mail API. -

- -

-

-
Author:
-
Benny Bottema
-
See Also:
DataSource
-
- -

+

+
org.codemonkey.simplejavamail
+

Class AttachmentResource

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/Email.Builder.html b/javadoc/developers/org/codemonkey/simplejavamail/Email.Builder.html new file mode 100644 index 000000000..ba7bff367 --- /dev/null +++ b/javadoc/developers/org/codemonkey/simplejavamail/Email.Builder.html @@ -0,0 +1,830 @@ + + + + + +Email.Builder (Simple Java Mail API) + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.codemonkey.simplejavamail
+

Class Email.Builder

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/Email.html b/javadoc/developers/org/codemonkey/simplejavamail/Email.html index eeaa4fab8..28a205034 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/Email.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/Email.html @@ -1,891 +1,876 @@ - - - - - -Email (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Email

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Email
-
-
-
-
public class Email
extends java.lang.Object
- - -

-Email message with all necessary data for an effective mailing action, including attachments etc. -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

+

+
org.codemonkey.simplejavamail
+

Class Email

+
+
+ +
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html b/javadoc/developers/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html index 38aab56ee..3da57ff45 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html @@ -1,364 +1,393 @@ - - - - - -EmailAddressValidationCriteria (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class EmailAddressValidationCriteria

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.EmailAddressValidationCriteria
-
-
-
-
public class EmailAddressValidationCriteria
extends java.lang.Object
- - -

-Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to - true. -

- -

-

-
Author:
-
Benny Bottema
-
See Also:
EmailAddressValidationCriteria(boolean, boolean)
-
- -

+

+
org.codemonkey.simplejavamail
+

Class EmailAddressValidationCriteria

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/EmailValidationUtil.html b/javadoc/developers/org/codemonkey/simplejavamail/EmailValidationUtil.html index 37b933fe1..d9aa40ce4 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/EmailValidationUtil.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/EmailValidationUtil.html @@ -1,315 +1,340 @@ - - - - - -EmailValidationUtil (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":9,"i1":9,"i2":9}; +var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class EmailValidationUtil

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.EmailValidationUtil
-
-
-
-
public final class EmailValidationUtil
extends java.lang.Object
- - -

-Validates an email address according to RFC 2822, using regular expressions. -

- From the original author:
-

If you use this code, please keep the author information in tact and reference my site at leshazlewood.com. Thanks!
-

- Code sanitized by Benny Bottema (kept validation 100% in tact). -

- -

-

-
Author:
-
Les Hazlewood, Benny Bottema
-
See Also:
EmailAddressValidationCriteria
-
- -

- +

+
org.codemonkey.simplejavamail
+

Class EmailValidationUtil

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/MailException.html b/javadoc/developers/org/codemonkey/simplejavamail/MailException.html index e07411901..9e18b63d2 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/MailException.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/MailException.html @@ -1,481 +1,496 @@ - - - - - -MailException (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class MailException

-
-java.lang.Object
-  extended by java.lang.Throwable
-      extended by java.lang.Exception
-          extended by java.lang.RuntimeException
-              extended by org.codemonkey.simplejavamail.MailException
-
-
-
All Implemented Interfaces:
java.io.Serializable
-
-
-
-
public final class MailException
extends java.lang.RuntimeException
- - -

-This exception is used to communicate errors during the sending of email. -

- -

-

-
Author:
-
Benny Bottema
-
See Also:
Serialized Form
-
- -

+

+
org.codemonkey.simplejavamail
+

Class MailException

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html b/javadoc/developers/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html index da493dc42..50f98a21a 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html @@ -1,320 +1,323 @@ - - - - - -Mailer.MimeEmailMessageWrapper (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Mailer.MimeEmailMessageWrapper

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper
-
-
-
Enclosing class:
Mailer
-
-
-
-
private class Mailer.MimeEmailMessageWrapper
extends java.lang.Object
- - -

-This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is - ultimately sent using JavaMail.
-
- The constructor creates a new email message constructed from MimeMultipart as follows: - -

- - root
-        - related
-                - alternative
-                        - mail tekst
-                        - mail html tekst
-                - embedded images
-        - attachments
- 
-

- -

-

-
Author:
-
Benny Bottema
-
-
- -

+

+
org.codemonkey.simplejavamail
+

Class Mailer.MimeEmailMessageWrapper

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/Mailer.html b/javadoc/developers/org/codemonkey/simplejavamail/Mailer.html index b92e5dd8a..890b52954 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/Mailer.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/Mailer.html @@ -1,869 +1,950 @@ - - - - - -Mailer (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Mailer

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Mailer
-
-
-
-
public class Mailer
extends java.lang.Object
- - -

-Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content, - embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL
-
- This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with Email - instances.
-
- The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some - mainstream client applications such as MS Outlook or Mozilla Thunderbird.
-
- Technically, the resulting email structure is as follows:
- -

- - root
-        - related
-                - alternative
-                        - mail text
-                        - mail html text
-                - embedded images
-        - attachments
- 
- -
- Usage example:
- -
- Email email = new Email();
- email.setFromAddress("lollypop", "lolly.pop@somemail.com");
- email.addRecipient("Sugar Cane", "sugar.cane@candystore.org", RecipientType.TO);
- email.setText("We should meet up!!");
- email.setTextHTML("<b>We should meet up!</b>");
- email.setSubject("Hey");
- new Mailer(preconfiguredMailSession).sendMail(email);
- // or:
- new Mailer("smtp.someserver.com", 25, "username", "password").sendMail(email);
+
+
org.codemonkey.simplejavamail
+

Class Mailer

+
+
+ +
+
    +
  • +
    +
    +
    public class Mailer
    +extends Object
    +
    Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content, + embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL
    +
    + This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with Email + instances.
    +
    + The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some + mainstream client applications such as MS Outlook or Mozilla Thunderbird.
    +
    + Technically, the resulting email structure is as follows:
    + +
    + - root
    +        - related
    +                - alternative
    +                        - mail text
    +                        - mail html text
    +                - embedded images
    +        - attachments
      
    -

    - -

    -

    -
    Author:
    -
    Benny Bottema
    -
    See Also:
    Mailer.MimeEmailMessageWrapper, -Email
    -
    - -

    + +
    + Usage example:
    + +

    + Email email = new Email();
    + email.setFromAddress("lollypop", "lolly.pop@somemail.com");
    + email.addRecipient("Sugar Cane", "sugar.cane@candystore.org", RecipientType.TO);
    + email.setText("We should meet up!!");
    + email.setTextHTML("<b>We should meet up!</b>");
    + email.setSubject("Hey");
    + new Mailer(preconfiguredMailSession).sendMail(email);
    + // or:
    + new Mailer("smtp.someserver.com", 25, "username", "password").sendMail(email);
    + 
    +
    +
    Author:
    +
    Benny Bottema
    +
    See Also:
    +
    Mailer.MimeEmailMessageWrapper, +Email
    +
    +
  • +
+
+
+
    +
  • - - - - - - - - - - -
    -Nested Class Summary
    -private  classMailer.MimeEmailMessageWrapper - -
    -          This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc.
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Field Summary
    -private static java.lang.StringCHARACTER_ENCODING - -
    -          Encoding used for setting body text, email address, headers, reply-to fields etc.
    -private  EmailAddressValidationCriteriaemailAddressValidationCriteria - -
    -          Email address restriction flags set either by constructor or overridden by getter by user.
    -private static org.apache.log4j.Loggerlogger - -
    -           
    -private  javax.mail.Sessionsession - -
    -          Used to actually send the email.
    -private  TransportStrategytransportStrategy - -
    -          The transport protocol strategy enum that actually handles the session configuration.
    -  +
      +
    • + + +

      Nested Class Summary

      + + + + + + + + + + +
      Nested Classes 
      Modifier and TypeClass and Description
      private class Mailer.MimeEmailMessageWrapper +
      This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc.
      +
      +
    • +
    + + - - - - - - - - - - - - - - - -
    -Constructor Summary
    Mailer(javax.mail.Session session) - -
    -          Default constructor, stores the given mail session for later use.
    Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password) - -
    -          Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
    Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password, - TransportStrategy transportStrategy) - -
    -          Overloaded constructor which produces a new Session on the fly.
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Mailer(javax.mail.Session session) +
      Default constructor, stores the given mail session for later use.
      +
      Mailer(String host, + Integer port, + String username, + String password) +
      Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
      +
      Mailer(String host, + Integer port, + String username, + String password, + TransportStrategy transportStrategy) +
      Overloaded constructor which produces a new Session on the fly.
      +
      +
    • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - javax.mail.SessioncreateMailSession(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password) - -
    -          Actually instantiates and configures the Session instance.
    -private  javax.mail.BodyPartgetBodyPartFromDatasource(AttachmentResource resource, - java.lang.String dispositionType) - -
    -          Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition - type (Part.INLINE or Part.ATTACHMENT).
    -private  voidlogSession(javax.mail.Session session, - TransportStrategy transportStrategy) - -
    -          Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
    -private  javax.mail.MessageprepareMessage(Email email, - Mailer.MimeEmailMessageWrapper messageRoot) - -
    -          Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send.
    - voidsendMail(Email email) - -
    -          Processes an Email instance into a completely configured Message.
    -private  voidsetAttachments(Email email, - javax.mail.internet.MimeMultipart multipartRoot) - -
    -          Fills the Message instance with the attachments from the Email.
    - voidsetDebug(boolean debug) - -
    -          Actually sets Session.setDebug(boolean) so that it generates debug information.
    - voidsetEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) - -
    -          Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance.
    -private  voidsetEmbeddedImages(Email email, - javax.mail.internet.MimeMultipart multipartRelated) - -
    -          Fills the Message instance with the embedded images from the Email.
    -private  voidsetHeaders(Email email, - javax.mail.Message message) - -
    -          Sets all headers on the Message instance.
    -private  voidsetRecipients(Email email, - javax.mail.Message message) - -
    -          Fills the Message instance with recipients from the Email.
    -private  voidsetReplyTo(Email email, - javax.mail.Message message) - -
    -          Fills the Message instance with reply-to address.
    -private  voidsetTexts(Email email, - javax.mail.internet.MimeMultipart multipartAlternativeMessages) - -
    -          Fills the Message instance with the content bodies (text and html).
    - booleanvalidate(Email email) - -
    -          Validates an Email instance.
    - - - - - - - -
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    -  -

    - +

      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethod and Description
      voidapplyProperties(Properties properties) +
      Copies all property entries into the Session using Session.getProperties().
      +
      protected javax.mail.SessioncreateMailSession(String host, + Integer port, + String username, + String password) +
      Actually instantiates and configures the Session instance.
      +
      private javax.mail.BodyPartgetBodyPartFromDatasource(AttachmentResource resource, + String dispositionType) +
      Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition + type (Part.INLINE or Part.ATTACHMENT).
      +
      javax.mail.SessiongetSession() +
      In case Simple Java Mail falls short somehow, you can get a hold of the internal Session instance to debug or tweak.
      +
      private voidlogSession(javax.mail.Session session, + TransportStrategy transportStrategy) +
      Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
      +
      private javax.mail.MessageprepareMessage(Email email, + Mailer.MimeEmailMessageWrapper messageRoot) +
      Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send.
      +
      voidsendMail(Email email) +
      Processes an Email instance into a completely configured Message.
      +
      private voidsetAttachments(Email email, + javax.mail.internet.MimeMultipart multipartRoot) +
      Fills the Message instance with the attachments from the Email.
      +
      voidsetDebug(boolean debug) +
      Actually sets Session.setDebug(boolean) so that it generates debug information.
      +
      voidsetEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) +
      Overrides the default email address validation restrictions when validating and sending emails using the current Mailer + instance.
      +
      private voidsetEmbeddedImages(Email email, + javax.mail.internet.MimeMultipart multipartRelated) +
      Fills the Message instance with the embedded images from the Email.
      +
      private voidsetHeaders(Email email, + javax.mail.Message message) +
      Sets all headers on the Message instance.
      +
      private voidsetRecipients(Email email, + javax.mail.Message message) +
      Fills the Message instance with recipients from the Email.
      +
      private voidsetReplyTo(Email email, + javax.mail.Message message) +
      Fills the Message instance with reply-to address.
      +
      private voidsetTexts(Email email, + javax.mail.internet.MimeMultipart multipartAlternativeMessages) +
      Fills the Message instance with the content bodies (text and html).
      +
      booleanvalidate(Email email) +
      Validates an Email instance.
      +
      + +
    • +
    +
  • +
+
+
+
    +
  • - - - - - - -
    -Field Detail
    - -

    -logger

    -
    -private static final org.apache.log4j.Logger logger
    -
    -
    -
    -
    -
    - -

    -CHARACTER_ENCODING

    -
    -private static final java.lang.String CHARACTER_ENCODING
    -
    -
    Encoding used for setting body text, email address, headers, reply-to fields etc. ("UTF-8"). -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -session

    -
    -private final javax.mail.Session session
    -
    -
    Used to actually send the email. This session can come from being passed in the default constructor, or made by Mailer - directly, when no Session instance was provided. -

    -

    -
    See Also:
    Mailer(Session), -Mailer(String, Integer, String, String, TransportStrategy)
    -
    -
    - -

    -transportStrategy

    -
    -private TransportStrategy transportStrategy
    -
    -
    The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right - properties for the appropriate transport type (ie. "mail.smtp.host" for SMTP, "mail.smtps.host" for SMTPS). -

    -

    -
    -
    -
    - -

    -emailAddressValidationCriteria

    -
    -private EmailAddressValidationCriteria emailAddressValidationCriteria
    -
    -
    Email address restriction flags set either by constructor or overridden by getter by user. -

    -

    -
    See Also:
    EmailAddressValidationCriteria
    -
    - + - - - - - - -
    -Constructor Detail
    - -

    -Mailer

    -
    -public Mailer(javax.mail.Session session)
    -
    -
    Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are - configured (host, port, authentication and transport protocol settings). -

    - Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain - literals and quoted identifiers (see EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean)). -

    -

    -
    Parameters:
    session - A preconfigured mail Session object with which a Message can be produced.
    -
    -
    - -

    -Mailer

    -
    -public Mailer(java.lang.String host,
    -              java.lang.Integer port,
    -              java.lang.String username,
    -              java.lang.String password,
    -              TransportStrategy transportStrategy)
    -
    -
    Overloaded constructor which produces a new Session on the fly. Use this if you don't have a mail session configured in your - web container, or Spring context etc. -

    - Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain - literals and quoted identifiers (see EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean)). -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null, but only if username is null as well.
    transportStrategy - The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
    -
    -
    - -

    -Mailer

    -
    -public Mailer(java.lang.String host,
    -              java.lang.Integer port,
    -              java.lang.String username,
    -              java.lang.String password)
    -
    -
    Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol. -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null, but only if username is null as well.
    See Also:
    Mailer(String, Integer, String, String, TransportStrategy)
    -
    - +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Mailer

        +
        public Mailer(javax.mail.Session session)
        +
        Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are + configured (host, port, authentication and transport protocol settings). +

        + Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the + smtp server instead.

        +
        +
        Parameters:
        +
        session - A preconfigured mail Session object with which a Message can be produced.
        +
        +
      • +
      + + + +
        +
      • +

        Mailer

        +
        public Mailer(String host,
        +              Integer port,
        +              String username,
        +              String password,
        +              TransportStrategy transportStrategy)
        +
        Overloaded constructor which produces a new Session on the fly. Use this if you don't have a mail session configured in your + web container, or Spring context etc. +

        + Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the + smtp server instead.

        +
        +
        Parameters:
        +
        host - The address URL of the SMTP server to be used.
        +
        port - The port of the SMTP server.
        +
        username - An optional username, may be null.
        +
        password - An optional password, may be null, but only if username is null as well.
        +
        transportStrategy - The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
        +
        +
      • +
      + + + +
        +
      • +

        Mailer

        +
        public Mailer(String host,
        +              Integer port,
        +              String username,
        +              String password)
        +
        Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
        +
        +
        Parameters:
        +
        host - The address URL of the SMTP server to be used.
        +
        port - The port of the SMTP server.
        +
        username - An optional username, may be null.
        +
        password - An optional password, may be null, but only if username is null as well.
        +
        See Also:
        +
        Mailer(String, Integer, String, String, TransportStrategy)
        +
        +
      • +
      +
    • +
    - - - - - - -
    -Method Detail
    - -

    -createMailSession

    -
    -public javax.mail.Session createMailSession(java.lang.String host,
    -                                            java.lang.Integer port,
    -                                            java.lang.String username,
    -                                            java.lang.String password)
    -
    -
    Actually instantiates and configures the Session instance. Delegates resolving transport protocol specific properties to the - transportStrategy in two ways: -
      -
    1. request an initial property list which the strategy may pre-populate
    2. -
    3. by requesting the property names according to the respective transport protocol it handles (for the host property for example it - would be "mail.smtp.host" for SMTP and "mail.smtps.host" for SMTPS)
    4. -
    -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null. -
    Returns:
    A fully configured Session instance complete with transport protocol settings.
    See Also:
    TransportStrategy.generateProperties(), -TransportStrategy.propertyNameHost(), -TransportStrategy.propertyNamePort(), -TransportStrategy.propertyNameUsername(), -TransportStrategy.propertyNameAuthenticate()
    -
    -
    -
    - -

    -setDebug

    -
    -public void setDebug(boolean debug)
    -
    -
    Actually sets Session.setDebug(boolean) so that it generates debug information. -

    -

    -
    Parameters:
    debug - Flag to indicate debug mode yes/no.
    -
    -
    -
    - -

    -sendMail

    -
    -public final void sendMail(Email email)
    -                    throws MailException
    -
    -
    Processes an Email instance into a completely configured Message. -

    - Sends the Sun JavaMail Message object using Session.getTransport(). It will call Service.connect() assuming - all connection details have been configured in the provided Session instance. -

    - Performs a call to Message.saveChanges() as the Sun JavaMail API indicates it is needed to configure the message headers and - providing a message id. -

    -

    -
    Parameters:
    email - The information for the email to be sent. -
    Throws: -
    MailException - Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending - etc.
    See Also:
    validate(Email), -prepareMessage(Email, MimeEmailMessageWrapper), -setRecipients(Email, Message), -setTexts(Email, MimeMultipart), -setEmbeddedImages(Email, MimeMultipart), -setAttachments(Email, MimeMultipart)
    -
    -
    -
    - -

    -logSession

    -
    -private void logSession(javax.mail.Session session,
    -                        TransportStrategy transportStrategy)
    -
    -
    Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used. -

    -

    -
    -
    -
    -
    - -

    -validate

    -
    -public boolean validate(Email email)
    -                 throws MailException
    -
    -
    Validates an Email instance. Validation fails if the subject is missing, content is missing, or no recipients are defined. -

    -

    -
    Parameters:
    email - The email that needs to be configured correctly. -
    Returns:
    Always true (throws a MailException exception if validation fails). -
    Throws: -
    MailException - Is being thrown in any of the above causes.
    See Also:
    EmailValidationUtil
    -
    -
    -
    - -

    -prepareMessage

    -
    -private javax.mail.Message prepareMessage(Email email,
    -                                          Mailer.MimeEmailMessageWrapper messageRoot)
    +
      +
    • + + +

      Method Detail

      + + + + + + + +
        +
      • +

        getSession

        +
        public javax.mail.Session getSession()
        +
        In case Simple Java Mail falls short somehow, you can get a hold of the internal Session instance to debug or tweak. Please + let us know why you are needing this on https://github.com/bbottema/simple-java-mail/issues.
        +
      • +
      + + + +
        +
      • +

        setDebug

        +
        public void setDebug(boolean debug)
        +
        Actually sets Session.setDebug(boolean) so that it generates debug information.
        +
        +
        Parameters:
        +
        debug - Flag to indicate debug mode yes/no.
        +
        +
      • +
      + + + +
        +
      • +

        applyProperties

        +
        public void applyProperties(Properties properties)
        +
        Copies all property entries into the Session using Session.getProperties().
        +
        +
        Parameters:
        +
        properties - The source properties to add or override in the internal Session instance.
        +
        +
      • +
      + + + + + + + +
        +
      • +

        logSession

        +
        private void logSession(javax.mail.Session session,
        +                        TransportStrategy transportStrategy)
        +
        Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
        +
      • +
      + + + +
        +
      • +

        validate

        +
        public boolean validate(Email email)
        +                 throws MailException
        +
        Validates an Email instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
        +
        +
        Parameters:
        +
        email - The email that needs to be configured correctly.
        +
        Returns:
        +
        Always true (throws a MailException exception if validation fails).
        +
        Throws:
        +
        MailException - Is being thrown in any of the above causes.
        +
        See Also:
        +
        EmailValidationUtil
        +
        +
      • +
      + + + +
        +
      • +

        prepareMessage

        +
        private javax.mail.Message prepareMessage(Email email,
        +                                          Mailer.MimeEmailMessageWrapper messageRoot)
                                            throws javax.mail.MessagingException,
        -                                          java.io.UnsupportedEncodingException
        -
        -
        Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send. -

        - Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers. -

        -

        -
        Parameters:
        email - The email message from which the subject and From-address are extracted.
        messageRoot - The root of the email which holds everything (filled with some email data). -
        Returns:
        A fully preparated Message instance, ready to be sent. -
        Throws: -
        javax.mail.MessagingException - Kan gegooid worden als het message niet goed behandelt wordt. -
        java.io.UnsupportedEncodingException - Zie InternetAddress.InternetAddress(String, String).
        -
        -
        -
        - -

        -setRecipients

        -
        -private void setRecipients(Email email,
        +                                          UnsupportedEncodingException
        +
        Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send. +

        + Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.

        +
        +
        Parameters:
        +
        email - The email message from which the subject and From-address are extracted.
        +
        messageRoot - The root of the email which holds everything (filled with some email data).
        +
        Returns:
        +
        A fully preparated Message instance, ready to be sent.
        +
        Throws:
        +
        javax.mail.MessagingException - May be thrown when the message couldn't be processed by JavaMail.
        +
        UnsupportedEncodingException - Zie InternetAddress.InternetAddress(String, String).
        +
        +
      • +
      + + + +
        +
      • +

        setRecipients

        +
        private void setRecipients(Email email,
                                    javax.mail.Message message)
        -                    throws java.io.UnsupportedEncodingException,
        -                           javax.mail.MessagingException
        -
        -
        Fills the Message instance with recipients from the Email. -

        -

        -
        Parameters:
        email - The message in which the recipients are defined.
        message - The javax message that needs to be filled with recipients. -
        Throws: -
        java.io.UnsupportedEncodingException - See InternetAddress.InternetAddress(String, String). -
        javax.mail.MessagingException - See Message.addRecipient(javax.mail.Message.RecipientType, Address)
        -
        -
        -
        - -

        -setReplyTo

        -
        -private void setReplyTo(Email email,
        +                    throws UnsupportedEncodingException,
        +                           javax.mail.MessagingException
        +
        Fills the Message instance with recipients from the Email.
        +
        +
        Parameters:
        +
        email - The message in which the recipients are defined.
        +
        message - The javax message that needs to be filled with recipients.
        +
        Throws:
        +
        UnsupportedEncodingException - See InternetAddress.InternetAddress(String, String).
        +
        javax.mail.MessagingException - See Message.addRecipient(javax.mail.Message.RecipientType, Address)
        +
        +
      • +
      + + + +
        +
      • +

        setReplyTo

        +
        private void setReplyTo(Email email,
                                 javax.mail.Message message)
        -                 throws java.io.UnsupportedEncodingException,
        -                        javax.mail.MessagingException
        -
        -
        Fills the Message instance with reply-to address. -

        -

        -
        Parameters:
        email - The message in which the recipients are defined.
        message - The javax message that needs to be filled with reply-to address. -
        Throws: -
        java.io.UnsupportedEncodingException - See InternetAddress.InternetAddress(String, String). -
        javax.mail.MessagingException - See Message.setReplyTo(Address[])
        -
        -
        -
        - -

        -setTexts

        -
        -private void setTexts(Email email,
        +                 throws UnsupportedEncodingException,
        +                        javax.mail.MessagingException
        +
        Fills the Message instance with reply-to address.
        +
        +
        Parameters:
        +
        email - The message in which the recipients are defined.
        +
        message - The javax message that needs to be filled with reply-to address.
        +
        Throws:
        +
        UnsupportedEncodingException - See InternetAddress.InternetAddress(String, String).
        +
        javax.mail.MessagingException - See Message.setReplyTo(Address[])
        +
        +
      • +
      + + + +
        +
      • +

        setTexts

        +
        private void setTexts(Email email,
                               javax.mail.internet.MimeMultipart multipartAlternativeMessages)
        -               throws javax.mail.MessagingException
        -
        -
        Fills the Message instance with the content bodies (text and html). -

        -

        -
        Parameters:
        email - The message in which the content is defined.
        multipartAlternativeMessages - See MimeMultipart.addBodyPart(BodyPart) -
        Throws: -
        javax.mail.MessagingException - See Part.setText(String), Part.setContent(Object, String) and - MimeMultipart.addBodyPart(BodyPart).
        -
        -
        -
        - -

        -setEmbeddedImages

        -
        -private void setEmbeddedImages(Email email,
        +               throws javax.mail.MessagingException
        +
        Fills the Message instance with the content bodies (text and html).
        +
        +
        Parameters:
        +
        email - The message in which the content is defined.
        +
        multipartAlternativeMessages - See MimeMultipart.addBodyPart(BodyPart)
        +
        Throws:
        +
        javax.mail.MessagingException - See Part.setText(String), Part.setContent(Object, String) and + MimeMultipart.addBodyPart(BodyPart).
        +
        +
      • +
      + + + +
        +
      • +

        setEmbeddedImages

        +
        private void setEmbeddedImages(Email email,
                                        javax.mail.internet.MimeMultipart multipartRelated)
        -                        throws javax.mail.MessagingException
        -
        -
        Fills the Message instance with the embedded images from the Email. -

        -

        -
        Parameters:
        email - The message in which the embedded images are defined.
        multipartRelated - The branch in the email structure in which we'll stuff the embedded images. -
        Throws: -
        javax.mail.MessagingException - See MimeMultipart.addBodyPart(BodyPart) and - getBodyPartFromDatasource(AttachmentResource, String)
        -
        -
        -
        - -

        -setAttachments

        -
        -private void setAttachments(Email email,
        +                        throws javax.mail.MessagingException
        +
        Fills the Message instance with the embedded images from the Email.
        +
        +
        Parameters:
        +
        email - The message in which the embedded images are defined.
        +
        multipartRelated - The branch in the email structure in which we'll stuff the embedded images.
        +
        Throws:
        +
        javax.mail.MessagingException - See MimeMultipart.addBodyPart(BodyPart) and + getBodyPartFromDatasource(AttachmentResource, String)
        +
        +
      • +
      + + + +
        +
      • +

        setAttachments

        +
        private void setAttachments(Email email,
                                     javax.mail.internet.MimeMultipart multipartRoot)
        -                     throws javax.mail.MessagingException
        -
        -
        Fills the Message instance with the attachments from the Email. -

        -

        -
        Parameters:
        email - The message in which the attachments are defined.
        multipartRoot - The branch in the email structure in which we'll stuff the attachments. -
        Throws: -
        javax.mail.MessagingException - See MimeMultipart.addBodyPart(BodyPart) and - getBodyPartFromDatasource(AttachmentResource, String)
        -
        -
        -
        - -

        -setHeaders

        -
        -private void setHeaders(Email email,
        +                     throws javax.mail.MessagingException
        +
        Fills the Message instance with the attachments from the Email.
        +
        +
        Parameters:
        +
        email - The message in which the attachments are defined.
        +
        multipartRoot - The branch in the email structure in which we'll stuff the attachments.
        +
        Throws:
        +
        javax.mail.MessagingException - See MimeMultipart.addBodyPart(BodyPart) and + getBodyPartFromDatasource(AttachmentResource, String)
        +
        +
      • +
      + + + +
        +
      • +

        setHeaders

        +
        private void setHeaders(Email email,
                                 javax.mail.Message message)
        -                 throws java.io.UnsupportedEncodingException,
        -                        javax.mail.MessagingException
        -
        -
        Sets all headers on the Message instance. Since we're not using a high-level JavaMail method, the JavaMail library says we - need to do some encoding and 'folding' manually, to get the value right for the headers (see MimeUtility. -

        -

        -
        Parameters:
        email - The message in which the headers are defined.
        message - The Message on which to set the raw, encoded and folded headers. -
        Throws: -
        java.io.UnsupportedEncodingException - See MimeUtility.encodeText(String, String, String) -
        javax.mail.MessagingException - See Part.addHeader(String, String)
        See Also:
        MimeUtility#encodeText(String, String, String)}, -MimeUtility.fold(int, String)
        -
        -
        -
        - -

        -getBodyPartFromDatasource

        -
        -private javax.mail.BodyPart getBodyPartFromDatasource(AttachmentResource resource,
        -                                                      java.lang.String dispositionType)
        -                                               throws javax.mail.MessagingException
        -
        -
        Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition - type (Part.INLINE or Part.ATTACHMENT). With this the attachment data can be converted into objects that fit in the - email structure.
        -
        - For every attachment and embedded image a header needs to be set. -

        -

        -
        Parameters:
        resource - An object that describes the attachment and contains the actual content data.
        dispositionType - The type of attachment, Part.INLINE or Part.ATTACHMENT . -
        Returns:
        An object with the attachment data read for placement in the email structure. -
        Throws: -
        javax.mail.MessagingException - All BodyPart setters.
        -
        -
        -
        - -

        -setEmailAddressValidationCriteria

        -
        -public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria)
        -
        -
        Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance. -

        -

        -
        Parameters:
        emailAddressValidationCriteria - Refer to - EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean).
        -
        -
        + throws UnsupportedEncodingException, + javax.mail.MessagingException
    +
    Sets all headers on the Message instance. Since we're not using a high-level JavaMail method, the JavaMail library says we + need to do some encoding and 'folding' manually, to get the value right for the headers (see MimeUtility.
    +
    +
    Parameters:
    +
    email - The message in which the headers are defined.
    +
    message - The Message on which to set the raw, encoded and folded headers.
    +
    Throws:
    +
    UnsupportedEncodingException - See MimeUtility.encodeText(String, String, String)
    +
    javax.mail.MessagingException - See Part.addHeader(String, String)
    +
    See Also:
    +
    MimeUtility#encodeText(String, String, String)}, +MimeUtility.fold(int, String)
    +
    +
  • +
+ + + +
    +
  • +

    getBodyPartFromDatasource

    +
    private javax.mail.BodyPart getBodyPartFromDatasource(AttachmentResource resource,
    +                                                      String dispositionType)
    +                                               throws javax.mail.MessagingException
    +
    Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition + type (Part.INLINE or Part.ATTACHMENT). With this the attachment data can be converted into objects that fit in the + email structure.
    +
    + For every attachment and embedded image a header needs to be set.
    +
    +
    Parameters:
    +
    resource - An object that describes the attachment and contains the actual content data.
    +
    dispositionType - The type of attachment, Part.INLINE or Part.ATTACHMENT .
    +
    Returns:
    +
    An object with the attachment data read for placement in the email structure.
    +
    Throws:
    +
    javax.mail.MessagingException - All BodyPart setters.
    +
    +
  • +
+ + + + + + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/Recipient.html b/javadoc/developers/org/codemonkey/simplejavamail/Recipient.html index 45ac4de1d..c2db9a818 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/Recipient.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/Recipient.html @@ -1,382 +1,387 @@ - - - - - -Recipient (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Recipient

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Recipient
-
-
-
-
public final class Recipient
extends java.lang.Object
-
- -

-An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC). -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

+

+
org.codemonkey.simplejavamail
+

Class Recipient

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/TransportStrategy.html b/javadoc/developers/org/codemonkey/simplejavamail/TransportStrategy.html index 064b9d285..9e61a62b6 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/TransportStrategy.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/TransportStrategy.html @@ -1,469 +1,457 @@ - - - - - -TransportStrategy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":6,"i2":6,"i3":6,"i4":6,"i5":9,"i6":9}; +var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Enum TransportStrategy

-
-java.lang.Object
-  extended by java.lang.Enum<TransportStrategy>
-      extended by org.codemonkey.simplejavamail.TransportStrategy
-
-
-
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<TransportStrategy>
-
-
-
-
public enum TransportStrategy
extends java.lang.Enum<TransportStrategy>
- - -

-Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation. -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

+

+
org.codemonkey.simplejavamail
+

Enum TransportStrategy

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/AttachmentResource.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/AttachmentResource.html index 16b5a116b..6045e9555 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/AttachmentResource.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/AttachmentResource.html @@ -1,215 +1,206 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.AttachmentResource (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.AttachmentResource

-
- - - - - -
-Uses of AttachmentResource in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Fields in org.codemonkey.simplejavamail with type parameters of type AttachmentResource
-private  java.util.List<AttachmentResource>Email.attachments - -
-          List of AttachmentResource.
-private  java.util.List<AttachmentResource>Email.embeddedImages - -
-          List of AttachmentResource.
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return types with arguments of type AttachmentResource
- java.util.List<AttachmentResource>Email.getAttachments() - -
-          Bean getter for Email.attachments as unmodifiable list.
- java.util.List<AttachmentResource>Email.getEmbeddedImages() - -
-          Bean getter for Email.embeddedImages as unmodifiable list.
-  -

- - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type AttachmentResource
-private  javax.mail.BodyPartMailer.getBodyPartFromDatasource(AttachmentResource resource, - java.lang.String dispositionType) - -
-          Helper method which generates a BodyPart from an AttachmentResource (from its DataSource) and a disposition - type (Part.INLINE or Part.ATTACHMENT).
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.AttachmentResource

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.Builder.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.Builder.html new file mode 100644 index 000000000..09f029a88 --- /dev/null +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.Builder.html @@ -0,0 +1,251 @@ + + + + + +Uses of Class org.codemonkey.simplejavamail.Email.Builder (Simple Java Mail API) + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Uses of Class
org.codemonkey.simplejavamail.Email.Builder

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.html index 6b336e422..48c904161 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Email.html @@ -1,236 +1,231 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Email (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Email

-
- - - - - -
-Uses of Email in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type Email
-private  javax.mail.MessageMailer.prepareMessage(Email email, - Mailer.MimeEmailMessageWrapper messageRoot) - -
-          Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send.
- voidMailer.sendMail(Email email) - -
-          Processes an Email instance into a completely configured Message.
-private  voidMailer.setAttachments(Email email, - javax.mail.internet.MimeMultipart multipartRoot) - -
-          Fills the Message instance with the attachments from the Email.
-private  voidMailer.setEmbeddedImages(Email email, - javax.mail.internet.MimeMultipart multipartRelated) - -
-          Fills the Message instance with the embedded images from the Email.
-private  voidMailer.setHeaders(Email email, - javax.mail.Message message) - -
-          Sets all headers on the Message instance.
-private  voidMailer.setRecipients(Email email, - javax.mail.Message message) - -
-          Fills the Message instance with recipients from the Email.
-private  voidMailer.setReplyTo(Email email, - javax.mail.Message message) - -
-          Fills the Message instance with reply-to address.
-private  voidMailer.setTexts(Email email, - javax.mail.internet.MimeMultipart multipartAlternativeMessages) - -
-          Fills the Message instance with the content bodies (text and html).
- booleanMailer.validate(Email email) - -
-          Validates an Email instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Email

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html index df4c4a88a..38c9f899f 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html @@ -1,199 +1,183 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.EmailAddressValidationCriteria (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.EmailAddressValidationCriteria

-
- - - - - -
-Uses of EmailAddressValidationCriteria in org.codemonkey.simplejavamail
-  -

- - - - - - - - - -
Fields in org.codemonkey.simplejavamail declared as EmailAddressValidationCriteria
-private  EmailAddressValidationCriteriaMailer.emailAddressValidationCriteria - -
-          Email address restriction flags set either by constructor or overridden by getter by user.
-  -

- - - - - - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type EmailAddressValidationCriteria
-protected static java.util.regex.PatternEmailValidationUtil.buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) - -
-           
-static booleanEmailValidationUtil.isValid(java.lang.String email, - EmailAddressValidationCriteria emailAddressValidationCriteria) - -
-          Validates an e-mail with given validation flags.
- voidMailer.setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) - -
-          Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.EmailAddressValidationCriteria

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html index 40fdcc0d2..df5d16284 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html @@ -1,142 +1,123 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.EmailValidationUtil (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.EmailValidationUtil

-
-No usage of org.codemonkey.simplejavamail.EmailValidationUtil -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.EmailValidationUtil

+
+
No usage of org.codemonkey.simplejavamail.EmailValidationUtil
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/MailException.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/MailException.html index 79522d78d..0038c8222 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/MailException.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/MailException.html @@ -1,173 +1,156 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.MailException (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.MailException

-
- - - - - -
-Uses of MailException in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that throw MailException
- voidMailer.sendMail(Email email) - -
-          Processes an Email instance into a completely configured Message.
- booleanMailer.validate(Email email) - -
-          Validates an Email instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.MailException

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.MimeEmailMessageWrapper.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.MimeEmailMessageWrapper.html index a52fdcae0..91d6cb4e5 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.MimeEmailMessageWrapper.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.MimeEmailMessageWrapper.html @@ -1,166 +1,151 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper

-
- - - - - -
-Uses of Mailer.MimeEmailMessageWrapper in org.codemonkey.simplejavamail
-  -

- - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type Mailer.MimeEmailMessageWrapper
-private  javax.mail.MessageMailer.prepareMessage(Email email, - Mailer.MimeEmailMessageWrapper messageRoot) - -
-          Creates a new MimeMessage instance and prepares it in the email structure, so that it can be filled and send.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Mailer.MimeEmailMessageWrapper

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.html index 0d355891b..995f1876b 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Mailer.html @@ -1,142 +1,123 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Mailer (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Mailer

-
-No usage of org.codemonkey.simplejavamail.Mailer -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Mailer

+
+
No usage of org.codemonkey.simplejavamail.Mailer
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Recipient.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Recipient.html index e00257623..678964e81 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/Recipient.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/Recipient.html @@ -1,229 +1,250 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Recipient (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Recipient

-
- - - - - -
-Uses of Recipient in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Fields in org.codemonkey.simplejavamail declared as Recipient
-private  RecipientEmail.fromRecipient - -
-          The sender of the email.
-private  RecipientEmail.replyToRecipient - -
-          The reply-to-address, optional.
-  -

- - - - - - - - - -
Fields in org.codemonkey.simplejavamail with type parameters of type Recipient
-private  java.util.List<Recipient>Email.recipients - -
-          List of Recipient.
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return Recipient
- RecipientEmail.getFromRecipient() - -
-          Bean getter for Email.fromRecipient.
- RecipientEmail.getReplyToRecipient() - -
-          Bean getter for Email.replyToRecipient.
-  -

- - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return types with arguments of type Recipient
- java.util.List<Recipient>Email.getRecipients() - -
-          Bean getter for Email.recipients as unmodifiable list.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Recipient

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/class-use/TransportStrategy.html b/javadoc/developers/org/codemonkey/simplejavamail/class-use/TransportStrategy.html index db66f5c82..395c58161 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/class-use/TransportStrategy.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/class-use/TransportStrategy.html @@ -1,225 +1,205 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.TransportStrategy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.TransportStrategy

-
- - - - - -
-Uses of TransportStrategy in org.codemonkey.simplejavamail
-  -

- - - - - - - - - -
Fields in org.codemonkey.simplejavamail declared as TransportStrategy
-private  TransportStrategyMailer.transportStrategy - -
-          The transport protocol strategy enum that actually handles the session configuration.
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return TransportStrategy
-static TransportStrategyTransportStrategy.valueOf(java.lang.String name) - -
-          Returns the enum constant of this type with the specified name.
-static TransportStrategy[]TransportStrategy.values() - -
-          Returns an array containing the constants of this enum type, in -the order they are declared.
-  -

- - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type TransportStrategy
-private  voidMailer.logSession(javax.mail.Session session, - TransportStrategy transportStrategy) - -
-          Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
-  -

- - - - - - - - -
Constructors in org.codemonkey.simplejavamail with parameters of type TransportStrategy
Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password, - TransportStrategy transportStrategy) - -
-          Overloaded constructor which produces a new Session on the fly.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.TransportStrategy

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/package-frame.html b/javadoc/developers/org/codemonkey/simplejavamail/package-frame.html index d3a24f551..a83e66632 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/package-frame.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/package-frame.html @@ -1,64 +1,34 @@ - - - - - -org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - - - - - -org.codemonkey.simplejavamail - - - - -
-Classes  - -
-AttachmentResource -
-Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-Recipient
- - - - - - -
-Enums  - -
-TransportStrategy
- - - - - - -
-Exceptions  - -
-MailException
- - - - + + + + +org.codemonkey.simplejavamail (Simple Java Mail API) + + + + + +

org.codemonkey.simplejavamail

+
+

Classes

+ +

Enums

+ +

Exceptions

+ +
+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/package-summary.html b/javadoc/developers/org/codemonkey/simplejavamail/package-summary.html index f1a25696b..20866756d 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/package-summary.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/package-summary.html @@ -1,204 +1,214 @@ - - - - - -org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-

-Package org.codemonkey.simplejavamail -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Class Summary
AttachmentResourceA named immutable email attachment information object.
EmailEmail message with all necessary data for an effective mailing action, including attachments etc.
EmailAddressValidationCriteriaDefines a set of restriction flags for email address validation.
EmailValidationUtilValidates an email address according to RFC 2822, using regular expressions.
MailerMailing tool aimed for simplicity, for sending e-mails of any complexity.
RecipientAn immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
-  - -

- - - - - - - - - -
-Enum Summary
TransportStrategyDefines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
-  - -

- - - - - - - - - -
-Exception Summary
MailExceptionThis exception is used to communicate errors during the sending of email.
-  - -

-

-
-
- - +
+

Package org.codemonkey.simplejavamail

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/package-tree.html b/javadoc/developers/org/codemonkey/simplejavamail/package-tree.html index 89c6fd4b0..758a9d52b 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/package-tree.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/package-tree.html @@ -1,165 +1,164 @@ - - - - - -org.codemonkey.simplejavamail Class Hierarchy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For Package org.codemonkey.simplejavamail -

-
-

-Class Hierarchy -

- -

-Enum Hierarchy -

- -
- - +
+

Hierarchy For Package org.codemonkey.simplejavamail

+
+
+

Class Hierarchy

+ +

Enum Hierarchy

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/org/codemonkey/simplejavamail/package-use.html b/javadoc/developers/org/codemonkey/simplejavamail/package-use.html index 51d7bf04e..57cbc4c90 100644 --- a/javadoc/developers/org/codemonkey/simplejavamail/package-use.html +++ b/javadoc/developers/org/codemonkey/simplejavamail/package-use.html @@ -1,192 +1,179 @@ - - - - - -Uses of Package org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Package
org.codemonkey.simplejavamail

-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
-Classes in org.codemonkey.simplejavamail used by org.codemonkey.simplejavamail
AttachmentResource - -
-          A named immutable email attachment information object.
Email - -
-          Email message with all necessary data for an effective mailing action, including attachments etc.
EmailAddressValidationCriteria - -
-          Defines a set of restriction flags for email address validation.
Mailer.MimeEmailMessageWrapper - -
-          This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc.
MailException - -
-          This exception is used to communicate errors during the sending of email.
Recipient - -
-          An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
TransportStrategy - -
-          Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
-  -

-


- - +
+

Uses of Package
org.codemonkey.simplejavamail

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/overview-tree.html b/javadoc/developers/overview-tree.html index 84f8d40c6..190b1c19e 100644 --- a/javadoc/developers/overview-tree.html +++ b/javadoc/developers/overview-tree.html @@ -1,167 +1,168 @@ - - - - - -Class Hierarchy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
org.codemonkey.simplejavamail
-
-

-Class Hierarchy -

- -

-Enum Hierarchy -

- -
- - +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +

Enum Hierarchy

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/script.js b/javadoc/developers/script.js new file mode 100644 index 000000000..b34635693 --- /dev/null +++ b/javadoc/developers/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/javadoc/developers/serialized-form.html b/javadoc/developers/serialized-form.html index e57efa872..428861856 100644 --- a/javadoc/developers/serialized-form.html +++ b/javadoc/developers/serialized-form.html @@ -1,161 +1,136 @@ - - - - - -Serialized Form (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Serialized Form

-
-
- - - - - -
-Package org.codemonkey.simplejavamail
- -

- - - - - -
-Class org.codemonkey.simplejavamail.MailException extends java.lang.RuntimeException implements Serializable
- -

- -

-


- - +
+

Serialized Form

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/AttachmentResource.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/AttachmentResource.html index 1fc13e261..9670e4927 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/AttachmentResource.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/AttachmentResource.html @@ -1,56 +1,61 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import javax.activation.DataSource;
-004    
-005    /**
-006     * A named immutable email attachment information object. The name can be a simple name, a filename or a named embedded
-007     * image (eg. &lt;cid:footer&gt;). Contains a {@link DataSource} that is compatible with the javax.mail API.
-008     * 
-009     * @author Benny Bottema
-010     * @see DataSource
-011     */
-012    final class AttachmentResource {
-013    
-014            /**
-015             * @see #AttachmentResource(String, DataSource)
-016             */
-017            private final String name;
-018    
-019            /**
-020             * @see #AttachmentResource(String, DataSource)
-021             */
-022            private final DataSource dataSource;
-023    
-024            /**
-025             * Constructor; initializes the attachment resource with a name and data.
-026             * 
-027             * @param name The name of the attachment which can be a simple name, a filename or a named embedded image (eg.
-028             *            &lt;cid:footer&gt;)
-029             * @param dataSource The attachment data.
-030             * @see DataSource
-031             */
-032            public AttachmentResource(final String name, final DataSource dataSource) {
-033                    this.name = name;
-034                    this.dataSource = dataSource;
-035            }
-036    
-037            /**
-038             * Bean getter for {@link #dataSource}.
-039             */
-040            public DataSource getDataSource() {
-041                    return dataSource;
-042            }
-043    
-044            /**
-045             * Bean getter for {@link #name}.
-046             */
-047            public String getName() {
-048                    return name;
-049            }
-050    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import javax.activation.DataSource;
+004
+005/**
+006 * A named immutable email attachment information object. The name can be a simple name, a filename or a named embedded
+007 * image (eg. &lt;cid:footer&gt;). Contains a {@link DataSource} that is compatible with the javax.mail API.
+008 * 
+009 * @author Benny Bottema
+010 * @see DataSource
+011 */
+012final class AttachmentResource {
+013
+014        /**
+015         * @see #AttachmentResource(String, DataSource)
+016         */
+017        private final String name;
+018
+019        /**
+020         * @see #AttachmentResource(String, DataSource)
+021         */
+022        private final DataSource dataSource;
+023
+024        /**
+025         * Constructor; initializes the attachment resource with a name and data.
+026         * 
+027         * @param name The name of the attachment which can be a simple name, a filename or a named embedded image (eg.
+028         *            &lt;cid:footer&gt;)
+029         * @param dataSource The attachment data.
+030         * @see DataSource
+031         */
+032        public AttachmentResource(final String name, final DataSource dataSource) {
+033                this.name = name;
+034                this.dataSource = dataSource;
+035        }
+036
+037        /**
+038         * Bean getter for {@link #dataSource}.
+039         */
+040        public DataSource getDataSource() {
+041                return dataSource;
+042        }
+043
+044        /**
+045         * Bean getter for {@link #name}.
+046         */
+047        public String getName() {
+048                return name;
+049        }
+050}
 
 
 
@@ -111,6 +116,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.Builder.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.Builder.html new file mode 100644 index 000000000..c273d9ad0 --- /dev/null +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.Builder.html @@ -0,0 +1,599 @@ + + + +Source code + + + +
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.ArrayList;
+004import java.util.Collections;
+005import java.util.HashMap;
+006import java.util.List;
+007import java.util.Map;
+008
+009import javax.activation.DataSource;
+010import javax.mail.Message.RecipientType;
+011import javax.mail.util.ByteArrayDataSource;
+012
+013/**
+014 * Email message with all necessary data for an effective mailing action, including attachments etc.
+015 *
+016 * @author Benny Bottema
+017 */
+018public class Email {
+019        /**
+020         * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
+021         */
+022        private Recipient fromRecipient;
+023        /**
+024         * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+025         */
+026        private Recipient replyToRecipient;
+027
+028        /**
+029         * The email message body in plain text.
+030         */
+031        private String text;
+032
+033        /**
+034         * The email message body in html.
+035         */
+036        private String textHTML;
+037
+038        /**
+039         * The subject of the email message.
+040         */
+041        private String subject;
+042
+043        /**
+044         * List of {@link Recipient}.
+045         */
+046        private final List<Recipient> recipients;
+047
+048        /**
+049         * List of {@link AttachmentResource}.
+050         */
+051        private final List<AttachmentResource> embeddedImages;
+052
+053        /**
+054         * List of {@link AttachmentResource}.
+055         */
+056        private final List<AttachmentResource> attachments;
+057
+058        /**
+059         * Map of header name and values, such as <code>X-Priority</code> etc.
+060         */
+061        private final Map<String, String> headers;
+062
+063        /**
+064         * Constructor, creates all internal lists.
+065         */
+066        public Email() {
+067                recipients = new ArrayList<Recipient>();
+068                embeddedImages = new ArrayList<AttachmentResource>();
+069                attachments = new ArrayList<AttachmentResource>();
+070                headers = new HashMap<String, String>();
+071        }
+072
+073        /**
+074         * Sets the sender address.
+075         *
+076         * @param name The sender's name.
+077         * @param fromAddress The sender's email address.
+078         */
+079        public void setFromAddress(final String name, final String fromAddress) {
+080                fromRecipient = new Recipient(name, fromAddress, null);
+081        }
+082
+083        /**
+084         * Sets the reply-to address (optional).
+085         *
+086         * @param name The replied-to-receiver name.
+087         * @param replyToAddress The replied-to-receiver email address.
+088         */
+089        public void setReplyToAddress(final String name, final String replyToAddress) {
+090                replyToRecipient = new Recipient(name, replyToAddress, null);
+091        }
+092
+093        /**
+094         * Bean setters for {@link #subject}.
+095         */
+096        public void setSubject(final String subject) {
+097                this.subject = subject;
+098        }
+099
+100        /**
+101         * Bean setters for {@link #text}.
+102         */
+103        public void setText(final String text) {
+104                this.text = text;
+105        }
+106
+107        /**
+108         * Bean setters for {@link #textHTML}.
+109         */
+110        public void setTextHTML(final String textHTML) {
+111                this.textHTML = textHTML;
+112        }
+113
+114        /**
+115         * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
+116         *
+117         * @param name The name of the recipient.
+118         * @param address The emailadres of the recipient.
+119         * @param type The type of receiver (eg. {@link RecipientType#CC}).
+120         * @see #recipients
+121         * @see Recipient
+122         * @see RecipientType
+123         */
+124        public void addRecipient(final String name, final String address, final RecipientType type) {
+125                recipients.add(new Recipient(name, address, type));
+126        }
+127
+128        /**
+129         * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+130         * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+131         * {@link ByteArrayDataSource}.
+132         *
+133         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+134         * @param data The byte data of the image to be embedded.
+135         * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+136         * @see ByteArrayDataSource
+137         * @see #addEmbeddedImage(String, DataSource)
+138         */
+139        public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
+140                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+141                dataSource.setName(name);
+142                addEmbeddedImage(name, dataSource);
+143        }
+144
+145        /**
+146         * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+147         *
+148         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+149         * @param imagedata The image data.
+150         */
+151        public void addEmbeddedImage(final String name, final DataSource imagedata) {
+152                embeddedImages.add(new AttachmentResource(name, imagedata));
+153        }
+154
+155        /**
+156         * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+157         * <p>
+158         * example: <code>email.addHeader("X-Priority", 2)</code>
+159         *
+160         * @param name The name of the header.
+161         * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+162         */
+163        public void addHeader(final String name, final Object value) {
+164                headers.put(name, String.valueOf(value));
+165        }
+166
+167        /**
+168         * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+169         * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+170         *
+171         * @param name The name of the extension (eg. filename including extension).
+172         * @param data The byte data of the attachment.
+173         * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+174         * @see ByteArrayDataSource
+175         * @see #addAttachment(String, DataSource)
+176         */
+177        public void addAttachment(final String name, final byte[] data, final String mimetype) {
+178                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+179                dataSource.setName(name);
+180                addAttachment(name, dataSource);
+181        }
+182
+183        /**
+184         * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+185         *
+186         * @param name The name of the attachment (eg. 'filename.ext').
+187         * @param filedata The attachment data.
+188         */
+189        public void addAttachment(final String name, final DataSource filedata) {
+190                attachments.add(new AttachmentResource(name, filedata));
+191        }
+192
+193        /**
+194         * Bean getter for {@link #fromRecipient}.
+195         */
+196        public Recipient getFromRecipient() {
+197                return fromRecipient;
+198        }
+199
+200        /**
+201         * Bean getter for {@link #replyToRecipient}.
+202         */
+203        public Recipient getReplyToRecipient() {
+204                return replyToRecipient;
+205        }
+206
+207        /**
+208         * Bean getter for {@link #subject}.
+209         */
+210        public String getSubject() {
+211                return subject;
+212        }
+213
+214        /**
+215         * Bean getter for {@link #text}.
+216         */
+217        public String getText() {
+218                return text;
+219        }
+220
+221        /**
+222         * Bean getter for {@link #textHTML}.
+223         */
+224        public String getTextHTML() {
+225                return textHTML;
+226        }
+227
+228        /**
+229         * Bean getter for {@link #attachments} as unmodifiable list.
+230         */
+231        public List<AttachmentResource> getAttachments() {
+232                return Collections.unmodifiableList(attachments);
+233        }
+234
+235        /**
+236         * Bean getter for {@link #embeddedImages} as unmodifiable list.
+237         */
+238        public List<AttachmentResource> getEmbeddedImages() {
+239                return Collections.unmodifiableList(embeddedImages);
+240        }
+241
+242        /**
+243         * Bean getter for {@link #recipients} as unmodifiable list.
+244         */
+245        public List<Recipient> getRecipients() {
+246                return Collections.unmodifiableList(recipients);
+247        }
+248
+249        /**
+250         * Bean getter for {@link #headers} as unmodifiable map.
+251         */
+252        public Map<String, String> getHeaders() {
+253                return Collections.unmodifiableMap(headers);
+254        }
+255
+256        /**
+257         * Fluent interface Builder for Emails
+258         * @author Jared Stewart
+259         */
+260        public static class Builder {
+261                private Recipient fromRecipient;
+262                /**
+263                 * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+264                 */
+265                private Recipient replyToRecipient;
+266
+267                /**
+268                 * The email message body in plain text.
+269                 */
+270                private String text;
+271
+272                /**
+273                 * The email message body in html.
+274                 */
+275                private String textHTML;
+276
+277                /**
+278                 * The subject of the email message.
+279                 */
+280                private String subject;
+281
+282                /**
+283                 * List of {@link Recipient}.
+284                 */
+285                private final List<Recipient> recipients;
+286
+287                /**
+288                 * List of {@link AttachmentResource}.
+289                 */
+290                private final List<AttachmentResource> embeddedImages;
+291
+292                /**
+293                 * List of {@link AttachmentResource}.
+294                 */
+295                private final List<AttachmentResource> attachments;
+296
+297                /**
+298                 * Map of header name and values, such as <code>X-Priority</code> etc.
+299                 */
+300                private final Map<String, String> headers;
+301
+302                private Email email;
+303
+304                public Builder() {
+305                        recipients = new ArrayList<Recipient>();
+306                        embeddedImages = new ArrayList<AttachmentResource>();
+307                        attachments = new ArrayList<AttachmentResource>();
+308                        headers = new HashMap<String, String>();
+309                }
+310
+311                /**
+312                 *
+313                 */
+314                public Email build() {
+315                        return new Email(this);
+316                }
+317
+318                /**
+319                 * Sets the sender address.
+320                 *
+321                 * @param name The sender's name.
+322                 * @param fromAddress The sender's email address.
+323                 */
+324                public Builder from(final String name, final String fromAddress){
+325                        this.fromRecipient = new Recipient(name, fromAddress, null);
+326                        return this;
+327                }
+328
+329                /**
+330                 * Sets the reply-to address (optional).
+331                 *
+332                 * @param name The replied-to-receiver name.
+333                 * @param replyToAddress The replied-to-receiver email address.
+334                 */
+335                public Builder replyTo(final String name, final String replyToAddress) {
+336                        this.replyToRecipient = new Recipient(name, replyToAddress, null);
+337                        return this;
+338                }
+339
+340
+341                /**
+342                 * Sets the {@link #subject}.
+343                 */
+344                public Builder subject(final String subject) {
+345                        this.subject = subject;
+346                        return this;
+347                }
+348
+349                /**
+350                 * Sets the {@link #text}.
+351                 */
+352                public Builder text(final String text) {
+353                        this.text = text;
+354                        return this;
+355                }
+356
+357                /**
+358                 * Sets the {@link #textHTML}.
+359                 */
+360                public Builder textHTML(final String textHTML) {
+361                        this.textHTML = textHTML;
+362                        return this;
+363                }
+364
+365                /**
+366                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+367                 *
+368                 * @param name The name of the recipient.
+369                 * @param address The emailaddress of the recipient.
+370                 * @see #recipients
+371                 * @see Recipient
+372                 */
+373                public Builder to(final String name, final String address) {
+374                        recipients.add(new Recipient(name, address, RecipientType.TO));
+375                        return this;
+376                }
+377
+378                /**
+379                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+380                 *
+381                 * @param recipient The recipent whose name and address to use
+382                 * @see #recipients
+383                 * @see Recipient
+384                 */
+385                public Builder to(final Recipient recipient) {
+386                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.TO));
+387                        return this;
+388                }
+389
+390
+391
+392                /**
+393                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+394                 *
+395                 * @param name The name of the recipient.
+396                 * @param address The emailaddress of the recipient.
+397                 * @see #recipients
+398                 * @see Recipient
+399                 */
+400                public Builder cc(final String name, final String address) {
+401                        recipients.add(new Recipient(name, address, RecipientType.CC));
+402                        return this;
+403                }
+404
+405                /**
+406                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+407                 *
+408                 * @param recipient The recipent whose name and address to use
+409                 * @see #recipients
+410                 * @see Recipient
+411                 */
+412                public Builder cc(final Recipient recipient) {
+413                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.CC));
+414                        return this;
+415                }
+416
+417                /**
+418                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+419                 *
+420                 * @param name The name of the recipient.
+421                 * @param address The emailaddress of the recipient.
+422                 * @see #recipients
+423                 * @see Recipient
+424                 */
+425                public Builder bcc(final String name, final String address) {
+426                        recipients.add(new Recipient(name, address, RecipientType.BCC));
+427                        return this;
+428                }
+429
+430                /**
+431                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+432                 *
+433                 * @param recipient The recipent whose name and address to use
+434                 * @see #recipients
+435                 * @see Recipient
+436                 */
+437                public Builder bcc(final Recipient recipient) {
+438                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.BCC));
+439                        return this;
+440                }
+441
+442                /**
+443                 * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+444                 * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+445                 * {@link ByteArrayDataSource}.
+446                 *
+447                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+448                 * @param data The byte data of the image to be embedded.
+449                 * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+450                 * @see ByteArrayDataSource
+451                 * @see #addEmbeddedImage(String, DataSource)
+452                 */
+453                public Builder embedImage(final String name, final byte[] data, final String mimetype) {
+454                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+455                        dataSource.setName(name);
+456                        return embedImage(name, dataSource);
+457                }
+458
+459                /**
+460                 * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+461                 *
+462                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+463                 * @param imagedata The image data.
+464                 */
+465                public Builder embedImage(final String name, final DataSource imagedata) {
+466                        embeddedImages.add(new AttachmentResource(name, imagedata));
+467                        return this;
+468                }
+469
+470                /**
+471                 * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+472                 * <p>
+473                 * example: <code>email.addHeader("X-Priority", 2)</code>
+474                 *
+475                 * @param name The name of the header.
+476                 * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+477                 */
+478                public Builder addHeader(final String name, final Object value) {
+479                        headers.put(name, String.valueOf(value));
+480                        return this;
+481                }
+482
+483                /**
+484                 * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+485                 * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+486                 *
+487                 * @param name The name of the extension (eg. filename including extension).
+488                 * @param data The byte data of the attachment.
+489                 * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+490                 * @see ByteArrayDataSource
+491                 * @see #addAttachment(String, DataSource)
+492                 */
+493                public void addAttachment(final String name, final byte[] data, final String mimetype) {
+494                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+495                        dataSource.setName(name);
+496                        addAttachment(name, dataSource);
+497                }
+498
+499                /**
+500                 * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+501                 *
+502                 * @param name The name of the attachment (eg. 'filename.ext').
+503                 * @param filedata The attachment data.
+504                 */
+505                public void addAttachment(final String name, final DataSource filedata) {
+506                        attachments.add(new AttachmentResource(name, filedata));
+507                }
+508
+509        }
+510
+511        /**
+512         * Constructor for the Builder class
+513         * @param builder The builder from which to create the email.
+514         */
+515        private Email(Builder builder) {
+516                recipients = builder.recipients;
+517                embeddedImages = builder.embeddedImages;
+518                attachments = builder.attachments;
+519                headers = builder.headers;
+520
+521                fromRecipient = builder.fromRecipient;
+522                replyToRecipient = builder.replyToRecipient;
+523                text = builder.text;
+524                textHTML = builder.textHTML;
+525                subject = builder.subject;
+526        }
+527}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.html index 179dfa8e3..be488641e 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Email.html @@ -1,261 +1,538 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.util.ArrayList;
-004    import java.util.Collections;
-005    import java.util.HashMap;
-006    import java.util.List;
-007    import java.util.Map;
-008    
-009    import javax.activation.DataSource;
-010    import javax.mail.Message.RecipientType;
-011    import javax.mail.util.ByteArrayDataSource;
-012    
-013    /**
-014     * Email message with all necessary data for an effective mailing action, including attachments etc.
-015     * 
-016     * @author Benny Bottema
-017     */
-018    public class Email {
-019            /**
-020             * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
-021             */
-022            private Recipient fromRecipient;
-023            /**
-024             * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
-025             */
-026            private Recipient replyToRecipient;
-027    
-028            /**
-029             * The email message body in plain text.
-030             */
-031            private String text;
-032    
-033            /**
-034             * The email message body in html.
-035             */
-036            private String textHTML;
-037    
-038            /**
-039             * The subject of the email message.
-040             */
-041            private String subject;
-042    
-043            /**
-044             * List of {@link Recipient}.
-045             */
-046            private final List<Recipient> recipients;
-047    
-048            /**
-049             * List of {@link AttachmentResource}.
-050             */
-051            private final List<AttachmentResource> embeddedImages;
-052    
-053            /**
-054             * List of {@link AttachmentResource}.
-055             */
-056            private final List<AttachmentResource> attachments;
-057    
-058            /**
-059             * Map of header name and values, such as <code>X-Priority</code> etc.
-060             */
-061            private final Map<String, String> headers;
-062    
-063            /**
-064             * Constructor, creates all internal lists.
-065             */
-066            public Email() {
-067                    recipients = new ArrayList<Recipient>();
-068                    embeddedImages = new ArrayList<AttachmentResource>();
-069                    attachments = new ArrayList<AttachmentResource>();
-070                    headers = new HashMap<String, String>();
-071            }
-072    
-073            /**
-074             * Sets the sender address.
-075             * 
-076             * @param name The sender's name.
-077             * @param fromAddress The sender's email address.
-078             */
-079            public void setFromAddress(final String name, final String fromAddress) {
-080                    fromRecipient = new Recipient(name, fromAddress, null);
-081            }
-082    
-083            /**
-084             * Sets the reply-to address (optional).
-085             * 
-086             * @param name The replied-to-receiver name.
-087             * @param replyToAddress The replied-to-receiver email address.
-088             */
-089            public void setReplyToAddress(final String name, final String replyToAddress) {
-090                    replyToRecipient = new Recipient(name, replyToAddress, null);
-091            }
-092    
-093            /**
-094             * Bean setters for {@link #subject}.
-095             */
-096            public void setSubject(final String subject) {
-097                    this.subject = subject;
-098            }
-099    
-100            /**
-101             * Bean setters for {@link #text}.
-102             */
-103            public void setText(final String text) {
-104                    this.text = text;
-105            }
-106    
-107            /**
-108             * Bean setters for {@link #textHTML}.
-109             */
-110            public void setTextHTML(final String textHTML) {
-111                    this.textHTML = textHTML;
-112            }
-113    
-114            /**
-115             * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
-116             * 
-117             * @param name The name of the recipient.
-118             * @param address The emailadres of the recipient.
-119             * @param type The type of receiver (eg. {@link RecipientType#CC}).
-120             * @see #recipients
-121             * @see Recipient
-122             * @see RecipientType
-123             */
-124            public void addRecipient(final String name, final String address, final RecipientType type) {
-125                    recipients.add(new Recipient(name, address, type));
-126            }
-127    
-128            /**
-129             * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
-130             * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
-131             * {@link ByteArrayDataSource}.
-132             * 
-133             * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
-134             * @param data The byte data of the image to be embedded.
-135             * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
-136             * @see ByteArrayDataSource
-137             * @see #addEmbeddedImage(String, DataSource)
-138             */
-139            public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
-140                    final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
-141                    dataSource.setName(name);
-142                    addEmbeddedImage(name, dataSource);
-143            }
-144    
-145            /**
-146             * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
-147             * 
-148             * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
-149             * @param imagedata The image data.
-150             */
-151            public void addEmbeddedImage(final String name, final DataSource imagedata) {
-152                    embeddedImages.add(new AttachmentResource(name, imagedata));
-153            }
-154    
-155            /**
-156             * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
-157             * <p>
-158             * example: <code>email.addHeader("X-Priority", 2)</code>
-159             * 
-160             * @param name The name of the header.
-161             * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
-162             */
-163            public void addHeader(final String name, final Object value) {
-164                    headers.put(name, String.valueOf(value));
-165            }
-166    
-167            /**
-168             * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
-169             * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
-170             * 
-171             * @param name The name of the extension (eg. filename including extension).
-172             * @param data The byte data of the attachment.
-173             * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
-174             * @see ByteArrayDataSource
-175             * @see #addAttachment(String, DataSource)
-176             */
-177            public void addAttachment(final String name, final byte[] data, final String mimetype) {
-178                    final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
-179                    dataSource.setName(name);
-180                    addAttachment(name, dataSource);
-181            }
-182    
-183            /**
-184             * Overloaded method which sets an attachment on account of name and {@link DataSource}.
-185             * 
-186             * @param name The name of the attachment (eg. 'filename.ext').
-187             * @param filedata The attachment data.
-188             */
-189            public void addAttachment(final String name, final DataSource filedata) {
-190                    attachments.add(new AttachmentResource(name, filedata));
-191            }
-192    
-193            /**
-194             * Bean getter for {@link #fromRecipient}.
-195             */
-196            public Recipient getFromRecipient() {
-197                    return fromRecipient;
-198            }
-199    
-200            /**
-201             * Bean getter for {@link #replyToRecipient}.
-202             */
-203            public Recipient getReplyToRecipient() {
-204                    return replyToRecipient;
-205            }
-206    
-207            /**
-208             * Bean getter for {@link #subject}.
-209             */
-210            public String getSubject() {
-211                    return subject;
-212            }
-213    
-214            /**
-215             * Bean getter for {@link #text}.
-216             */
-217            public String getText() {
-218                    return text;
-219            }
-220    
-221            /**
-222             * Bean getter for {@link #textHTML}.
-223             */
-224            public String getTextHTML() {
-225                    return textHTML;
-226            }
-227    
-228            /**
-229             * Bean getter for {@link #attachments} as unmodifiable list.
-230             */
-231            public List<AttachmentResource> getAttachments() {
-232                    return Collections.unmodifiableList(attachments);
-233            }
-234    
-235            /**
-236             * Bean getter for {@link #embeddedImages} as unmodifiable list.
-237             */
-238            public List<AttachmentResource> getEmbeddedImages() {
-239                    return Collections.unmodifiableList(embeddedImages);
-240            }
-241    
-242            /**
-243             * Bean getter for {@link #recipients} as unmodifiable list.
-244             */
-245            public List<Recipient> getRecipients() {
-246                    return Collections.unmodifiableList(recipients);
-247            }
-248    
-249            /**
-250             * Bean getter for {@link #headers} as unmodifiable map.
-251             */
-252            public Map<String, String> getHeaders() {
-253                    return Collections.unmodifiableMap(headers);
-254            }
-255    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.ArrayList;
+004import java.util.Collections;
+005import java.util.HashMap;
+006import java.util.List;
+007import java.util.Map;
+008
+009import javax.activation.DataSource;
+010import javax.mail.Message.RecipientType;
+011import javax.mail.util.ByteArrayDataSource;
+012
+013/**
+014 * Email message with all necessary data for an effective mailing action, including attachments etc.
+015 *
+016 * @author Benny Bottema
+017 */
+018public class Email {
+019        /**
+020         * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
+021         */
+022        private Recipient fromRecipient;
+023        /**
+024         * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+025         */
+026        private Recipient replyToRecipient;
+027
+028        /**
+029         * The email message body in plain text.
+030         */
+031        private String text;
+032
+033        /**
+034         * The email message body in html.
+035         */
+036        private String textHTML;
+037
+038        /**
+039         * The subject of the email message.
+040         */
+041        private String subject;
+042
+043        /**
+044         * List of {@link Recipient}.
+045         */
+046        private final List<Recipient> recipients;
+047
+048        /**
+049         * List of {@link AttachmentResource}.
+050         */
+051        private final List<AttachmentResource> embeddedImages;
+052
+053        /**
+054         * List of {@link AttachmentResource}.
+055         */
+056        private final List<AttachmentResource> attachments;
+057
+058        /**
+059         * Map of header name and values, such as <code>X-Priority</code> etc.
+060         */
+061        private final Map<String, String> headers;
+062
+063        /**
+064         * Constructor, creates all internal lists.
+065         */
+066        public Email() {
+067                recipients = new ArrayList<Recipient>();
+068                embeddedImages = new ArrayList<AttachmentResource>();
+069                attachments = new ArrayList<AttachmentResource>();
+070                headers = new HashMap<String, String>();
+071        }
+072
+073        /**
+074         * Sets the sender address.
+075         *
+076         * @param name The sender's name.
+077         * @param fromAddress The sender's email address.
+078         */
+079        public void setFromAddress(final String name, final String fromAddress) {
+080                fromRecipient = new Recipient(name, fromAddress, null);
+081        }
+082
+083        /**
+084         * Sets the reply-to address (optional).
+085         *
+086         * @param name The replied-to-receiver name.
+087         * @param replyToAddress The replied-to-receiver email address.
+088         */
+089        public void setReplyToAddress(final String name, final String replyToAddress) {
+090                replyToRecipient = new Recipient(name, replyToAddress, null);
+091        }
+092
+093        /**
+094         * Bean setters for {@link #subject}.
+095         */
+096        public void setSubject(final String subject) {
+097                this.subject = subject;
+098        }
+099
+100        /**
+101         * Bean setters for {@link #text}.
+102         */
+103        public void setText(final String text) {
+104                this.text = text;
+105        }
+106
+107        /**
+108         * Bean setters for {@link #textHTML}.
+109         */
+110        public void setTextHTML(final String textHTML) {
+111                this.textHTML = textHTML;
+112        }
+113
+114        /**
+115         * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
+116         *
+117         * @param name The name of the recipient.
+118         * @param address The emailadres of the recipient.
+119         * @param type The type of receiver (eg. {@link RecipientType#CC}).
+120         * @see #recipients
+121         * @see Recipient
+122         * @see RecipientType
+123         */
+124        public void addRecipient(final String name, final String address, final RecipientType type) {
+125                recipients.add(new Recipient(name, address, type));
+126        }
+127
+128        /**
+129         * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+130         * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+131         * {@link ByteArrayDataSource}.
+132         *
+133         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+134         * @param data The byte data of the image to be embedded.
+135         * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+136         * @see ByteArrayDataSource
+137         * @see #addEmbeddedImage(String, DataSource)
+138         */
+139        public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
+140                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+141                dataSource.setName(name);
+142                addEmbeddedImage(name, dataSource);
+143        }
+144
+145        /**
+146         * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+147         *
+148         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+149         * @param imagedata The image data.
+150         */
+151        public void addEmbeddedImage(final String name, final DataSource imagedata) {
+152                embeddedImages.add(new AttachmentResource(name, imagedata));
+153        }
+154
+155        /**
+156         * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+157         * <p>
+158         * example: <code>email.addHeader("X-Priority", 2)</code>
+159         *
+160         * @param name The name of the header.
+161         * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+162         */
+163        public void addHeader(final String name, final Object value) {
+164                headers.put(name, String.valueOf(value));
+165        }
+166
+167        /**
+168         * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+169         * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+170         *
+171         * @param name The name of the extension (eg. filename including extension).
+172         * @param data The byte data of the attachment.
+173         * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+174         * @see ByteArrayDataSource
+175         * @see #addAttachment(String, DataSource)
+176         */
+177        public void addAttachment(final String name, final byte[] data, final String mimetype) {
+178                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+179                dataSource.setName(name);
+180                addAttachment(name, dataSource);
+181        }
+182
+183        /**
+184         * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+185         *
+186         * @param name The name of the attachment (eg. 'filename.ext').
+187         * @param filedata The attachment data.
+188         */
+189        public void addAttachment(final String name, final DataSource filedata) {
+190                attachments.add(new AttachmentResource(name, filedata));
+191        }
+192
+193        /**
+194         * Bean getter for {@link #fromRecipient}.
+195         */
+196        public Recipient getFromRecipient() {
+197                return fromRecipient;
+198        }
+199
+200        /**
+201         * Bean getter for {@link #replyToRecipient}.
+202         */
+203        public Recipient getReplyToRecipient() {
+204                return replyToRecipient;
+205        }
+206
+207        /**
+208         * Bean getter for {@link #subject}.
+209         */
+210        public String getSubject() {
+211                return subject;
+212        }
+213
+214        /**
+215         * Bean getter for {@link #text}.
+216         */
+217        public String getText() {
+218                return text;
+219        }
+220
+221        /**
+222         * Bean getter for {@link #textHTML}.
+223         */
+224        public String getTextHTML() {
+225                return textHTML;
+226        }
+227
+228        /**
+229         * Bean getter for {@link #attachments} as unmodifiable list.
+230         */
+231        public List<AttachmentResource> getAttachments() {
+232                return Collections.unmodifiableList(attachments);
+233        }
+234
+235        /**
+236         * Bean getter for {@link #embeddedImages} as unmodifiable list.
+237         */
+238        public List<AttachmentResource> getEmbeddedImages() {
+239                return Collections.unmodifiableList(embeddedImages);
+240        }
+241
+242        /**
+243         * Bean getter for {@link #recipients} as unmodifiable list.
+244         */
+245        public List<Recipient> getRecipients() {
+246                return Collections.unmodifiableList(recipients);
+247        }
+248
+249        /**
+250         * Bean getter for {@link #headers} as unmodifiable map.
+251         */
+252        public Map<String, String> getHeaders() {
+253                return Collections.unmodifiableMap(headers);
+254        }
+255
+256        /**
+257         * Fluent interface Builder for Emails
+258         * @author Jared Stewart
+259         */
+260        public static class Builder {
+261                private Recipient fromRecipient;
+262                /**
+263                 * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+264                 */
+265                private Recipient replyToRecipient;
+266
+267                /**
+268                 * The email message body in plain text.
+269                 */
+270                private String text;
+271
+272                /**
+273                 * The email message body in html.
+274                 */
+275                private String textHTML;
+276
+277                /**
+278                 * The subject of the email message.
+279                 */
+280                private String subject;
+281
+282                /**
+283                 * List of {@link Recipient}.
+284                 */
+285                private final List<Recipient> recipients;
+286
+287                /**
+288                 * List of {@link AttachmentResource}.
+289                 */
+290                private final List<AttachmentResource> embeddedImages;
+291
+292                /**
+293                 * List of {@link AttachmentResource}.
+294                 */
+295                private final List<AttachmentResource> attachments;
+296
+297                /**
+298                 * Map of header name and values, such as <code>X-Priority</code> etc.
+299                 */
+300                private final Map<String, String> headers;
+301
+302                private Email email;
+303
+304                public Builder() {
+305                        recipients = new ArrayList<Recipient>();
+306                        embeddedImages = new ArrayList<AttachmentResource>();
+307                        attachments = new ArrayList<AttachmentResource>();
+308                        headers = new HashMap<String, String>();
+309                }
+310
+311                /**
+312                 *
+313                 */
+314                public Email build() {
+315                        return new Email(this);
+316                }
+317
+318                /**
+319                 * Sets the sender address.
+320                 *
+321                 * @param name The sender's name.
+322                 * @param fromAddress The sender's email address.
+323                 */
+324                public Builder from(final String name, final String fromAddress){
+325                        this.fromRecipient = new Recipient(name, fromAddress, null);
+326                        return this;
+327                }
+328
+329                /**
+330                 * Sets the reply-to address (optional).
+331                 *
+332                 * @param name The replied-to-receiver name.
+333                 * @param replyToAddress The replied-to-receiver email address.
+334                 */
+335                public Builder replyTo(final String name, final String replyToAddress) {
+336                        this.replyToRecipient = new Recipient(name, replyToAddress, null);
+337                        return this;
+338                }
+339
+340
+341                /**
+342                 * Sets the {@link #subject}.
+343                 */
+344                public Builder subject(final String subject) {
+345                        this.subject = subject;
+346                        return this;
+347                }
+348
+349                /**
+350                 * Sets the {@link #text}.
+351                 */
+352                public Builder text(final String text) {
+353                        this.text = text;
+354                        return this;
+355                }
+356
+357                /**
+358                 * Sets the {@link #textHTML}.
+359                 */
+360                public Builder textHTML(final String textHTML) {
+361                        this.textHTML = textHTML;
+362                        return this;
+363                }
+364
+365                /**
+366                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+367                 *
+368                 * @param name The name of the recipient.
+369                 * @param address The emailaddress of the recipient.
+370                 * @see #recipients
+371                 * @see Recipient
+372                 */
+373                public Builder to(final String name, final String address) {
+374                        recipients.add(new Recipient(name, address, RecipientType.TO));
+375                        return this;
+376                }
+377
+378                /**
+379                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+380                 *
+381                 * @param recipient The recipent whose name and address to use
+382                 * @see #recipients
+383                 * @see Recipient
+384                 */
+385                public Builder to(final Recipient recipient) {
+386                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.TO));
+387                        return this;
+388                }
+389
+390
+391
+392                /**
+393                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+394                 *
+395                 * @param name The name of the recipient.
+396                 * @param address The emailaddress of the recipient.
+397                 * @see #recipients
+398                 * @see Recipient
+399                 */
+400                public Builder cc(final String name, final String address) {
+401                        recipients.add(new Recipient(name, address, RecipientType.CC));
+402                        return this;
+403                }
+404
+405                /**
+406                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+407                 *
+408                 * @param recipient The recipent whose name and address to use
+409                 * @see #recipients
+410                 * @see Recipient
+411                 */
+412                public Builder cc(final Recipient recipient) {
+413                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.CC));
+414                        return this;
+415                }
+416
+417                /**
+418                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+419                 *
+420                 * @param name The name of the recipient.
+421                 * @param address The emailaddress of the recipient.
+422                 * @see #recipients
+423                 * @see Recipient
+424                 */
+425                public Builder bcc(final String name, final String address) {
+426                        recipients.add(new Recipient(name, address, RecipientType.BCC));
+427                        return this;
+428                }
+429
+430                /**
+431                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+432                 *
+433                 * @param recipient The recipent whose name and address to use
+434                 * @see #recipients
+435                 * @see Recipient
+436                 */
+437                public Builder bcc(final Recipient recipient) {
+438                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.BCC));
+439                        return this;
+440                }
+441
+442                /**
+443                 * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+444                 * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+445                 * {@link ByteArrayDataSource}.
+446                 *
+447                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+448                 * @param data The byte data of the image to be embedded.
+449                 * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+450                 * @see ByteArrayDataSource
+451                 * @see #addEmbeddedImage(String, DataSource)
+452                 */
+453                public Builder embedImage(final String name, final byte[] data, final String mimetype) {
+454                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+455                        dataSource.setName(name);
+456                        return embedImage(name, dataSource);
+457                }
+458
+459                /**
+460                 * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+461                 *
+462                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+463                 * @param imagedata The image data.
+464                 */
+465                public Builder embedImage(final String name, final DataSource imagedata) {
+466                        embeddedImages.add(new AttachmentResource(name, imagedata));
+467                        return this;
+468                }
+469
+470                /**
+471                 * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+472                 * <p>
+473                 * example: <code>email.addHeader("X-Priority", 2)</code>
+474                 *
+475                 * @param name The name of the header.
+476                 * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+477                 */
+478                public Builder addHeader(final String name, final Object value) {
+479                        headers.put(name, String.valueOf(value));
+480                        return this;
+481                }
+482
+483                /**
+484                 * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+485                 * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+486                 *
+487                 * @param name The name of the extension (eg. filename including extension).
+488                 * @param data The byte data of the attachment.
+489                 * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+490                 * @see ByteArrayDataSource
+491                 * @see #addAttachment(String, DataSource)
+492                 */
+493                public void addAttachment(final String name, final byte[] data, final String mimetype) {
+494                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+495                        dataSource.setName(name);
+496                        addAttachment(name, dataSource);
+497                }
+498
+499                /**
+500                 * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+501                 *
+502                 * @param name The name of the attachment (eg. 'filename.ext').
+503                 * @param filedata The attachment data.
+504                 */
+505                public void addAttachment(final String name, final DataSource filedata) {
+506                        attachments.add(new AttachmentResource(name, filedata));
+507                }
+508
+509        }
+510
+511        /**
+512         * Constructor for the Builder class
+513         * @param builder The builder from which to create the email.
+514         */
+515        private Email(Builder builder) {
+516                recipients = builder.recipients;
+517                embeddedImages = builder.embeddedImages;
+518                attachments = builder.attachments;
+519                headers = builder.headers;
+520
+521                fromRecipient = builder.fromRecipient;
+522                replyToRecipient = builder.replyToRecipient;
+523                text = builder.text;
+524                textHTML = builder.textHTML;
+525                subject = builder.subject;
+526        }
+527}
 
 
 
@@ -316,6 +593,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html index 5668d5e94..3f82dbd12 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html @@ -1,64 +1,75 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    /**
-004     * Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to
-005     * <code>true</code>.
-006     * 
-007     * @author Benny Bottema
-008     * @see #EmailAddressValidationCriteria(boolean, boolean)
-009     */
-010    public class EmailAddressValidationCriteria {
-011            private final boolean allowDomainLiterals;
-012            private final boolean allowQuotedIdentifiers;
-013    
-014            /**
-015             * @param allowDomainLiterals <ul>
-016             *            <li>This flag states whether domain literals are allowed in the email address, e.g.:
-017             *            <p>
-018             *            <tt>someone@[192.168.1.100]</tt> or <br/>
-019             *            <tt>john.doe@[23:33:A2:22:16:1F]</tt> or <br/>
-020             *            <tt>me@[my computer]</tt>
-021             *            </p>
-022             *            <p>
-023             *            The RFC says these are valid email addresses, but most people don't like allowing them. If you don't want to allow them,
-024             *            and only want to allow valid domain names (<a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>, x.y.z.com, etc),
-025             *            change this constant to <tt>false</tt>.
-026             *            <p>
-027             *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
-028             *            application.
-029             *            </li>
-030             *            </ul>
-031             * @param allowQuotedIdentifiers <ul>
-032             *            <li>This flag states whether quoted identifiers are allowed (using quotes and angle brackets around the raw address) are
-033             *            allowed, e.g.:
-034             *            <p>
-035             *            <tt>"John Smith" &lt;john.smith@somewhere.com&gt;</tt>
-036             *            <p>
-037             *            The RFC says this is a valid mailbox. If you don't want to allow this, because for example, you only want users to enter
-038             *            in a raw address (<tt>john.smith@somewhere.com</tt> - no quotes or angle brackets), then change this constant to
-039             *            <tt>false</tt>.
-040             *            <p>
-041             *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
-042             *            application.
-043             *            </li>
-044             *            </ul>
-045             */
-046            public EmailAddressValidationCriteria(boolean allowDomainLiterals, boolean allowQuotedIdentifiers) {
-047                    this.allowDomainLiterals = allowDomainLiterals;
-048                    this.allowQuotedIdentifiers = allowQuotedIdentifiers;
-049            }
-050    
-051            public final boolean isAllowDomainLiterals() {
-052                    return allowDomainLiterals;
-053            }
-054    
-055            public final boolean isAllowQuotedIdentifiers() {
-056                    return allowQuotedIdentifiers;
-057            }
-058    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003/**
+004 * Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to
+005 * <code>true</code>.
+006 * 
+007 * @author Benny Bottema
+008 * @see #EmailAddressValidationCriteria(boolean, boolean)
+009 */
+010public class EmailAddressValidationCriteria {
+011
+012        private final boolean allowDomainLiterals;
+013        private final boolean allowQuotedIdentifiers;
+014
+015        /**
+016         * Criteria which is most RFC 2822 compliant and allows all compiant address forms, including the more exotic ones.
+017         * 
+018         * @see #EmailAddressValidationCriteria(boolean, boolean)
+019         */
+020        public static final EmailAddressValidationCriteria RFC_COMPLIANT = new EmailAddressValidationCriteria(true, true);
+021
+022        /**
+023         * @param allowDomainLiterals <ul>
+024         *            <li>This flag states whether domain literals are allowed in the email address, e.g.:
+025         *            <p>
+026         *            <tt>someone@[192.168.1.100]</tt> or <br>
+027         *            <tt>john.doe@[23:33:A2:22:16:1F]</tt> or <br>
+028         *            <tt>me@[my computer]</tt>
+029         *            </p>
+030         *            <p>
+031         *            The RFC says these are valid email addresses, but most people don't like allowing them. If you don't want to allow them,
+032         *            and only want to allow valid domain names (<a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>, x.y.z.com, etc),
+033         *            change this constant to <tt>false</tt>.
+034         *            <p>
+035         *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
+036         *            application.</li>
+037         *            </ul>
+038         * @param allowQuotedIdentifiers <ul>
+039         *            <li>This flag states whether quoted identifiers are allowed (using quotes and angle brackets around the raw address) are
+040         *            allowed, e.g.:
+041         *            <p>
+042         *            <tt>"John Smith" &lt;john.smith@somewhere.com&gt;</tt>
+043         *            <p>
+044         *            The RFC says this is a valid mailbox. If you don't want to allow this, because for example, you only want users to enter
+045         *            in a raw address (<tt>john.smith@somewhere.com</tt> - no quotes or angle brackets), then change this constant to
+046         *            <tt>false</tt>.
+047         *            <p>
+048         *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
+049         *            application.</li>
+050         *            </ul>
+051         */
+052        public EmailAddressValidationCriteria(boolean allowDomainLiterals, boolean allowQuotedIdentifiers) {
+053                this.allowDomainLiterals = allowDomainLiterals;
+054                this.allowQuotedIdentifiers = allowQuotedIdentifiers;
+055        }
+056
+057        public final boolean isAllowDomainLiterals() {
+058                return allowDomainLiterals;
+059        }
+060
+061        public final boolean isAllowQuotedIdentifiers() {
+062                return allowQuotedIdentifiers;
+063        }
+064}
 
 
 
@@ -119,6 +130,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html index bb2347e46..3b01118fc 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html @@ -1,113 +1,118 @@ - - -
-001    /*
-002     * Copyright 2008 Les Hazlewood Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
-003     * file except in compliance with the License. You may obtain a copy of the License at
-004     * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
-005     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
-006     * either express or implied. See the License for the specific language governing permissions and limitations under the
-007     * License.
-008     */
-009    package org.codemonkey.simplejavamail;
-010    
-011    import java.util.regex.Pattern;
-012    
-013    /**
-014     * Validates an email address according to <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>, using regular expressions.
-015     * <p>
-016     * From the original author: <br />
-017     * <blockquote> If you use this code, please keep the author information in tact and reference my site at <a
-018     * href="http://www.leshazlewood.com">leshazlewood.com</a>. Thanks! </blockquote>
-019     * <p>
-020     * Code sanitized by Benny Bottema (kept validation 100% in tact).
-021     * 
-022     * @author Les Hazlewood, Benny Bottema
-023     * @see EmailAddressValidationCriteria
-024     */
-025    public final class EmailValidationUtil {
-026    
-027            /**
-028             * Private constructor; this is a utility class with static methods only, not designed for extension.
-029             */
-030            private EmailValidationUtil() {
-031                    //
-032            }
-033    
-034            /**
-035             * Validates an e-mail with default validation flags that remains <code>true</code> to RFC 2822. This means allowing both domain
-036             * literals and quoted identifiers.
-037             * 
-038             * @param email A complete email address.
-039             * @return Whether the e-mail address is compliant with RFC 2822.
-040             * @see EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)
-041             */
-042            public static boolean isValid(final String email) {
-043                    return isValid(email, new EmailAddressValidationCriteria(true, true));
-044            }
-045    
-046            /**
-047             * Validates an e-mail with given validation flags.
-048             * 
-049             * @param email A complete email address.
-050             * @param emailAddressValidationCriteria A set of flags that restrict or relax RFC 2822 compliance.
-051             * @return Whether the e-mail address is compliant with RFC 2822, configured using the passed in {@link EmailAddressValidationCriteria}.
-052             * @see EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)
-053             */
-054            public static boolean isValid(final String email, final EmailAddressValidationCriteria emailAddressValidationCriteria) {
-055                    return buildValidEmailPattern(emailAddressValidationCriteria).matcher(email).matches();
-056            }
-057    
-058            protected static Pattern buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) {
-059                    // RFC 2822 2.2.2 Structured Header Field Bodies
-060                    final String wsp = "[ \\t]"; // space or tab
-061                    final String fwsp = wsp + "*";
-062                    // RFC 2822 3.2.1 Primitive tokens
-063                    final String dquote = "\\\"";
-064                    // ASCII Control characters excluding white space:
-065                    final String noWsCtl = "\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F";
-066                    // all ASCII characters except CR and LF:
-067                    final String asciiText = "[\\x01-\\x09\\x0B\\x0C\\x0E-\\x7F]";
-068                    // RFC 2822 3.2.2 Quoted characters:
-069                    // single backslash followed by a text char
-070                    final String quotedPair = "(\\\\" + asciiText + ")";
-071                    // RFC 2822 3.2.4 Atom:
-072                    final String atext = "[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
-073                    final String atom = fwsp + atext + "+" + fwsp;
-074                    final String dotAtomText = atext + "+" + "(" + "\\." + atext + "+)*";
-075                    final String dotAtom = fwsp + "(" + dotAtomText + ")" + fwsp;
-076                    // RFC 2822 3.2.5 Quoted strings:
-077                    // noWsCtl and the rest of ASCII except the doublequote and backslash characters:
-078                    final String qtext = "[" + noWsCtl + "\\x21\\x23-\\x5B\\x5D-\\x7E]";
-079                    final String qcontent = "(" + qtext + "|" + quotedPair + ")";
-080                    final String quotedString = dquote + "(" + fwsp + qcontent + ")*" + fwsp + dquote;
-081                    // RFC 2822 3.2.6 Miscellaneous tokens
-082                    final String word = "((" + atom + ")|(" + quotedString + "))";
-083                    final String phrase = word + "+"; // one or more words.
-084                    // RFC 1035 tokens for domain names:
-085                    final String letter = "[a-zA-Z]";
-086                    final String letDig = "[a-zA-Z0-9]";
-087                    final String letDigHyp = "[a-zA-Z0-9-]";
-088                    final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + ")?";
-089                    final String rfc1035DomainName = rfcLabel + "(\\." + rfcLabel + ")*\\." + letter + "{2,6}";
-090                    // RFC 2822 3.4 Address specification
-091                    // domain text - non white space controls and the rest of ASCII chars not including [, ], or \:
-092                    final String dtext = "[" + noWsCtl + "\\x21-\\x5A\\x5E-\\x7E]";
-093                    final String dcontent = dtext + "|" + quotedPair;
-094                    final String domainLiteral = "\\[" + "(" + fwsp + dcontent + "+)*" + fwsp + "\\]";
-095                    final String rfc2822Domain = "(" + dotAtom + "|" + domainLiteral + ")";
-096                    final String domain = parameterObject.isAllowDomainLiterals() ? rfc2822Domain : rfc1035DomainName;
-097                    final String localPart = "((" + dotAtom + ")|(" + quotedString + "))";
-098                    final String addrSpec = localPart + "@" + domain;
-099                    final String angleAddr = "<" + addrSpec + ">";
-100                    final String nameAddr = "(" + phrase + ")?" + fwsp + angleAddr;
-101                    final String mailbox = nameAddr + "|" + addrSpec;
-102                    // now compile a pattern for efficient re-use:
-103                    // if we're allowing quoted identifiers or not:
-104                    final String patternString = parameterObject.isAllowQuotedIdentifiers() ? mailbox : addrSpec;
-105                    return Pattern.compile(patternString);
-106            }
-107    }
+
+
+
+Source code
+
+
+
+
+
001/*
+002 * Copyright 2008 Les Hazlewood Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
+003 * file except in compliance with the License. You may obtain a copy of the License at
+004 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
+005 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+006 * either express or implied. See the License for the specific language governing permissions and limitations under the
+007 * License.
+008 */
+009package org.codemonkey.simplejavamail;
+010
+011import java.util.regex.Pattern;
+012
+013/**
+014 * Validates an email address according to <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>, using regular expressions.
+015 * <p>
+016 * From the original author: <br>
+017 * <blockquote> If you use this code, please keep the author information in tact and reference my site at <a
+018 * href="http://www.leshazlewood.com">leshazlewood.com</a>. Thanks! </blockquote>
+019 * <p>
+020 * Code sanitized by Benny Bottema (kept validation 100% in tact).
+021 * 
+022 * @author Les Hazlewood, Benny Bottema
+023 * @see EmailAddressValidationCriteria
+024 */
+025public final class EmailValidationUtil {
+026
+027        /**
+028         * Private constructor; this is a utility class with static methods only, not designed for extension.
+029         */
+030        private EmailValidationUtil() {
+031                //
+032        }
+033
+034        /**
+035         * Validates an e-mail with default validation flags that remains <code>true</code> to RFC 2822. This means allowing both domain
+036         * literals and quoted identifiers.
+037         * 
+038         * @param email A complete email address.
+039         * @return Whether the e-mail address is compliant with RFC 2822.
+040         * @see EmailAddressValidationCriteria#RFC_COMPLIANT
+041         */
+042        public static boolean isValid(final String email) {
+043                return isValid(email, EmailAddressValidationCriteria.RFC_COMPLIANT);
+044        }
+045
+046        /**
+047         * Validates an e-mail with given validation flags.
+048         * 
+049         * @param email A complete email address.
+050         * @param emailAddressValidationCriteria A set of flags that restrict or relax RFC 2822 compliance.
+051         * @return Whether the e-mail address is compliant with RFC 2822, configured using the passed in {@link EmailAddressValidationCriteria}.
+052         * @see EmailAddressValidationCriteria#RFC_COMPLIANT
+053         */
+054        public static boolean isValid(final String email, final EmailAddressValidationCriteria emailAddressValidationCriteria) {
+055                return buildValidEmailPattern(emailAddressValidationCriteria).matcher(email).matches();
+056        }
+057
+058        protected static Pattern buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) {
+059                // RFC 2822 2.2.2 Structured Header Field Bodies
+060                final String wsp = "[ \\t]"; // space or tab
+061                final String fwsp = wsp + "*";
+062                // RFC 2822 3.2.1 Primitive tokens
+063                final String dquote = "\\\"";
+064                // ASCII Control characters excluding white space:
+065                final String noWsCtl = "\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F";
+066                // all ASCII characters except CR and LF:
+067                final String asciiText = "[\\x01-\\x09\\x0B\\x0C\\x0E-\\x7F]";
+068                // RFC 2822 3.2.2 Quoted characters:
+069                // single backslash followed by a text char
+070                final String quotedPair = "(\\\\" + asciiText + ")";
+071                // RFC 2822 3.2.4 Atom:
+072                final String atext = "[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
+073                final String atom = fwsp + atext + "+" + fwsp;
+074                final String dotAtomText = atext + "+" + "(" + "\\." + atext + "+)*";
+075                final String dotAtom = fwsp + "(" + dotAtomText + ")" + fwsp;
+076                // RFC 2822 3.2.5 Quoted strings:
+077                // noWsCtl and the rest of ASCII except the doublequote and backslash characters:
+078                final String qtext = "[" + noWsCtl + "\\x21\\x23-\\x5B\\x5D-\\x7E]";
+079                final String qcontent = "(" + qtext + "|" + quotedPair + ")";
+080                final String quotedString = dquote + "(" + fwsp + qcontent + ")*" + fwsp + dquote;
+081                // RFC 2822 3.2.6 Miscellaneous tokens
+082                final String word = "((" + atom + ")|(" + quotedString + "))";
+083                final String phrase = word + "+"; // one or more words.
+084                // RFC 1035 tokens for domain names:
+085                final String letter = "[a-zA-Z]";
+086                final String letDig = "[a-zA-Z0-9]";
+087                final String letDigHyp = "[a-zA-Z0-9-]";
+088                final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + ")?";
+089                final String rfc1035DomainName = rfcLabel + "(\\." + rfcLabel + ")*\\." + letter + "{2,6}";
+090                // RFC 2822 3.4 Address specification
+091                // domain text - non white space controls and the rest of ASCII chars not including [, ], or \:
+092                final String dtext = "[" + noWsCtl + "\\x21-\\x5A\\x5E-\\x7E]";
+093                final String dcontent = dtext + "|" + quotedPair;
+094                final String domainLiteral = "\\[" + "(" + fwsp + dcontent + "+)*" + fwsp + "\\]";
+095                final String rfc2822Domain = "(" + dotAtom + "|" + domainLiteral + ")";
+096                final String domain = parameterObject.isAllowDomainLiterals() ? rfc2822Domain : rfc1035DomainName;
+097                final String localPart = "((" + dotAtom + ")|(" + quotedString + "))";
+098                final String addrSpec = localPart + "@" + domain;
+099                final String angleAddr = "<" + addrSpec + ">";
+100                final String nameAddr = "(" + phrase + ")?" + fwsp + angleAddr;
+101                final String mailbox = nameAddr + "|" + addrSpec;
+102                // now compile a pattern for efficient re-use:
+103                // if we're allowing quoted identifiers or not:
+104                final String patternString = parameterObject.isAllowQuotedIdentifiers() ? mailbox : addrSpec;
+105                return Pattern.compile(patternString);
+106        }
+107}
 
 
 
@@ -168,6 +173,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/MailException.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/MailException.html index 8c88b4380..26a9c9ab4 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/MailException.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/MailException.html @@ -1,38 +1,43 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import javax.mail.MessagingException;
-004    
-005    /**
-006     * This exception is used to communicate errors during the sending of email.
-007     * 
-008     * @author Benny Bottema
-009     */
-010    @SuppressWarnings("serial")
-011    public final class MailException extends RuntimeException {
-012    
-013            protected static final String GENERIC_ERROR = "Generic error: %s";
-014            protected static final String MISSING_HOST = "Can't send an email without host";
-015            protected static final String MISSING_USERNAME = "Can't have a password without username";
-016            protected static final String INVALID_ENCODING = "Encoding not accepted: %s";
-017            protected static final String INVALID_RECIPIENT = "Invalid TO address: %s";
-018            protected static final String INVALID_REPLYTO = "Invalid REPLY TO address: %s";
-019            protected static final String INVALID_SENDER = "Invalid FROM address: %s";
-020            protected static final String MISSING_SENDER = "Email is not valid: missing sender";
-021            protected static final String MISSING_RECIPIENT = "Email is not valid: missing recipients";
-022            protected static final String MISSING_SUBJECT = "Email is not valid: missing subject";
-023            protected static final String MISSING_CONTENT = "Email is not valid: missing content body";
-024    
-025            protected MailException(final String message) {
-026                    super(message);
-027            }
-028    
-029            protected MailException(final String message, final MessagingException cause) {
-030                    super(message, cause);
-031            }
-032    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import javax.mail.MessagingException;
+004
+005/**
+006 * This exception is used to communicate errors during the sending of email.
+007 * 
+008 * @author Benny Bottema
+009 */
+010@SuppressWarnings("serial")
+011public final class MailException extends RuntimeException {
+012
+013        protected static final String GENERIC_ERROR = "Generic error: %s";
+014        protected static final String MISSING_HOST = "Can't send an email without host";
+015        protected static final String MISSING_USERNAME = "Can't have a password without username";
+016        protected static final String INVALID_ENCODING = "Encoding not accepted: %s";
+017        protected static final String INVALID_RECIPIENT = "Invalid TO address: %s";
+018        protected static final String INVALID_REPLYTO = "Invalid REPLY TO address: %s";
+019        protected static final String INVALID_SENDER = "Invalid FROM address: %s";
+020        protected static final String MISSING_SENDER = "Email is not valid: missing sender";
+021        protected static final String MISSING_RECIPIENT = "Email is not valid: missing recipients";
+022        protected static final String MISSING_SUBJECT = "Email is not valid: missing subject";
+023        protected static final String MISSING_CONTENT = "Email is not valid: missing content body";
+024
+025        protected MailException(final String message) {
+026                super(message);
+027        }
+028
+029        protected MailException(final String message, final MessagingException cause) {
+030                super(message, cause);
+031        }
+032}
 
 
 
@@ -93,6 +98,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html index d0e5df973..11c78bc17 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.MimeEmailMessageWrapper.html @@ -1,526 +1,558 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.io.UnsupportedEncodingException;
-004    import java.util.Date;
-005    import java.util.Map;
-006    import java.util.Properties;
-007    
-008    import javax.activation.DataHandler;
-009    import javax.activation.DataSource;
-010    import javax.mail.Address;
-011    import javax.mail.Authenticator;
-012    import javax.mail.BodyPart;
-013    import javax.mail.Message;
-014    import javax.mail.MessagingException;
-015    import javax.mail.Part;
-016    import javax.mail.PasswordAuthentication;
-017    import javax.mail.Session;
-018    import javax.mail.Transport;
-019    import javax.mail.internet.InternetAddress;
-020    import javax.mail.internet.MimeBodyPart;
-021    import javax.mail.internet.MimeMessage;
-022    import javax.mail.internet.MimeMultipart;
-023    import javax.mail.internet.MimeUtility;
-024    
-025    import org.apache.log4j.Logger;
-026    
-027    /**
-028     * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
-029     * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br />
-030     * <br />
-031     * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
-032     * instances. <br />
-033     * <br />
-034     * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
-035     * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br />
-036     * <br />
-037     * Technically, the resulting email structure is as follows:<br />
-038     * 
-039     * <pre>
-040     * - root
-041     *      - related
-042     *              - alternative
-043     *                      - mail text
-044     *                      - mail html text
-045     *              - embedded images
-046     *      - attachments
-047     * </pre>
-048     * 
-049     * <br />
-050     * Usage example:<br />
-051     * 
-052     * <pre>
-053     * Email email = new Email();
-054     * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
-055     * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
-056     * email.setText(&quot;We should meet up!!&quot;);
-057     * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
-058     * email.setSubject(&quot;Hey&quot;);
-059     * new Mailer(preconfiguredMailSession).sendMail(email);
-060     * // or:
-061     * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
-062     * </pre>
-063     * 
-064     * @author Benny Bottema
-065     * @see MimeEmailMessageWrapper
-066     * @see Email
-067     */
-068    public class Mailer {
-069    
-070            private static final Logger logger = Logger.getLogger(Mailer.class);
-071            
-072            /**
-073             * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
-074             */
-075            private static final String CHARACTER_ENCODING = "UTF-8";
-076    
-077            /**
-078             * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
-079             * directly, when no <code>Session</code> instance was provided.
-080             * 
-081             * @see #Mailer(Session)
-082             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-083             */
-084            private final Session session;
-085    
-086            /**
-087             * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
-088             * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
-089             */
-090            private TransportStrategy transportStrategy;
-091    
-092            /**
-093             * Email address restriction flags set either by constructor or overridden by getter by user.
-094             * 
-095             * @see EmailAddressValidationCriteria
-096             */
-097            private EmailAddressValidationCriteria emailAddressValidationCriteria;
-098    
-099            /**
-100             * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
-101             * configured (host, port, authentication and transport protocol settings).
-102             * <p>
-103             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-104             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-105             * 
-106             * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
-107             */
-108            public Mailer(final Session session) {
-109                    this.session = session;
-110                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-111            }
-112    
-113            /**
-114             * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
-115             * web container, or Spring context etc.
-116             * <p>
-117             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-118             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-119             * 
-120             * @param host The address URL of the SMTP server to be used.
-121             * @param port The port of the SMTP server.
-122             * @param username An optional username, may be <code>null</code>.
-123             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-124             * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
-125             */
-126            public Mailer(final String host, final Integer port, final String username, final String password,
-127                            final TransportStrategy transportStrategy) {
-128                    // we're doing these validations manually instead of using Apache Commons to avoid another dependency
-129                    if (host == null || host.trim().equals("")) {
-130                            throw new MailException(MailException.MISSING_HOST);
-131                    } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
-132                            throw new MailException(MailException.MISSING_USERNAME);
-133                    }
-134                    this.transportStrategy = transportStrategy;
-135                    this.session = createMailSession(host, port, username, password);
-136                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-137            }
-138    
-139            /**
-140             * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
-141             * {@link #transportStrategy} in two ways:
-142             * <ol>
-143             * <li>request an initial property list which the strategy may pre-populate</li>
-144             * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
-145             * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
-146             * </ol>
-147             * 
-148             * @param host The address URL of the SMTP server to be used.
-149             * @param port The port of the SMTP server.
-150             * @param username An optional username, may be <code>null</code>.
-151             * @param password An optional password, may be <code>null</code>.
-152             * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
-153             * @see TransportStrategy#generateProperties()
-154             * @see TransportStrategy#propertyNameHost()
-155             * @see TransportStrategy#propertyNamePort()
-156             * @see TransportStrategy#propertyNameUsername()
-157             * @see TransportStrategy#propertyNameAuthenticate()
-158             */
-159            public Session createMailSession(final String host, final Integer port, final String username, final String password) {
-160                    if (transportStrategy == null) {
-161                            logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
-162                            transportStrategy = TransportStrategy.SMTP_PLAIN;
-163                    }
-164                    Properties props = transportStrategy.generateProperties();
-165                    props.put(transportStrategy.propertyNameHost(), host);
-166                    if (port != null) {
-167                            props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
-168                    } else {
-169                            // let JavaMail's Transport objects determine deault port base don the used protocol
-170                    }
-171    
-172                    if (username != null) {
-173                            props.put(transportStrategy.propertyNameUsername(), username);
-174                    }
-175    
-176                    if (password != null) {
-177                            props.put(transportStrategy.propertyNameAuthenticate(), "true");
-178                            return Session.getInstance(props, new Authenticator() {
-179                                    @Override
-180                                    protected PasswordAuthentication getPasswordAuthentication() {
-181                                            return new PasswordAuthentication(username, password);
-182                                    }
-183                            });
-184                    } else {
-185                            return Session.getInstance(props);
-186                    }
-187            }
-188    
-189            /**
-190             * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
-191             * 
-192             * @param host The address URL of the SMTP server to be used.
-193             * @param port The port of the SMTP server.
-194             * @param username An optional username, may be <code>null</code>.
-195             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-196             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-197             */
-198            public Mailer(final String host, final Integer port, final String username, final String password) {
-199                    this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
-200            }
-201    
-202            /**
-203             * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
-204             * 
-205             * @param debug Flag to indicate debug mode yes/no.
-206             */
-207            public void setDebug(boolean debug) {
-208                    session.setDebug(debug);
-209            }
-210    
-211            /**
-212             * Processes an {@link Email} instance into a completely configured {@link Message}.
-213             * <p>
-214             * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
-215             * all connection details have been configured in the provided {@link Session} instance.
-216             * <p>
-217             * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
-218             * providing a message id.
-219             * 
-220             * @param email The information for the email to be sent.
-221             * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
-222             *             etc.
-223             * @see #validate(Email)
-224             * @see #prepareMessage(Email, MimeEmailMessageWrapper)
-225             * @see #setRecipients(Email, Message)
-226             * @see #setTexts(Email, MimeMultipart)
-227             * @see #setEmbeddedImages(Email, MimeMultipart)
-228             * @see #setAttachments(Email, MimeMultipart)
-229             */
-230            public final void sendMail(final Email email)
-231                            throws MailException {
-232                    if (validate(email)) {
-233                            try {
-234                                    // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
-235                                    final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
-236                                    // fill and send wrapped mime message parts
-237                                    final Message message = prepareMessage(email, messageRoot);
-238                                    logSession(session, transportStrategy);
-239                                    message.saveChanges(); // some headers and id's will be set for this specific message
-240                                    Transport transport = session.getTransport();
-241                                    transport.connect();
-242                                    transport.sendMessage(message, message.getAllRecipients());
-243                                    transport.close();
-244                            } catch (final UnsupportedEncodingException e) {
-245                                    logger.error(e.getMessage(), e);
-246                                    throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
-247                            } catch (final MessagingException e) {
-248                                    logger.error(e.getMessage(), e);
-249                                    throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
-250                            }
-251                    }
-252            }
-253    
-254            /**
-255             * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
-256             */
-257            private void logSession(Session session, TransportStrategy transportStrategy) {
-258                    final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
-259                    Properties properties = session.getProperties();
-260                    logger.debug(String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
-261                                    properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
-262                                    properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy));
-263            }
-264    
-265            /**
-266             * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
-267             * 
-268             * @param email The email that needs to be configured correctly.
-269             * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
-270             * @throws MailException Is being thrown in any of the above causes.
-271             * @see EmailValidationUtil
-272             */
-273            public boolean validate(final Email email)
-274                            throws MailException {
-275                    if (email.getText() == null && email.getTextHTML() == null) {
-276                            throw new MailException(MailException.MISSING_CONTENT);
-277                    } else if (email.getSubject() == null || email.getSubject().equals("")) {
-278                            throw new MailException(MailException.MISSING_SUBJECT);
-279                    } else if (email.getRecipients().size() == 0) {
-280                            throw new MailException(MailException.MISSING_RECIPIENT);
-281                    } else if (email.getFromRecipient() == null) {
-282                            throw new MailException(MailException.MISSING_SENDER);
-283                    } else {
-284                            if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
-285                                    throw new MailException(String.format(MailException.INVALID_SENDER, email));
-286                            }
-287                            for (final Recipient recipient : email.getRecipients()) {
-288                                    if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
-289                                            throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
-290                                    }
-291                            }
-292                            if (email.getReplyToRecipient() != null) {
-293                                    if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
-294                                            throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
-295                                    }
-296                            }
-297                    }
-298                    return true;
-299            }
-300    
-301            /**
-302             * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
-303             * <p>
-304             * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
-305             * 
-306             * @param email The email message from which the subject and From-address are extracted.
-307             * @param messageRoot The root of the email which holds everything (filled with some email data).
-308             * @return A fully preparated {@link Message} instance, ready to be sent.
-309             * @throws MessagingException Kan gegooid worden als het message niet goed behandelt wordt.
-310             * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
-311             */
-312            private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
-313                            throws MessagingException, UnsupportedEncodingException {
-314                    final MimeMessage message = new MimeMessage(session);
-315                    // set basic email properties
-316                    message.setSubject(email.getSubject(), CHARACTER_ENCODING);
-317                    message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
-318                    setReplyTo(email, message);
-319                    setRecipients(email, message);
-320                    // fill multipart structure
-321                    setTexts(email, messageRoot.multipartAlternativeMessages);
-322                    setEmbeddedImages(email, messageRoot.multipartRelated);
-323                    setAttachments(email, messageRoot.multipartRoot);
-324                    message.setContent(messageRoot.multipartRoot);
-325                    setHeaders(email, message);
-326                    message.setSentDate(new Date());
-327                    return message;
-328            }
-329    
-330            /**
-331             * Fills the {@link Message} instance with recipients from the {@link Email}.
-332             * 
-333             * @param email The message in which the recipients are defined.
-334             * @param message The javax message that needs to be filled with recipients.
-335             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-336             * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
-337             */
-338            private void setRecipients(final Email email, final Message message)
-339                            throws UnsupportedEncodingException, MessagingException {
-340                    for (final Recipient recipient : email.getRecipients()) {
-341                            final Address address = new InternetAddress(recipient.getAddress(), recipient.getName());
-342                            message.addRecipient(recipient.getType(), address);
-343                    }
-344            }
-345    
-346            /**
-347             * Fills the {@link Message} instance with reply-to address.
-348             * 
-349             * @param email The message in which the recipients are defined.
-350             * @param message The javax message that needs to be filled with reply-to address.
-351             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-352             * @throws MessagingException See {@link Message#setReplyTo(Address[])}
-353             */
-354            private void setReplyTo(final Email email, final Message message)
-355                            throws UnsupportedEncodingException, MessagingException {
-356                    final Recipient replyToRecipient = email.getReplyToRecipient();
-357                    if (replyToRecipient != null) {
-358                            InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(), CHARACTER_ENCODING);
-359                            message.setReplyTo(new Address[] { replyToAddress });
-360                    }
-361            }
-362    
-363            /**
-364             * Fills the {@link Message} instance with the content bodies (text and html).
-365             * 
-366             * @param email The message in which the content is defined.
-367             * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
-368             * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
-369             *             {@link MimeMultipart#addBodyPart(BodyPart)}.
-370             */
-371            private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
-372                            throws MessagingException {
-373                    if (email.getText() != null) {
-374                            final MimeBodyPart messagePart = new MimeBodyPart();
-375                            messagePart.setText(email.getText(), CHARACTER_ENCODING);
-376                            multipartAlternativeMessages.addBodyPart(messagePart);
-377                    }
-378                    if (email.getTextHTML() != null) {
-379                            final MimeBodyPart messagePartHTML = new MimeBodyPart();
-380                            messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
-381                            multipartAlternativeMessages.addBodyPart(messagePartHTML);
-382                    }
-383            }
-384    
-385            /**
-386             * Fills the {@link Message} instance with the embedded images from the {@link Email}.
-387             * 
-388             * @param email The message in which the embedded images are defined.
-389             * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
-390             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-391             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-392             */
-393            private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
-394                            throws MessagingException {
-395                    for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
-396                            multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
-397                    }
-398            }
-399    
-400            /**
-401             * Fills the {@link Message} instance with the attachments from the {@link Email}.
-402             * 
-403             * @param email The message in which the attachments are defined.
-404             * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
-405             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-406             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-407             */
-408            private void setAttachments(final Email email, final MimeMultipart multipartRoot)
-409                            throws MessagingException {
-410                    for (final AttachmentResource resource : email.getAttachments()) {
-411                            multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
-412                    }
-413            }
-414    
-415            /**
-416             * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
-417             * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
-418             * 
-419             * @param email The message in which the headers are defined.
-420             * @param message The {@link Message} on which to set the raw, encoded and folded headers.
-421             * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
-422             * @throws MessagingException See {@link Message#addHeader(String, String)}
-423             * @see {@link MimeUtility#encodeText(String, String, String)}
-424             * @see MimeUtility#fold(int, String)
-425             */
-426            private void setHeaders(final Email email, final Message message)
-427                            throws UnsupportedEncodingException, MessagingException {
-428                    // add headers (for raw message headers we need to 'fold' them using MimeUtility
-429                    for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
-430                            String headerName = header.getKey();
-431                            String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
-432                            String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
-433                            message.addHeader(header.getKey(), foldedHeaderValue);
-434                    }
-435            }
-436    
-437            /**
-438             * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
-439             * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
-440             * email structure. <br />
-441             * <br />
-442             * For every attachment and embedded image a header needs to be set.
-443             * 
-444             * @param resource An object that describes the attachment and contains the actual content data.
-445             * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
-446             * @return An object with the attachment data read for placement in the email structure.
-447             * @throws MessagingException All BodyPart setters.
-448             */
-449            private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
-450                            throws MessagingException {
-451                    final BodyPart attachmentPart = new MimeBodyPart();
-452                    final DataSource ds = resource.getDataSource();
-453                    // setting headers isn't working nicely using the javax mail API, so let's do that manually
-454                    attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
-455                    attachmentPart.setFileName(resource.getName());
-456                    attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
-457                    attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
-458                    attachmentPart.setDisposition(dispositionType + "; size=0");
-459                    return attachmentPart;
-460            }
-461    
-462            /**
-463             * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
-464             * ultimately sent using JavaMail.<br />
-465             * <br />
-466             * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
-467             * 
-468             * <pre>
-469             * - root
-470             *      - related
-471             *              - alternative
-472             *                      - mail tekst
-473             *                      - mail html tekst
-474             *              - embedded images
-475             *      - attachments
-476             * </pre>
-477             * 
-478             * @author Benny Bottema
-479             */
-480            private class MimeEmailMessageWrapper {
-481    
-482                    private final MimeMultipart multipartRoot;
-483    
-484                    private final MimeMultipart multipartRelated;
-485    
-486                    private final MimeMultipart multipartAlternativeMessages;
-487    
-488                    /**
-489                     * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
-490                     */
-491                    MimeEmailMessageWrapper() {
-492                            multipartRoot = new MimeMultipart("mixed");
-493                            final MimeBodyPart contentRelated = new MimeBodyPart();
-494                            multipartRelated = new MimeMultipart("related");
-495                            final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
-496                            multipartAlternativeMessages = new MimeMultipart("alternative");
-497                            try {
-498                                    // construct mail structure
-499                                    multipartRoot.addBodyPart(contentRelated);
-500                                    contentRelated.setContent(multipartRelated);
-501                                    multipartRelated.addBodyPart(contentAlternativeMessages);
-502                                    contentAlternativeMessages.setContent(multipartAlternativeMessages);
-503                            } catch (final MessagingException e) {
-504                                    logger.error(e.getMessage(), e);
-505                                    throw new RuntimeException(e.getMessage(), e);
-506                            }
-507                    }
-508            }
-509    
-510            /**
-511             * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
-512             * instance.
-513             * 
-514             * @param emailAddressValidationCriteria Refer to
-515             *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
-516             */
-517            public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
-518                    this.emailAddressValidationCriteria = emailAddressValidationCriteria;
-519            }
-520    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.io.UnsupportedEncodingException;
+004import java.util.Date;
+005import java.util.Map;
+006import java.util.Properties;
+007
+008import javax.activation.DataHandler;
+009import javax.activation.DataSource;
+010import javax.mail.Address;
+011import javax.mail.Authenticator;
+012import javax.mail.BodyPart;
+013import javax.mail.Message;
+014import javax.mail.MessagingException;
+015import javax.mail.Part;
+016import javax.mail.PasswordAuthentication;
+017import javax.mail.Session;
+018import javax.mail.Transport;
+019import javax.mail.internet.InternetAddress;
+020import javax.mail.internet.MimeBodyPart;
+021import javax.mail.internet.MimeMessage;
+022import javax.mail.internet.MimeMultipart;
+023import javax.mail.internet.MimeUtility;
+024
+025import org.slf4j.Logger;
+026import org.slf4j.LoggerFactory;
+027
+028/**
+029 * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
+030 * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br>
+031 * <br>
+032 * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
+033 * instances. <br>
+034 * <br>
+035 * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
+036 * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br>
+037 * <br>
+038 * Technically, the resulting email structure is as follows:<br>
+039 * 
+040 * <pre>
+041 * - root
+042 *      - related
+043 *              - alternative
+044 *                      - mail text
+045 *                      - mail html text
+046 *              - embedded images
+047 *      - attachments
+048 * </pre>
+049 * 
+050 * <br>
+051 * Usage example:<br>
+052 * 
+053 * <pre>
+054 * Email email = new Email();
+055 * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
+056 * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
+057 * email.setText(&quot;We should meet up!!&quot;);
+058 * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
+059 * email.setSubject(&quot;Hey&quot;);
+060 * new Mailer(preconfiguredMailSession).sendMail(email);
+061 * // or:
+062 * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
+063 * </pre>
+064 * 
+065 * @author Benny Bottema
+066 * @see MimeEmailMessageWrapper
+067 * @see Email
+068 */
+069public class Mailer {
+070
+071        private static final Logger logger = LoggerFactory.getLogger(Mailer.class);
+072
+073        /**
+074         * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
+075         */
+076        private static final String CHARACTER_ENCODING = "UTF-8";
+077
+078        /**
+079         * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
+080         * directly, when no <code>Session</code> instance was provided.
+081         * 
+082         * @see #Mailer(Session)
+083         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+084         */
+085        private final Session session;
+086
+087        /**
+088         * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
+089         * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
+090         */
+091        private TransportStrategy transportStrategy;
+092
+093        /**
+094         * Email address restriction flags set either by constructor or overridden by getter by user.
+095         * 
+096         * @see EmailAddressValidationCriteria
+097         */
+098        private EmailAddressValidationCriteria emailAddressValidationCriteria;
+099
+100        /**
+101         * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
+102         * configured (host, port, authentication and transport protocol settings).
+103         * <p>
+104         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+105         * smtp server instead.
+106         * 
+107         * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
+108         */
+109        public Mailer(final Session session) {
+110                this.session = session;
+111                this.emailAddressValidationCriteria = null;
+112        }
+113
+114        /**
+115         * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
+116         * web container, or Spring context etc.
+117         * <p>
+118         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+119         * smtp server instead.
+120         * 
+121         * @param host The address URL of the SMTP server to be used.
+122         * @param port The port of the SMTP server.
+123         * @param username An optional username, may be <code>null</code>.
+124         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+125         * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
+126         */
+127        public Mailer(final String host, final Integer port, final String username, final String password,
+128                        final TransportStrategy transportStrategy) {
+129                // we're doing these validations manually instead of using Apache Commons to avoid another dependency
+130                if (host == null || host.trim().equals("")) {
+131                        throw new MailException(MailException.MISSING_HOST);
+132                } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
+133                        throw new MailException(MailException.MISSING_USERNAME);
+134                }
+135                this.transportStrategy = transportStrategy;
+136                this.session = createMailSession(host, port, username, password);
+137                this.emailAddressValidationCriteria = null;
+138        }
+139
+140        /**
+141         * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
+142         * {@link #transportStrategy} in two ways:
+143         * <ol>
+144         * <li>request an initial property list which the strategy may pre-populate</li>
+145         * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
+146         * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
+147         * </ol>
+148         * 
+149         * @param host The address URL of the SMTP server to be used.
+150         * @param port The port of the SMTP server.
+151         * @param username An optional username, may be <code>null</code>.
+152         * @param password An optional password, may be <code>null</code>.
+153         * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
+154         * @see TransportStrategy#generateProperties()
+155         * @see TransportStrategy#propertyNameHost()
+156         * @see TransportStrategy#propertyNamePort()
+157         * @see TransportStrategy#propertyNameUsername()
+158         * @see TransportStrategy#propertyNameAuthenticate()
+159         */
+160        protected Session createMailSession(final String host, final Integer port, final String username, final String password) {
+161                if (transportStrategy == null) {
+162                        logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
+163                        transportStrategy = TransportStrategy.SMTP_PLAIN;
+164                }
+165                Properties props = transportStrategy.generateProperties();
+166                props.put(transportStrategy.propertyNameHost(), host);
+167                if (port != null) {
+168                        props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
+169                } else {
+170                        // let JavaMail's Transport objects determine deault port base don the used protocol
+171                }
+172
+173                if (username != null) {
+174                        props.put(transportStrategy.propertyNameUsername(), username);
+175                }
+176
+177                if (password != null) {
+178                        props.put(transportStrategy.propertyNameAuthenticate(), "true");
+179                        return Session.getInstance(props, new Authenticator() {
+180                                @Override
+181                                protected PasswordAuthentication getPasswordAuthentication() {
+182                                        return new PasswordAuthentication(username, password);
+183                                }
+184                        });
+185                } else {
+186                        return Session.getInstance(props);
+187                }
+188        }
+189
+190        /**
+191         * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
+192         * 
+193         * @param host The address URL of the SMTP server to be used.
+194         * @param port The port of the SMTP server.
+195         * @param username An optional username, may be <code>null</code>.
+196         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+197         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+198         */
+199        public Mailer(final String host, final Integer port, final String username, final String password) {
+200                this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
+201        }
+202
+203        /**
+204         * In case Simple Java Mail falls short somehow, you can get a hold of the internal {@link Session} instance to debug or tweak. Please
+205         * let us know why you are needing this on https://github.com/bbottema/simple-java-mail/issues.
+206         */
+207        public Session getSession() {
+208                logger.warn("Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it.");
+209                logger.warn("\t>https://github.com/bbottema/simple-java-mail/issues");
+210                return session;
+211        }
+212
+213        /**
+214         * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
+215         * 
+216         * @param debug Flag to indicate debug mode yes/no.
+217         */
+218        public void setDebug(final boolean debug) {
+219                session.setDebug(debug);
+220        }
+221
+222        /**
+223         * Copies all property entries into the {@link Session} using {@link Session#getProperties()}.
+224         * 
+225         * @param properties The source properties to add or override in the internal {@link Session} instance.
+226         */
+227        public void applyProperties(final Properties properties) {
+228                session.getProperties().putAll(properties);
+229        }
+230
+231        /**
+232         * Processes an {@link Email} instance into a completely configured {@link Message}.
+233         * <p>
+234         * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
+235         * all connection details have been configured in the provided {@link Session} instance.
+236         * <p>
+237         * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
+238         * providing a message id.
+239         * 
+240         * @param email The information for the email to be sent.
+241         * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
+242         *             etc.
+243         * @see #validate(Email)
+244         * @see #prepareMessage(Email, MimeEmailMessageWrapper)
+245         * @see #setRecipients(Email, Message)
+246         * @see #setTexts(Email, MimeMultipart)
+247         * @see #setEmbeddedImages(Email, MimeMultipart)
+248         * @see #setAttachments(Email, MimeMultipart)
+249         */
+250        public final void sendMail(final Email email)
+251                        throws MailException {
+252                if (validate(email)) {
+253                        try {
+254                                // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
+255                                final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
+256                                // fill and send wrapped mime message parts
+257                                final Message message = prepareMessage(email, messageRoot);
+258                                logSession(session, transportStrategy);
+259                                message.saveChanges(); // some headers and id's will be set for this specific message
+260                                Transport transport = session.getTransport();
+261                                transport.connect();
+262                                transport.sendMessage(message, message.getAllRecipients());
+263                                transport.close();
+264                        } catch (final UnsupportedEncodingException e) {
+265                                logger.error(e.getMessage(), e);
+266                                throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
+267                        } catch (final MessagingException e) {
+268                                logger.error(e.getMessage(), e);
+269                                throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
+270                        }
+271                }
+272        }
+273
+274        /**
+275         * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
+276         */
+277        private void logSession(Session session, TransportStrategy transportStrategy) {
+278                Properties properties = session.getProperties();
+279                final String specifics;
+280                if (transportStrategy != null) {
+281                        final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
+282                        specifics = String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
+283                                        properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
+284                                        properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy);
+285                } else {
+286                        specifics = properties.toString();
+287                }
+288                logger.debug(String.format("starting mail session (%s)", specifics));
+289        }
+290
+291        /**
+292         * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
+293         * 
+294         * @param email The email that needs to be configured correctly.
+295         * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
+296         * @throws MailException Is being thrown in any of the above causes.
+297         * @see EmailValidationUtil
+298         */
+299        public boolean validate(final Email email)
+300                        throws MailException {
+301                if (email.getText() == null && email.getTextHTML() == null) {
+302                        throw new MailException(MailException.MISSING_CONTENT);
+303                } else if (email.getSubject() == null || email.getSubject().equals("")) {
+304                        throw new MailException(MailException.MISSING_SUBJECT);
+305                } else if (email.getRecipients().size() == 0) {
+306                        throw new MailException(MailException.MISSING_RECIPIENT);
+307                } else if (email.getFromRecipient() == null) {
+308                        throw new MailException(MailException.MISSING_SENDER);
+309                } else if (emailAddressValidationCriteria != null) {
+310                        if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
+311                                throw new MailException(String.format(MailException.INVALID_SENDER, email));
+312                        }
+313                        for (final Recipient recipient : email.getRecipients()) {
+314                                if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
+315                                        throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
+316                                }
+317                        }
+318                        if (email.getReplyToRecipient() != null) {
+319                                if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
+320                                        throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
+321                                }
+322                        }
+323                }
+324                return true;
+325        }
+326
+327        /**
+328         * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
+329         * <p>
+330         * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
+331         * 
+332         * @param email The email message from which the subject and From-address are extracted.
+333         * @param messageRoot The root of the email which holds everything (filled with some email data).
+334         * @return A fully preparated {@link Message} instance, ready to be sent.
+335         * @throws MessagingException May be thrown when the message couldn't be processed by JavaMail.
+336         * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
+337         */
+338        private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
+339                        throws MessagingException, UnsupportedEncodingException {
+340                final MimeMessage message = new MimeMessage(session);
+341                // set basic email properties
+342                message.setSubject(email.getSubject(), CHARACTER_ENCODING);
+343                message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
+344                setReplyTo(email, message);
+345                setRecipients(email, message);
+346                // fill multipart structure
+347                setTexts(email, messageRoot.multipartAlternativeMessages);
+348                setEmbeddedImages(email, messageRoot.multipartRelated);
+349                setAttachments(email, messageRoot.multipartRoot);
+350                message.setContent(messageRoot.multipartRoot);
+351                setHeaders(email, message);
+352                message.setSentDate(new Date());
+353                return message;
+354        }
+355
+356        /**
+357         * Fills the {@link Message} instance with recipients from the {@link Email}.
+358         * 
+359         * @param email The message in which the recipients are defined.
+360         * @param message The javax message that needs to be filled with recipients.
+361         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+362         * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
+363         */
+364        private void setRecipients(final Email email, final Message message)
+365                        throws UnsupportedEncodingException, MessagingException {
+366                for (final Recipient recipient : email.getRecipients()) {
+367                        final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
+368                        message.addRecipient(recipient.getType(), address);
+369                }
+370        }
+371
+372        /**
+373         * Fills the {@link Message} instance with reply-to address.
+374         * 
+375         * @param email The message in which the recipients are defined.
+376         * @param message The javax message that needs to be filled with reply-to address.
+377         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+378         * @throws MessagingException See {@link Message#setReplyTo(Address[])}
+379         */
+380        private void setReplyTo(final Email email, final Message message)
+381                        throws UnsupportedEncodingException, MessagingException {
+382                final Recipient replyToRecipient = email.getReplyToRecipient();
+383                if (replyToRecipient != null) {
+384                        InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(),
+385                                        CHARACTER_ENCODING);
+386                        message.setReplyTo(new Address[] { replyToAddress });
+387                }
+388        }
+389
+390        /**
+391         * Fills the {@link Message} instance with the content bodies (text and html).
+392         * 
+393         * @param email The message in which the content is defined.
+394         * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
+395         * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
+396         *             {@link MimeMultipart#addBodyPart(BodyPart)}.
+397         */
+398        private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
+399                        throws MessagingException {
+400                if (email.getText() != null) {
+401                        final MimeBodyPart messagePart = new MimeBodyPart();
+402                        messagePart.setText(email.getText(), CHARACTER_ENCODING);
+403                        multipartAlternativeMessages.addBodyPart(messagePart);
+404                }
+405                if (email.getTextHTML() != null) {
+406                        final MimeBodyPart messagePartHTML = new MimeBodyPart();
+407                        messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
+408                        multipartAlternativeMessages.addBodyPart(messagePartHTML);
+409                }
+410        }
+411
+412        /**
+413         * Fills the {@link Message} instance with the embedded images from the {@link Email}.
+414         * 
+415         * @param email The message in which the embedded images are defined.
+416         * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
+417         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+418         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+419         */
+420        private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
+421                        throws MessagingException {
+422                for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
+423                        multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
+424                }
+425        }
+426
+427        /**
+428         * Fills the {@link Message} instance with the attachments from the {@link Email}.
+429         * 
+430         * @param email The message in which the attachments are defined.
+431         * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
+432         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+433         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+434         */
+435        private void setAttachments(final Email email, final MimeMultipart multipartRoot)
+436                        throws MessagingException {
+437                for (final AttachmentResource resource : email.getAttachments()) {
+438                        multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
+439                }
+440        }
+441
+442        /**
+443         * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
+444         * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
+445         * 
+446         * @param email The message in which the headers are defined.
+447         * @param message The {@link Message} on which to set the raw, encoded and folded headers.
+448         * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
+449         * @throws MessagingException See {@link Message#addHeader(String, String)}
+450         * @see {@link MimeUtility#encodeText(String, String, String)}
+451         * @see MimeUtility#fold(int, String)
+452         */
+453        private void setHeaders(final Email email, final Message message)
+454                        throws UnsupportedEncodingException, MessagingException {
+455                // add headers (for raw message headers we need to 'fold' them using MimeUtility
+456                for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
+457                        String headerName = header.getKey();
+458                        String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
+459                        String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
+460                        message.addHeader(header.getKey(), foldedHeaderValue);
+461                }
+462        }
+463
+464        /**
+465         * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
+466         * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
+467         * email structure. <br>
+468         * <br>
+469         * For every attachment and embedded image a header needs to be set.
+470         * 
+471         * @param resource An object that describes the attachment and contains the actual content data.
+472         * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
+473         * @return An object with the attachment data read for placement in the email structure.
+474         * @throws MessagingException All BodyPart setters.
+475         */
+476        private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
+477                        throws MessagingException {
+478                final BodyPart attachmentPart = new MimeBodyPart();
+479                final DataSource ds = resource.getDataSource();
+480                // setting headers isn't working nicely using the javax mail API, so let's do that manually
+481                attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
+482                attachmentPart.setFileName(resource.getName());
+483                attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
+484                attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
+485                attachmentPart.setDisposition(dispositionType + "; size=0");
+486                return attachmentPart;
+487        }
+488
+489        /**
+490         * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
+491         * ultimately sent using JavaMail.<br>
+492         * <br>
+493         * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
+494         * 
+495         * <pre>
+496         * - root
+497         *      - related
+498         *              - alternative
+499         *                      - mail tekst
+500         *                      - mail html tekst
+501         *              - embedded images
+502         *      - attachments
+503         * </pre>
+504         * 
+505         * @author Benny Bottema
+506         */
+507        private class MimeEmailMessageWrapper {
+508
+509                private final MimeMultipart multipartRoot;
+510
+511                private final MimeMultipart multipartRelated;
+512
+513                private final MimeMultipart multipartAlternativeMessages;
+514
+515                /**
+516                 * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
+517                 */
+518                MimeEmailMessageWrapper() {
+519                        multipartRoot = new MimeMultipart("mixed");
+520                        final MimeBodyPart contentRelated = new MimeBodyPart();
+521                        multipartRelated = new MimeMultipart("related");
+522                        final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
+523                        multipartAlternativeMessages = new MimeMultipart("alternative");
+524                        try {
+525                                // construct mail structure
+526                                multipartRoot.addBodyPart(contentRelated);
+527                                contentRelated.setContent(multipartRelated);
+528                                multipartRelated.addBodyPart(contentAlternativeMessages);
+529                                contentAlternativeMessages.setContent(multipartAlternativeMessages);
+530                        } catch (final MessagingException e) {
+531                                logger.error(e.getMessage(), e);
+532                                throw new RuntimeException(e.getMessage(), e);
+533                        }
+534                }
+535        }
+536
+537        /**
+538         * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
+539         * instance. By default no validation will be performed by simple-java-mail, until a criteria object has been set.
+540         * 
+541         * @param emailAddressValidationCriteria Refer to
+542         *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
+543         */
+544        public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
+545                this.emailAddressValidationCriteria = emailAddressValidationCriteria;
+546        }
+547}
 
 
 
@@ -581,6 +613,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.html index d0e5df973..11c78bc17 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Mailer.html @@ -1,526 +1,558 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.io.UnsupportedEncodingException;
-004    import java.util.Date;
-005    import java.util.Map;
-006    import java.util.Properties;
-007    
-008    import javax.activation.DataHandler;
-009    import javax.activation.DataSource;
-010    import javax.mail.Address;
-011    import javax.mail.Authenticator;
-012    import javax.mail.BodyPart;
-013    import javax.mail.Message;
-014    import javax.mail.MessagingException;
-015    import javax.mail.Part;
-016    import javax.mail.PasswordAuthentication;
-017    import javax.mail.Session;
-018    import javax.mail.Transport;
-019    import javax.mail.internet.InternetAddress;
-020    import javax.mail.internet.MimeBodyPart;
-021    import javax.mail.internet.MimeMessage;
-022    import javax.mail.internet.MimeMultipart;
-023    import javax.mail.internet.MimeUtility;
-024    
-025    import org.apache.log4j.Logger;
-026    
-027    /**
-028     * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
-029     * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br />
-030     * <br />
-031     * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
-032     * instances. <br />
-033     * <br />
-034     * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
-035     * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br />
-036     * <br />
-037     * Technically, the resulting email structure is as follows:<br />
-038     * 
-039     * <pre>
-040     * - root
-041     *      - related
-042     *              - alternative
-043     *                      - mail text
-044     *                      - mail html text
-045     *              - embedded images
-046     *      - attachments
-047     * </pre>
-048     * 
-049     * <br />
-050     * Usage example:<br />
-051     * 
-052     * <pre>
-053     * Email email = new Email();
-054     * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
-055     * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
-056     * email.setText(&quot;We should meet up!!&quot;);
-057     * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
-058     * email.setSubject(&quot;Hey&quot;);
-059     * new Mailer(preconfiguredMailSession).sendMail(email);
-060     * // or:
-061     * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
-062     * </pre>
-063     * 
-064     * @author Benny Bottema
-065     * @see MimeEmailMessageWrapper
-066     * @see Email
-067     */
-068    public class Mailer {
-069    
-070            private static final Logger logger = Logger.getLogger(Mailer.class);
-071            
-072            /**
-073             * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
-074             */
-075            private static final String CHARACTER_ENCODING = "UTF-8";
-076    
-077            /**
-078             * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
-079             * directly, when no <code>Session</code> instance was provided.
-080             * 
-081             * @see #Mailer(Session)
-082             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-083             */
-084            private final Session session;
-085    
-086            /**
-087             * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
-088             * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
-089             */
-090            private TransportStrategy transportStrategy;
-091    
-092            /**
-093             * Email address restriction flags set either by constructor or overridden by getter by user.
-094             * 
-095             * @see EmailAddressValidationCriteria
-096             */
-097            private EmailAddressValidationCriteria emailAddressValidationCriteria;
-098    
-099            /**
-100             * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
-101             * configured (host, port, authentication and transport protocol settings).
-102             * <p>
-103             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-104             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-105             * 
-106             * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
-107             */
-108            public Mailer(final Session session) {
-109                    this.session = session;
-110                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-111            }
-112    
-113            /**
-114             * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
-115             * web container, or Spring context etc.
-116             * <p>
-117             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-118             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-119             * 
-120             * @param host The address URL of the SMTP server to be used.
-121             * @param port The port of the SMTP server.
-122             * @param username An optional username, may be <code>null</code>.
-123             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-124             * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
-125             */
-126            public Mailer(final String host, final Integer port, final String username, final String password,
-127                            final TransportStrategy transportStrategy) {
-128                    // we're doing these validations manually instead of using Apache Commons to avoid another dependency
-129                    if (host == null || host.trim().equals("")) {
-130                            throw new MailException(MailException.MISSING_HOST);
-131                    } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
-132                            throw new MailException(MailException.MISSING_USERNAME);
-133                    }
-134                    this.transportStrategy = transportStrategy;
-135                    this.session = createMailSession(host, port, username, password);
-136                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-137            }
-138    
-139            /**
-140             * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
-141             * {@link #transportStrategy} in two ways:
-142             * <ol>
-143             * <li>request an initial property list which the strategy may pre-populate</li>
-144             * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
-145             * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
-146             * </ol>
-147             * 
-148             * @param host The address URL of the SMTP server to be used.
-149             * @param port The port of the SMTP server.
-150             * @param username An optional username, may be <code>null</code>.
-151             * @param password An optional password, may be <code>null</code>.
-152             * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
-153             * @see TransportStrategy#generateProperties()
-154             * @see TransportStrategy#propertyNameHost()
-155             * @see TransportStrategy#propertyNamePort()
-156             * @see TransportStrategy#propertyNameUsername()
-157             * @see TransportStrategy#propertyNameAuthenticate()
-158             */
-159            public Session createMailSession(final String host, final Integer port, final String username, final String password) {
-160                    if (transportStrategy == null) {
-161                            logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
-162                            transportStrategy = TransportStrategy.SMTP_PLAIN;
-163                    }
-164                    Properties props = transportStrategy.generateProperties();
-165                    props.put(transportStrategy.propertyNameHost(), host);
-166                    if (port != null) {
-167                            props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
-168                    } else {
-169                            // let JavaMail's Transport objects determine deault port base don the used protocol
-170                    }
-171    
-172                    if (username != null) {
-173                            props.put(transportStrategy.propertyNameUsername(), username);
-174                    }
-175    
-176                    if (password != null) {
-177                            props.put(transportStrategy.propertyNameAuthenticate(), "true");
-178                            return Session.getInstance(props, new Authenticator() {
-179                                    @Override
-180                                    protected PasswordAuthentication getPasswordAuthentication() {
-181                                            return new PasswordAuthentication(username, password);
-182                                    }
-183                            });
-184                    } else {
-185                            return Session.getInstance(props);
-186                    }
-187            }
-188    
-189            /**
-190             * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
-191             * 
-192             * @param host The address URL of the SMTP server to be used.
-193             * @param port The port of the SMTP server.
-194             * @param username An optional username, may be <code>null</code>.
-195             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-196             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-197             */
-198            public Mailer(final String host, final Integer port, final String username, final String password) {
-199                    this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
-200            }
-201    
-202            /**
-203             * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
-204             * 
-205             * @param debug Flag to indicate debug mode yes/no.
-206             */
-207            public void setDebug(boolean debug) {
-208                    session.setDebug(debug);
-209            }
-210    
-211            /**
-212             * Processes an {@link Email} instance into a completely configured {@link Message}.
-213             * <p>
-214             * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
-215             * all connection details have been configured in the provided {@link Session} instance.
-216             * <p>
-217             * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
-218             * providing a message id.
-219             * 
-220             * @param email The information for the email to be sent.
-221             * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
-222             *             etc.
-223             * @see #validate(Email)
-224             * @see #prepareMessage(Email, MimeEmailMessageWrapper)
-225             * @see #setRecipients(Email, Message)
-226             * @see #setTexts(Email, MimeMultipart)
-227             * @see #setEmbeddedImages(Email, MimeMultipart)
-228             * @see #setAttachments(Email, MimeMultipart)
-229             */
-230            public final void sendMail(final Email email)
-231                            throws MailException {
-232                    if (validate(email)) {
-233                            try {
-234                                    // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
-235                                    final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
-236                                    // fill and send wrapped mime message parts
-237                                    final Message message = prepareMessage(email, messageRoot);
-238                                    logSession(session, transportStrategy);
-239                                    message.saveChanges(); // some headers and id's will be set for this specific message
-240                                    Transport transport = session.getTransport();
-241                                    transport.connect();
-242                                    transport.sendMessage(message, message.getAllRecipients());
-243                                    transport.close();
-244                            } catch (final UnsupportedEncodingException e) {
-245                                    logger.error(e.getMessage(), e);
-246                                    throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
-247                            } catch (final MessagingException e) {
-248                                    logger.error(e.getMessage(), e);
-249                                    throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
-250                            }
-251                    }
-252            }
-253    
-254            /**
-255             * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
-256             */
-257            private void logSession(Session session, TransportStrategy transportStrategy) {
-258                    final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
-259                    Properties properties = session.getProperties();
-260                    logger.debug(String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
-261                                    properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
-262                                    properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy));
-263            }
-264    
-265            /**
-266             * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
-267             * 
-268             * @param email The email that needs to be configured correctly.
-269             * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
-270             * @throws MailException Is being thrown in any of the above causes.
-271             * @see EmailValidationUtil
-272             */
-273            public boolean validate(final Email email)
-274                            throws MailException {
-275                    if (email.getText() == null && email.getTextHTML() == null) {
-276                            throw new MailException(MailException.MISSING_CONTENT);
-277                    } else if (email.getSubject() == null || email.getSubject().equals("")) {
-278                            throw new MailException(MailException.MISSING_SUBJECT);
-279                    } else if (email.getRecipients().size() == 0) {
-280                            throw new MailException(MailException.MISSING_RECIPIENT);
-281                    } else if (email.getFromRecipient() == null) {
-282                            throw new MailException(MailException.MISSING_SENDER);
-283                    } else {
-284                            if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
-285                                    throw new MailException(String.format(MailException.INVALID_SENDER, email));
-286                            }
-287                            for (final Recipient recipient : email.getRecipients()) {
-288                                    if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
-289                                            throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
-290                                    }
-291                            }
-292                            if (email.getReplyToRecipient() != null) {
-293                                    if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
-294                                            throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
-295                                    }
-296                            }
-297                    }
-298                    return true;
-299            }
-300    
-301            /**
-302             * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
-303             * <p>
-304             * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
-305             * 
-306             * @param email The email message from which the subject and From-address are extracted.
-307             * @param messageRoot The root of the email which holds everything (filled with some email data).
-308             * @return A fully preparated {@link Message} instance, ready to be sent.
-309             * @throws MessagingException Kan gegooid worden als het message niet goed behandelt wordt.
-310             * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
-311             */
-312            private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
-313                            throws MessagingException, UnsupportedEncodingException {
-314                    final MimeMessage message = new MimeMessage(session);
-315                    // set basic email properties
-316                    message.setSubject(email.getSubject(), CHARACTER_ENCODING);
-317                    message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
-318                    setReplyTo(email, message);
-319                    setRecipients(email, message);
-320                    // fill multipart structure
-321                    setTexts(email, messageRoot.multipartAlternativeMessages);
-322                    setEmbeddedImages(email, messageRoot.multipartRelated);
-323                    setAttachments(email, messageRoot.multipartRoot);
-324                    message.setContent(messageRoot.multipartRoot);
-325                    setHeaders(email, message);
-326                    message.setSentDate(new Date());
-327                    return message;
-328            }
-329    
-330            /**
-331             * Fills the {@link Message} instance with recipients from the {@link Email}.
-332             * 
-333             * @param email The message in which the recipients are defined.
-334             * @param message The javax message that needs to be filled with recipients.
-335             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-336             * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
-337             */
-338            private void setRecipients(final Email email, final Message message)
-339                            throws UnsupportedEncodingException, MessagingException {
-340                    for (final Recipient recipient : email.getRecipients()) {
-341                            final Address address = new InternetAddress(recipient.getAddress(), recipient.getName());
-342                            message.addRecipient(recipient.getType(), address);
-343                    }
-344            }
-345    
-346            /**
-347             * Fills the {@link Message} instance with reply-to address.
-348             * 
-349             * @param email The message in which the recipients are defined.
-350             * @param message The javax message that needs to be filled with reply-to address.
-351             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-352             * @throws MessagingException See {@link Message#setReplyTo(Address[])}
-353             */
-354            private void setReplyTo(final Email email, final Message message)
-355                            throws UnsupportedEncodingException, MessagingException {
-356                    final Recipient replyToRecipient = email.getReplyToRecipient();
-357                    if (replyToRecipient != null) {
-358                            InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(), CHARACTER_ENCODING);
-359                            message.setReplyTo(new Address[] { replyToAddress });
-360                    }
-361            }
-362    
-363            /**
-364             * Fills the {@link Message} instance with the content bodies (text and html).
-365             * 
-366             * @param email The message in which the content is defined.
-367             * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
-368             * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
-369             *             {@link MimeMultipart#addBodyPart(BodyPart)}.
-370             */
-371            private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
-372                            throws MessagingException {
-373                    if (email.getText() != null) {
-374                            final MimeBodyPart messagePart = new MimeBodyPart();
-375                            messagePart.setText(email.getText(), CHARACTER_ENCODING);
-376                            multipartAlternativeMessages.addBodyPart(messagePart);
-377                    }
-378                    if (email.getTextHTML() != null) {
-379                            final MimeBodyPart messagePartHTML = new MimeBodyPart();
-380                            messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
-381                            multipartAlternativeMessages.addBodyPart(messagePartHTML);
-382                    }
-383            }
-384    
-385            /**
-386             * Fills the {@link Message} instance with the embedded images from the {@link Email}.
-387             * 
-388             * @param email The message in which the embedded images are defined.
-389             * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
-390             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-391             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-392             */
-393            private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
-394                            throws MessagingException {
-395                    for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
-396                            multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
-397                    }
-398            }
-399    
-400            /**
-401             * Fills the {@link Message} instance with the attachments from the {@link Email}.
-402             * 
-403             * @param email The message in which the attachments are defined.
-404             * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
-405             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-406             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-407             */
-408            private void setAttachments(final Email email, final MimeMultipart multipartRoot)
-409                            throws MessagingException {
-410                    for (final AttachmentResource resource : email.getAttachments()) {
-411                            multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
-412                    }
-413            }
-414    
-415            /**
-416             * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
-417             * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
-418             * 
-419             * @param email The message in which the headers are defined.
-420             * @param message The {@link Message} on which to set the raw, encoded and folded headers.
-421             * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
-422             * @throws MessagingException See {@link Message#addHeader(String, String)}
-423             * @see {@link MimeUtility#encodeText(String, String, String)}
-424             * @see MimeUtility#fold(int, String)
-425             */
-426            private void setHeaders(final Email email, final Message message)
-427                            throws UnsupportedEncodingException, MessagingException {
-428                    // add headers (for raw message headers we need to 'fold' them using MimeUtility
-429                    for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
-430                            String headerName = header.getKey();
-431                            String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
-432                            String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
-433                            message.addHeader(header.getKey(), foldedHeaderValue);
-434                    }
-435            }
-436    
-437            /**
-438             * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
-439             * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
-440             * email structure. <br />
-441             * <br />
-442             * For every attachment and embedded image a header needs to be set.
-443             * 
-444             * @param resource An object that describes the attachment and contains the actual content data.
-445             * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
-446             * @return An object with the attachment data read for placement in the email structure.
-447             * @throws MessagingException All BodyPart setters.
-448             */
-449            private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
-450                            throws MessagingException {
-451                    final BodyPart attachmentPart = new MimeBodyPart();
-452                    final DataSource ds = resource.getDataSource();
-453                    // setting headers isn't working nicely using the javax mail API, so let's do that manually
-454                    attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
-455                    attachmentPart.setFileName(resource.getName());
-456                    attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
-457                    attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
-458                    attachmentPart.setDisposition(dispositionType + "; size=0");
-459                    return attachmentPart;
-460            }
-461    
-462            /**
-463             * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
-464             * ultimately sent using JavaMail.<br />
-465             * <br />
-466             * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
-467             * 
-468             * <pre>
-469             * - root
-470             *      - related
-471             *              - alternative
-472             *                      - mail tekst
-473             *                      - mail html tekst
-474             *              - embedded images
-475             *      - attachments
-476             * </pre>
-477             * 
-478             * @author Benny Bottema
-479             */
-480            private class MimeEmailMessageWrapper {
-481    
-482                    private final MimeMultipart multipartRoot;
-483    
-484                    private final MimeMultipart multipartRelated;
-485    
-486                    private final MimeMultipart multipartAlternativeMessages;
-487    
-488                    /**
-489                     * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
-490                     */
-491                    MimeEmailMessageWrapper() {
-492                            multipartRoot = new MimeMultipart("mixed");
-493                            final MimeBodyPart contentRelated = new MimeBodyPart();
-494                            multipartRelated = new MimeMultipart("related");
-495                            final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
-496                            multipartAlternativeMessages = new MimeMultipart("alternative");
-497                            try {
-498                                    // construct mail structure
-499                                    multipartRoot.addBodyPart(contentRelated);
-500                                    contentRelated.setContent(multipartRelated);
-501                                    multipartRelated.addBodyPart(contentAlternativeMessages);
-502                                    contentAlternativeMessages.setContent(multipartAlternativeMessages);
-503                            } catch (final MessagingException e) {
-504                                    logger.error(e.getMessage(), e);
-505                                    throw new RuntimeException(e.getMessage(), e);
-506                            }
-507                    }
-508            }
-509    
-510            /**
-511             * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
-512             * instance.
-513             * 
-514             * @param emailAddressValidationCriteria Refer to
-515             *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
-516             */
-517            public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
-518                    this.emailAddressValidationCriteria = emailAddressValidationCriteria;
-519            }
-520    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.io.UnsupportedEncodingException;
+004import java.util.Date;
+005import java.util.Map;
+006import java.util.Properties;
+007
+008import javax.activation.DataHandler;
+009import javax.activation.DataSource;
+010import javax.mail.Address;
+011import javax.mail.Authenticator;
+012import javax.mail.BodyPart;
+013import javax.mail.Message;
+014import javax.mail.MessagingException;
+015import javax.mail.Part;
+016import javax.mail.PasswordAuthentication;
+017import javax.mail.Session;
+018import javax.mail.Transport;
+019import javax.mail.internet.InternetAddress;
+020import javax.mail.internet.MimeBodyPart;
+021import javax.mail.internet.MimeMessage;
+022import javax.mail.internet.MimeMultipart;
+023import javax.mail.internet.MimeUtility;
+024
+025import org.slf4j.Logger;
+026import org.slf4j.LoggerFactory;
+027
+028/**
+029 * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
+030 * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br>
+031 * <br>
+032 * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
+033 * instances. <br>
+034 * <br>
+035 * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
+036 * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br>
+037 * <br>
+038 * Technically, the resulting email structure is as follows:<br>
+039 * 
+040 * <pre>
+041 * - root
+042 *      - related
+043 *              - alternative
+044 *                      - mail text
+045 *                      - mail html text
+046 *              - embedded images
+047 *      - attachments
+048 * </pre>
+049 * 
+050 * <br>
+051 * Usage example:<br>
+052 * 
+053 * <pre>
+054 * Email email = new Email();
+055 * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
+056 * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
+057 * email.setText(&quot;We should meet up!!&quot;);
+058 * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
+059 * email.setSubject(&quot;Hey&quot;);
+060 * new Mailer(preconfiguredMailSession).sendMail(email);
+061 * // or:
+062 * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
+063 * </pre>
+064 * 
+065 * @author Benny Bottema
+066 * @see MimeEmailMessageWrapper
+067 * @see Email
+068 */
+069public class Mailer {
+070
+071        private static final Logger logger = LoggerFactory.getLogger(Mailer.class);
+072
+073        /**
+074         * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
+075         */
+076        private static final String CHARACTER_ENCODING = "UTF-8";
+077
+078        /**
+079         * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
+080         * directly, when no <code>Session</code> instance was provided.
+081         * 
+082         * @see #Mailer(Session)
+083         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+084         */
+085        private final Session session;
+086
+087        /**
+088         * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
+089         * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
+090         */
+091        private TransportStrategy transportStrategy;
+092
+093        /**
+094         * Email address restriction flags set either by constructor or overridden by getter by user.
+095         * 
+096         * @see EmailAddressValidationCriteria
+097         */
+098        private EmailAddressValidationCriteria emailAddressValidationCriteria;
+099
+100        /**
+101         * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
+102         * configured (host, port, authentication and transport protocol settings).
+103         * <p>
+104         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+105         * smtp server instead.
+106         * 
+107         * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
+108         */
+109        public Mailer(final Session session) {
+110                this.session = session;
+111                this.emailAddressValidationCriteria = null;
+112        }
+113
+114        /**
+115         * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
+116         * web container, or Spring context etc.
+117         * <p>
+118         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+119         * smtp server instead.
+120         * 
+121         * @param host The address URL of the SMTP server to be used.
+122         * @param port The port of the SMTP server.
+123         * @param username An optional username, may be <code>null</code>.
+124         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+125         * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
+126         */
+127        public Mailer(final String host, final Integer port, final String username, final String password,
+128                        final TransportStrategy transportStrategy) {
+129                // we're doing these validations manually instead of using Apache Commons to avoid another dependency
+130                if (host == null || host.trim().equals("")) {
+131                        throw new MailException(MailException.MISSING_HOST);
+132                } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
+133                        throw new MailException(MailException.MISSING_USERNAME);
+134                }
+135                this.transportStrategy = transportStrategy;
+136                this.session = createMailSession(host, port, username, password);
+137                this.emailAddressValidationCriteria = null;
+138        }
+139
+140        /**
+141         * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
+142         * {@link #transportStrategy} in two ways:
+143         * <ol>
+144         * <li>request an initial property list which the strategy may pre-populate</li>
+145         * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
+146         * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
+147         * </ol>
+148         * 
+149         * @param host The address URL of the SMTP server to be used.
+150         * @param port The port of the SMTP server.
+151         * @param username An optional username, may be <code>null</code>.
+152         * @param password An optional password, may be <code>null</code>.
+153         * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
+154         * @see TransportStrategy#generateProperties()
+155         * @see TransportStrategy#propertyNameHost()
+156         * @see TransportStrategy#propertyNamePort()
+157         * @see TransportStrategy#propertyNameUsername()
+158         * @see TransportStrategy#propertyNameAuthenticate()
+159         */
+160        protected Session createMailSession(final String host, final Integer port, final String username, final String password) {
+161                if (transportStrategy == null) {
+162                        logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
+163                        transportStrategy = TransportStrategy.SMTP_PLAIN;
+164                }
+165                Properties props = transportStrategy.generateProperties();
+166                props.put(transportStrategy.propertyNameHost(), host);
+167                if (port != null) {
+168                        props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
+169                } else {
+170                        // let JavaMail's Transport objects determine deault port base don the used protocol
+171                }
+172
+173                if (username != null) {
+174                        props.put(transportStrategy.propertyNameUsername(), username);
+175                }
+176
+177                if (password != null) {
+178                        props.put(transportStrategy.propertyNameAuthenticate(), "true");
+179                        return Session.getInstance(props, new Authenticator() {
+180                                @Override
+181                                protected PasswordAuthentication getPasswordAuthentication() {
+182                                        return new PasswordAuthentication(username, password);
+183                                }
+184                        });
+185                } else {
+186                        return Session.getInstance(props);
+187                }
+188        }
+189
+190        /**
+191         * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
+192         * 
+193         * @param host The address URL of the SMTP server to be used.
+194         * @param port The port of the SMTP server.
+195         * @param username An optional username, may be <code>null</code>.
+196         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+197         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+198         */
+199        public Mailer(final String host, final Integer port, final String username, final String password) {
+200                this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
+201        }
+202
+203        /**
+204         * In case Simple Java Mail falls short somehow, you can get a hold of the internal {@link Session} instance to debug or tweak. Please
+205         * let us know why you are needing this on https://github.com/bbottema/simple-java-mail/issues.
+206         */
+207        public Session getSession() {
+208                logger.warn("Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it.");
+209                logger.warn("\t>https://github.com/bbottema/simple-java-mail/issues");
+210                return session;
+211        }
+212
+213        /**
+214         * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
+215         * 
+216         * @param debug Flag to indicate debug mode yes/no.
+217         */
+218        public void setDebug(final boolean debug) {
+219                session.setDebug(debug);
+220        }
+221
+222        /**
+223         * Copies all property entries into the {@link Session} using {@link Session#getProperties()}.
+224         * 
+225         * @param properties The source properties to add or override in the internal {@link Session} instance.
+226         */
+227        public void applyProperties(final Properties properties) {
+228                session.getProperties().putAll(properties);
+229        }
+230
+231        /**
+232         * Processes an {@link Email} instance into a completely configured {@link Message}.
+233         * <p>
+234         * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
+235         * all connection details have been configured in the provided {@link Session} instance.
+236         * <p>
+237         * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
+238         * providing a message id.
+239         * 
+240         * @param email The information for the email to be sent.
+241         * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
+242         *             etc.
+243         * @see #validate(Email)
+244         * @see #prepareMessage(Email, MimeEmailMessageWrapper)
+245         * @see #setRecipients(Email, Message)
+246         * @see #setTexts(Email, MimeMultipart)
+247         * @see #setEmbeddedImages(Email, MimeMultipart)
+248         * @see #setAttachments(Email, MimeMultipart)
+249         */
+250        public final void sendMail(final Email email)
+251                        throws MailException {
+252                if (validate(email)) {
+253                        try {
+254                                // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
+255                                final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
+256                                // fill and send wrapped mime message parts
+257                                final Message message = prepareMessage(email, messageRoot);
+258                                logSession(session, transportStrategy);
+259                                message.saveChanges(); // some headers and id's will be set for this specific message
+260                                Transport transport = session.getTransport();
+261                                transport.connect();
+262                                transport.sendMessage(message, message.getAllRecipients());
+263                                transport.close();
+264                        } catch (final UnsupportedEncodingException e) {
+265                                logger.error(e.getMessage(), e);
+266                                throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
+267                        } catch (final MessagingException e) {
+268                                logger.error(e.getMessage(), e);
+269                                throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
+270                        }
+271                }
+272        }
+273
+274        /**
+275         * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
+276         */
+277        private void logSession(Session session, TransportStrategy transportStrategy) {
+278                Properties properties = session.getProperties();
+279                final String specifics;
+280                if (transportStrategy != null) {
+281                        final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
+282                        specifics = String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
+283                                        properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
+284                                        properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy);
+285                } else {
+286                        specifics = properties.toString();
+287                }
+288                logger.debug(String.format("starting mail session (%s)", specifics));
+289        }
+290
+291        /**
+292         * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
+293         * 
+294         * @param email The email that needs to be configured correctly.
+295         * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
+296         * @throws MailException Is being thrown in any of the above causes.
+297         * @see EmailValidationUtil
+298         */
+299        public boolean validate(final Email email)
+300                        throws MailException {
+301                if (email.getText() == null && email.getTextHTML() == null) {
+302                        throw new MailException(MailException.MISSING_CONTENT);
+303                } else if (email.getSubject() == null || email.getSubject().equals("")) {
+304                        throw new MailException(MailException.MISSING_SUBJECT);
+305                } else if (email.getRecipients().size() == 0) {
+306                        throw new MailException(MailException.MISSING_RECIPIENT);
+307                } else if (email.getFromRecipient() == null) {
+308                        throw new MailException(MailException.MISSING_SENDER);
+309                } else if (emailAddressValidationCriteria != null) {
+310                        if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
+311                                throw new MailException(String.format(MailException.INVALID_SENDER, email));
+312                        }
+313                        for (final Recipient recipient : email.getRecipients()) {
+314                                if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
+315                                        throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
+316                                }
+317                        }
+318                        if (email.getReplyToRecipient() != null) {
+319                                if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
+320                                        throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
+321                                }
+322                        }
+323                }
+324                return true;
+325        }
+326
+327        /**
+328         * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
+329         * <p>
+330         * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
+331         * 
+332         * @param email The email message from which the subject and From-address are extracted.
+333         * @param messageRoot The root of the email which holds everything (filled with some email data).
+334         * @return A fully preparated {@link Message} instance, ready to be sent.
+335         * @throws MessagingException May be thrown when the message couldn't be processed by JavaMail.
+336         * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
+337         */
+338        private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
+339                        throws MessagingException, UnsupportedEncodingException {
+340                final MimeMessage message = new MimeMessage(session);
+341                // set basic email properties
+342                message.setSubject(email.getSubject(), CHARACTER_ENCODING);
+343                message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
+344                setReplyTo(email, message);
+345                setRecipients(email, message);
+346                // fill multipart structure
+347                setTexts(email, messageRoot.multipartAlternativeMessages);
+348                setEmbeddedImages(email, messageRoot.multipartRelated);
+349                setAttachments(email, messageRoot.multipartRoot);
+350                message.setContent(messageRoot.multipartRoot);
+351                setHeaders(email, message);
+352                message.setSentDate(new Date());
+353                return message;
+354        }
+355
+356        /**
+357         * Fills the {@link Message} instance with recipients from the {@link Email}.
+358         * 
+359         * @param email The message in which the recipients are defined.
+360         * @param message The javax message that needs to be filled with recipients.
+361         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+362         * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
+363         */
+364        private void setRecipients(final Email email, final Message message)
+365                        throws UnsupportedEncodingException, MessagingException {
+366                for (final Recipient recipient : email.getRecipients()) {
+367                        final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
+368                        message.addRecipient(recipient.getType(), address);
+369                }
+370        }
+371
+372        /**
+373         * Fills the {@link Message} instance with reply-to address.
+374         * 
+375         * @param email The message in which the recipients are defined.
+376         * @param message The javax message that needs to be filled with reply-to address.
+377         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+378         * @throws MessagingException See {@link Message#setReplyTo(Address[])}
+379         */
+380        private void setReplyTo(final Email email, final Message message)
+381                        throws UnsupportedEncodingException, MessagingException {
+382                final Recipient replyToRecipient = email.getReplyToRecipient();
+383                if (replyToRecipient != null) {
+384                        InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(),
+385                                        CHARACTER_ENCODING);
+386                        message.setReplyTo(new Address[] { replyToAddress });
+387                }
+388        }
+389
+390        /**
+391         * Fills the {@link Message} instance with the content bodies (text and html).
+392         * 
+393         * @param email The message in which the content is defined.
+394         * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
+395         * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
+396         *             {@link MimeMultipart#addBodyPart(BodyPart)}.
+397         */
+398        private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
+399                        throws MessagingException {
+400                if (email.getText() != null) {
+401                        final MimeBodyPart messagePart = new MimeBodyPart();
+402                        messagePart.setText(email.getText(), CHARACTER_ENCODING);
+403                        multipartAlternativeMessages.addBodyPart(messagePart);
+404                }
+405                if (email.getTextHTML() != null) {
+406                        final MimeBodyPart messagePartHTML = new MimeBodyPart();
+407                        messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
+408                        multipartAlternativeMessages.addBodyPart(messagePartHTML);
+409                }
+410        }
+411
+412        /**
+413         * Fills the {@link Message} instance with the embedded images from the {@link Email}.
+414         * 
+415         * @param email The message in which the embedded images are defined.
+416         * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
+417         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+418         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+419         */
+420        private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
+421                        throws MessagingException {
+422                for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
+423                        multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
+424                }
+425        }
+426
+427        /**
+428         * Fills the {@link Message} instance with the attachments from the {@link Email}.
+429         * 
+430         * @param email The message in which the attachments are defined.
+431         * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
+432         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+433         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+434         */
+435        private void setAttachments(final Email email, final MimeMultipart multipartRoot)
+436                        throws MessagingException {
+437                for (final AttachmentResource resource : email.getAttachments()) {
+438                        multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
+439                }
+440        }
+441
+442        /**
+443         * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
+444         * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
+445         * 
+446         * @param email The message in which the headers are defined.
+447         * @param message The {@link Message} on which to set the raw, encoded and folded headers.
+448         * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
+449         * @throws MessagingException See {@link Message#addHeader(String, String)}
+450         * @see {@link MimeUtility#encodeText(String, String, String)}
+451         * @see MimeUtility#fold(int, String)
+452         */
+453        private void setHeaders(final Email email, final Message message)
+454                        throws UnsupportedEncodingException, MessagingException {
+455                // add headers (for raw message headers we need to 'fold' them using MimeUtility
+456                for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
+457                        String headerName = header.getKey();
+458                        String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
+459                        String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
+460                        message.addHeader(header.getKey(), foldedHeaderValue);
+461                }
+462        }
+463
+464        /**
+465         * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
+466         * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
+467         * email structure. <br>
+468         * <br>
+469         * For every attachment and embedded image a header needs to be set.
+470         * 
+471         * @param resource An object that describes the attachment and contains the actual content data.
+472         * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
+473         * @return An object with the attachment data read for placement in the email structure.
+474         * @throws MessagingException All BodyPart setters.
+475         */
+476        private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
+477                        throws MessagingException {
+478                final BodyPart attachmentPart = new MimeBodyPart();
+479                final DataSource ds = resource.getDataSource();
+480                // setting headers isn't working nicely using the javax mail API, so let's do that manually
+481                attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
+482                attachmentPart.setFileName(resource.getName());
+483                attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
+484                attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
+485                attachmentPart.setDisposition(dispositionType + "; size=0");
+486                return attachmentPart;
+487        }
+488
+489        /**
+490         * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
+491         * ultimately sent using JavaMail.<br>
+492         * <br>
+493         * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
+494         * 
+495         * <pre>
+496         * - root
+497         *      - related
+498         *              - alternative
+499         *                      - mail tekst
+500         *                      - mail html tekst
+501         *              - embedded images
+502         *      - attachments
+503         * </pre>
+504         * 
+505         * @author Benny Bottema
+506         */
+507        private class MimeEmailMessageWrapper {
+508
+509                private final MimeMultipart multipartRoot;
+510
+511                private final MimeMultipart multipartRelated;
+512
+513                private final MimeMultipart multipartAlternativeMessages;
+514
+515                /**
+516                 * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
+517                 */
+518                MimeEmailMessageWrapper() {
+519                        multipartRoot = new MimeMultipart("mixed");
+520                        final MimeBodyPart contentRelated = new MimeBodyPart();
+521                        multipartRelated = new MimeMultipart("related");
+522                        final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
+523                        multipartAlternativeMessages = new MimeMultipart("alternative");
+524                        try {
+525                                // construct mail structure
+526                                multipartRoot.addBodyPart(contentRelated);
+527                                contentRelated.setContent(multipartRelated);
+528                                multipartRelated.addBodyPart(contentAlternativeMessages);
+529                                contentAlternativeMessages.setContent(multipartAlternativeMessages);
+530                        } catch (final MessagingException e) {
+531                                logger.error(e.getMessage(), e);
+532                                throw new RuntimeException(e.getMessage(), e);
+533                        }
+534                }
+535        }
+536
+537        /**
+538         * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
+539         * instance. By default no validation will be performed by simple-java-mail, until a criteria object has been set.
+540         * 
+541         * @param emailAddressValidationCriteria Refer to
+542         *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
+543         */
+544        public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
+545                this.emailAddressValidationCriteria = emailAddressValidationCriteria;
+546        }
+547}
 
 
 
@@ -581,6 +613,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Recipient.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Recipient.html index c2e9e25fe..392bbb983 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/Recipient.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/Recipient.html @@ -1,58 +1,63 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import javax.mail.Message.RecipientType;
-004    
-005    /**
-006     * An immutable recipient object, with a name, emailadres and recipient type (eg {@link RecipientType#BCC}).
-007     * 
-008     * @author Benny Bottema
-009     */
-010    public final class Recipient {
-011    
-012            private final String name;
-013    
-014            private final String address;
-015    
-016            private final RecipientType type;
-017    
-018            /**
-019             * Constructor; initializes this recipient object.
-020             * 
-021             * @param name The name of the recipient.
-022             * @param address The email address of the recipient.
-023             * @param type The recipient type (eg. {@link RecipientType#TO}).
-024             * @see RecipientType
-025             */
-026            public Recipient(final String name, final String address, final RecipientType type) {
-027                    this.name = name;
-028                    this.address = address;
-029                    this.type = type;
-030            }
-031    
-032            /**
-033             * Bean getter for {@link #name};
-034             */
-035            public String getName() {
-036                    return name;
-037            }
-038    
-039            /**
-040             * Bean getter for {@link #address};
-041             */
-042            public String getAddress() {
-043                    return address;
-044            }
-045    
-046            /**
-047             * Bean getter for {@link #type};
-048             */
-049            public RecipientType getType() {
-050                    return type;
-051            }
-052    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import javax.mail.Message.RecipientType;
+004
+005/**
+006 * An immutable recipient object, with a name, emailadres and recipient type (eg {@link RecipientType#BCC}).
+007 * 
+008 * @author Benny Bottema
+009 */
+010public final class Recipient {
+011
+012        private final String name;
+013
+014        private final String address;
+015
+016        private final RecipientType type;
+017
+018        /**
+019         * Constructor; initializes this recipient object.
+020         * 
+021         * @param name The name of the recipient.
+022         * @param address The email address of the recipient.
+023         * @param type The recipient type (eg. {@link RecipientType#TO}).
+024         * @see RecipientType
+025         */
+026        public Recipient(final String name, final String address, final RecipientType type) {
+027                this.name = name;
+028                this.address = address;
+029                this.type = type;
+030        }
+031
+032        /**
+033         * Bean getter for {@link #name};
+034         */
+035        public String getName() {
+036                return name;
+037        }
+038
+039        /**
+040         * Bean getter for {@link #address};
+041         */
+042        public String getAddress() {
+043                return address;
+044        }
+045
+046        /**
+047         * Bean getter for {@link #type};
+048         */
+049        public RecipientType getType() {
+050                return type;
+051        }
+052}
 
 
 
@@ -113,6 +118,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/developers/src-html/org/codemonkey/simplejavamail/TransportStrategy.html b/javadoc/developers/src-html/org/codemonkey/simplejavamail/TransportStrategy.html index e5b7a7f46..55bd0bdbb 100644 --- a/javadoc/developers/src-html/org/codemonkey/simplejavamail/TransportStrategy.html +++ b/javadoc/developers/src-html/org/codemonkey/simplejavamail/TransportStrategy.html @@ -1,204 +1,209 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.util.Properties;
-004    
-005    import javax.mail.Session;
-006    
-007    /**
-008     * Defines the various types of transport protocols and implements respective properties so that a {@link Session} may be configured using a
-009     * <code>TransportStrategy</code> implementation.
-010     * 
-011     * @author Benny Bottema
-012     */
-013    public enum TransportStrategy {
-014    
-015            /**
-016             * Simplest possible form: only vanilla ".smtp." property names and no extra properties. Additionally the transport protocol is
-017             * explicitly set to smtp.
-018             */
-019            SMTP_PLAIN {
-020                    /**
-021                     * Here protocol "mail.transport.protocol" is set to "smtp".
-022                     * 
-023                     * @see TransportStrategy#SMTP_PLAIN
-024                     */
-025                    @Override
-026                    public Properties generateProperties() {
-027                            final Properties props = super.generateProperties();
-028                            props.put("mail.transport.protocol", "smtp");
-029                            return props;
-030                    };
-031    
-032                    /**
-033                     * @return "mail.smtp.host"
-034                     */
-035                    @Override
-036                    String propertyNameHost() {
-037                            return "mail.smtp.host";
-038                    };
-039    
-040                    /**
-041                     * @return "mail.smtp.port"
-042                     */
-043                    @Override
-044                    String propertyNamePort() {
-045                            return "mail.smtp.port";
-046                    };
-047    
-048                    /**
-049                     * @return "mail.smtp.username"
-050                     */
-051                    @Override
-052                    String propertyNameUsername() {
-053                            return "mail.smtp.username";
-054                    };
-055    
-056                    /**
-057                     * @return "mail.smtp.auth"
-058                     */
-059                    @Override
-060                    String propertyNameAuthenticate() {
-061                            return "mail.smtp.auth";
-062                    };
-063            },
-064            /**
-065             * SMTPS / SSL transport strategy, that returns the ".smtps." variation of the SMTP_PLAIN version. Additionally the transport protocol
-066             * is explicitly set to smtps. Finally, he property "mail.smtps.quitwait" is set to false, to get rid of a strange SSL exception:<br />
-067             * 
-068             * <pre>
-069             * javax.mail.MessagingException: Exception reading response;
-070             * nested exception is:
-071             *      javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
-072             * (..)
-073             * </pre>
-074             * 
-075             * <quote>The mail is sent but the exception is unwanted. The property <em>quitwait</em> means If set to false, the QUIT command is sent
-076             * and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT
-077             * command</quote><br />
-078             * <strong>- <a href="http://www.rgagnon.com/javadetails/java-0570.html">source</a></strong>
-079             */
-080            SMTP_SSL {
-081                    /**
-082                     * Here protocol "mail.transport.protocol" is set to "smtps" and the quitwait property "mail.smtps.quitwait" is set to "false".
-083                     * 
-084                     * @see TransportStrategy#SMTP_SSL
-085                     */
-086                    @Override
-087                    public Properties generateProperties() {
-088                            final Properties props = super.generateProperties();
-089                            props.put("mail.transport.protocol", "smtps");
-090                            props.put("mail.smtps.quitwait", "false");
-091                            return props;
-092                    };
-093    
-094                    /**
-095                     * @return "mail.smtps.host"
-096                     */
-097                    @Override
-098                    String propertyNameHost() {
-099                            return "mail.smtps.host";
-100                    };
-101    
-102                    /**
-103                     * @return "mail.smtps.port"
-104                     */
-105                    @Override
-106                    String propertyNamePort() {
-107                            return "mail.smtps.port";
-108                    };
-109    
-110                    /**
-111                     * @return "mail.smtps.username"
-112                     */
-113                    @Override
-114                    String propertyNameUsername() {
-115                            return "mail.smtps.username";
-116                    };
-117    
-118                    /**
-119                     * @return "mail.smtps.auth"
-120                     */
-121                    @Override
-122                    String propertyNameAuthenticate() {
-123                            return "mail.smtps.auth";
-124                    };
-125            },
-126            /**
-127             * <strong>NOTE: this code is in untested beta state</strong>
-128             * <p>
-129             * Uses standard ".smtp." property names (like {@link TransportStrategy#SMTP_PLAIN}). Additionally the transport protocol is explicitly
-130             * set to smtp. Finally, the property "mail.smtp.starttls.enable" is being set to true.
-131             */
-132            SMTP_TLS {
-133    
-134                    /**
-135                     * Here protocol "mail.transport.protocol" is set to "smtp" and the tls property "mail.smtp.starttls.enable" is set to "true".
-136                     * 
-137                     * @see TransportStrategy#SMTP_TLS
-138                     */
-139                    @Override
-140                    public Properties generateProperties() {
-141                            final Properties props = super.generateProperties();
-142                            props.put("mail.transport.protocol", "smtp");
-143                            props.put("mail.smtp.starttls.enable", "true");
-144                            return props;
-145                    }
-146    
-147                    /**
-148                     * @return "mail.smtp.host"
-149                     */
-150                    @Override
-151                    String propertyNameHost() {
-152                            return "mail.smtp.host";
-153                    };
-154    
-155                    /**
-156                     * @return "mail.smtp.port"
-157                     */
-158                    @Override
-159                    String propertyNamePort() {
-160                            return "mail.smtp.port";
-161                    };
-162    
-163                    /**
-164                     * @return "mail.smtp.username"
-165                     */
-166                    @Override
-167                    String propertyNameUsername() {
-168                            return "mail.smtp.username";
-169                    };
-170    
-171                    /**
-172                     * @return "mail.smtp.auth"
-173                     */
-174                    @Override
-175                    String propertyNameAuthenticate() {
-176                            return "mail.smtp.auth";
-177                    };
-178    
-179            };
-180    
-181            /**
-182             * Base implementation that simply returns an empty list of properties. Should be overridden by the various strategies where
-183             * appropriate.
-184             * 
-185             * @return An empty <code>Properties</code> instance.
-186             */
-187            public Properties generateProperties() {
-188                    return new Properties();
-189            }
-190    
-191            abstract String propertyNameHost();
-192    
-193            abstract String propertyNamePort();
-194    
-195            abstract String propertyNameUsername();
-196    
-197            abstract String propertyNameAuthenticate();
-198    };
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.Properties;
+004
+005import javax.mail.Session;
+006
+007/**
+008 * Defines the various types of transport protocols and implements respective properties so that a {@link Session} may be configured using a
+009 * <code>TransportStrategy</code> implementation.
+010 * 
+011 * @author Benny Bottema
+012 */
+013public enum TransportStrategy {
+014
+015        /**
+016         * Simplest possible form: only vanilla ".smtp." property names and no extra properties. Additionally the transport protocol is
+017         * explicitly set to smtp.
+018         */
+019        SMTP_PLAIN {
+020                /**
+021                 * Here protocol "mail.transport.protocol" is set to "smtp".
+022                 * 
+023                 * @see TransportStrategy#SMTP_PLAIN
+024                 */
+025                @Override
+026                public Properties generateProperties() {
+027                        final Properties props = super.generateProperties();
+028                        props.put("mail.transport.protocol", "smtp");
+029                        return props;
+030                };
+031
+032                /**
+033                 * @return "mail.smtp.host"
+034                 */
+035                @Override
+036                String propertyNameHost() {
+037                        return "mail.smtp.host";
+038                };
+039
+040                /**
+041                 * @return "mail.smtp.port"
+042                 */
+043                @Override
+044                String propertyNamePort() {
+045                        return "mail.smtp.port";
+046                };
+047
+048                /**
+049                 * @return "mail.smtp.username"
+050                 */
+051                @Override
+052                String propertyNameUsername() {
+053                        return "mail.smtp.username";
+054                };
+055
+056                /**
+057                 * @return "mail.smtp.auth"
+058                 */
+059                @Override
+060                String propertyNameAuthenticate() {
+061                        return "mail.smtp.auth";
+062                };
+063        },
+064        /**
+065         * SMTPS / SSL transport strategy, that returns the ".smtps." variation of the SMTP_PLAIN version. Additionally the transport protocol
+066         * is explicitly set to smtps. Finally, he property "mail.smtps.quitwait" is set to false, to get rid of a strange SSL exception:<br>
+067         * 
+068         * <pre>
+069         * javax.mail.MessagingException: Exception reading response;
+070         * nested exception is:
+071         *      javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
+072         * (..)
+073         * </pre>
+074         * 
+075         * <blockquote>The mail is sent but the exception is unwanted. The property <em>quitwait</em> means If set to false, the QUIT command is sent
+076         * and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT
+077         * command</blockquote><br>
+078         * <strong>- <a href="http://www.rgagnon.com/javadetails/java-0570.html">source</a></strong>
+079         */
+080        SMTP_SSL {
+081                /**
+082                 * Here protocol "mail.transport.protocol" is set to "smtps" and the quitwait property "mail.smtps.quitwait" is set to "false".
+083                 * 
+084                 * @see TransportStrategy#SMTP_SSL
+085                 */
+086                @Override
+087                public Properties generateProperties() {
+088                        final Properties props = super.generateProperties();
+089                        props.put("mail.transport.protocol", "smtps");
+090                        props.put("mail.smtps.quitwait", "false");
+091                        return props;
+092                };
+093
+094                /**
+095                 * @return "mail.smtps.host"
+096                 */
+097                @Override
+098                String propertyNameHost() {
+099                        return "mail.smtps.host";
+100                };
+101
+102                /**
+103                 * @return "mail.smtps.port"
+104                 */
+105                @Override
+106                String propertyNamePort() {
+107                        return "mail.smtps.port";
+108                };
+109
+110                /**
+111                 * @return "mail.smtps.username"
+112                 */
+113                @Override
+114                String propertyNameUsername() {
+115                        return "mail.smtps.username";
+116                };
+117
+118                /**
+119                 * @return "mail.smtps.auth"
+120                 */
+121                @Override
+122                String propertyNameAuthenticate() {
+123                        return "mail.smtps.auth";
+124                };
+125        },
+126        /**
+127         * <strong>NOTE: this code is in untested beta state</strong>
+128         * <p>
+129         * Uses standard ".smtp." property names (like {@link TransportStrategy#SMTP_PLAIN}). Additionally the transport protocol is explicitly
+130         * set to smtp. Finally, the property "mail.smtp.starttls.enable" is being set to true.
+131         */
+132        SMTP_TLS {
+133
+134                /**
+135                 * Here protocol "mail.transport.protocol" is set to "smtp" and the tls property "mail.smtp.starttls.enable" is set to "true".
+136                 * 
+137                 * @see TransportStrategy#SMTP_TLS
+138                 */
+139                @Override
+140                public Properties generateProperties() {
+141                        final Properties props = super.generateProperties();
+142                        props.put("mail.transport.protocol", "smtp");
+143                        props.put("mail.smtp.starttls.enable", "true");
+144                        return props;
+145                }
+146
+147                /**
+148                 * @return "mail.smtp.host"
+149                 */
+150                @Override
+151                String propertyNameHost() {
+152                        return "mail.smtp.host";
+153                };
+154
+155                /**
+156                 * @return "mail.smtp.port"
+157                 */
+158                @Override
+159                String propertyNamePort() {
+160                        return "mail.smtp.port";
+161                };
+162
+163                /**
+164                 * @return "mail.smtp.username"
+165                 */
+166                @Override
+167                String propertyNameUsername() {
+168                        return "mail.smtp.username";
+169                };
+170
+171                /**
+172                 * @return "mail.smtp.auth"
+173                 */
+174                @Override
+175                String propertyNameAuthenticate() {
+176                        return "mail.smtp.auth";
+177                };
+178
+179        };
+180
+181        /**
+182         * Base implementation that simply returns an empty list of properties. Should be overridden by the various strategies where
+183         * appropriate.
+184         * 
+185         * @return An empty <code>Properties</code> instance.
+186         */
+187        public Properties generateProperties() {
+188                return new Properties();
+189        }
+190
+191        abstract String propertyNameHost();
+192
+193        abstract String propertyNamePort();
+194
+195        abstract String propertyNameUsername();
+196
+197        abstract String propertyNameAuthenticate();
+198};
 
 
 
@@ -259,6 +264,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/allclasses-frame.html b/javadoc/users/allclasses-frame.html index e04be2a85..a1ba3c0dc 100644 --- a/javadoc/users/allclasses-frame.html +++ b/javadoc/users/allclasses-frame.html @@ -1,43 +1,26 @@ - - - - - -All Classes (Simple Java Mail API) - - - - - - - - - - - -All Classes -
- - - - - -
Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-MailException -
-Recipient -
-TransportStrategy -
-
- - - + + + + +All Classes (Simple Java Mail API) + + + + + +

All Classes

+
+ +
+ + diff --git a/javadoc/users/allclasses-noframe.html b/javadoc/users/allclasses-noframe.html index 7e3b8d237..3630a356e 100644 --- a/javadoc/users/allclasses-noframe.html +++ b/javadoc/users/allclasses-noframe.html @@ -1,43 +1,26 @@ - - - - - -All Classes (Simple Java Mail API) - - - - - - - - - - - -All Classes -
- - - - - -
Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-MailException -
-Recipient -
-TransportStrategy -
-
- - - + + + + +All Classes (Simple Java Mail API) + + + + + +

All Classes

+
+ +
+ + diff --git a/javadoc/users/constant-values.html b/javadoc/users/constant-values.html index 4f92e5b50..3b2259f1c 100644 --- a/javadoc/users/constant-values.html +++ b/javadoc/users/constant-values.html @@ -1,232 +1,222 @@ - - - - - -Constant Field Values (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Constant Field Values

-
-
-Contents - - - - - - -
-org.codemonkey.*
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
org.codemonkey.simplejavamail.MailException
-protected static final java.lang.StringGENERIC_ERROR"Generic error: %s"
-protected static final java.lang.StringINVALID_ENCODING"Encoding not accepted: %s"
-protected static final java.lang.StringINVALID_RECIPIENT"Invalid TO address: %s"
-protected static final java.lang.StringINVALID_REPLYTO"Invalid REPLY TO address: %s"
-protected static final java.lang.StringINVALID_SENDER"Invalid FROM address: %s"
-protected static final java.lang.StringMISSING_CONTENT"Email is not valid: missing content body"
-protected static final java.lang.StringMISSING_HOST"Can\'t send an email without host"
-protected static final java.lang.StringMISSING_RECIPIENT"Email is not valid: missing recipients"
-protected static final java.lang.StringMISSING_SENDER"Email is not valid: missing sender"
-protected static final java.lang.StringMISSING_SUBJECT"Email is not valid: missing subject"
-protected static final java.lang.StringMISSING_USERNAME"Can\'t have a password without username"
- -

- -

-


- - +
+

Constant Field Values

+

Contents

+ +
+
+ + +

org.codemonkey.*

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/deprecated-list.html b/javadoc/users/deprecated-list.html index 002744795..040940cc7 100644 --- a/javadoc/users/deprecated-list.html +++ b/javadoc/users/deprecated-list.html @@ -1,144 +1,123 @@ - - - - - -Deprecated List (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Deprecated API

-
-
-Contents - -
- - +
+

Deprecated API

+

Contents

+
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/help-doc.html b/javadoc/users/help-doc.html index 948036103..b15fb0893 100644 --- a/javadoc/users/help-doc.html +++ b/javadoc/users/help-doc.html @@ -1,215 +1,224 @@ - - - - - -API Help (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. -
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+ +This help file applies to API documentation generated using the standard doclet.
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/index-all.html b/javadoc/users/index-all.html index 94a352146..849dca010 100644 --- a/javadoc/users/index-all.html +++ b/javadoc/users/index-all.html @@ -1,364 +1,503 @@ - - - - - -Index (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -A B C E G I M O R S T V
-

-A

-
-
addAttachment(String, byte[], String) - -Method in class org.codemonkey.simplejavamail.Email -
Adds an attachment to the email message and generates the necessary DataSource with the given byte data. -
addAttachment(String, DataSource) - -Method in class org.codemonkey.simplejavamail.Email -
Overloaded method which sets an attachment on account of name and DataSource. -
addEmbeddedImage(String, byte[], String) - -Method in class org.codemonkey.simplejavamail.Email -
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte - data. -
addEmbeddedImage(String, DataSource) - -Method in class org.codemonkey.simplejavamail.Email -
Overloaded method which sets an embedded image on account of name and DataSource. -
addHeader(String, Object) - -Method in class org.codemonkey.simplejavamail.Email -
Adds a header to the headers list. -
addRecipient(String, String, Message.RecipientType) - -Method in class org.codemonkey.simplejavamail.Email -
Adds a new Recipient to the list on account of name, address and recipient type (eg. -
-
-

-B

-
-
buildValidEmailPattern(EmailAddressValidationCriteria) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
  -
-
-

-C

-
-
createMailSession(String, Integer, String, String) - -Method in class org.codemonkey.simplejavamail.Mailer -
Actually instantiates and configures the Session instance. -
-
-

-E

-
-
Email - Class in org.codemonkey.simplejavamail
Email message with all necessary data for an effective mailing action, including attachments etc.
Email() - -Constructor for class org.codemonkey.simplejavamail.Email -
Constructor, creates all internal lists. -
EmailAddressValidationCriteria - Class in org.codemonkey.simplejavamail
Defines a set of restriction flags for email address validation.
EmailAddressValidationCriteria(boolean, boolean) - -Constructor for class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
EmailValidationUtil - Class in org.codemonkey.simplejavamail
Validates an email address according to RFC 2822, using regular expressions.
-
-

-G

-
-
generateProperties() - -Method in enum org.codemonkey.simplejavamail.TransportStrategy -
Base implementation that simply returns an empty list of properties. -
GENERIC_ERROR - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
getAddress() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.address; -
getAttachments() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for attachments as unmodifiable list. -
getEmbeddedImages() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for embeddedImages as unmodifiable list. -
getFromRecipient() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for fromRecipient. -
getHeaders() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for headers as unmodifiable map. -
getName() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.name; -
getRecipients() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for recipients as unmodifiable list. -
getReplyToRecipient() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for replyToRecipient. -
getSubject() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for subject. -
getText() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for text. -
getTextHTML() - -Method in class org.codemonkey.simplejavamail.Email -
Bean getter for textHTML. -
getType() - -Method in class org.codemonkey.simplejavamail.Recipient -
Bean getter for Recipient.type; -
-
-

-I

-
-
INVALID_ENCODING - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_RECIPIENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_REPLYTO - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
INVALID_SENDER - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
isAllowDomainLiterals() - -Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
isAllowQuotedIdentifiers() - -Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria -
  -
isValid(String) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
Validates an e-mail with default validation flags that remains true to RFC 2822. -
isValid(String, EmailAddressValidationCriteria) - -Static method in class org.codemonkey.simplejavamail.EmailValidationUtil -
Validates an e-mail with given validation flags. -
-
-

-M

-
-
Mailer - Class in org.codemonkey.simplejavamail
Mailing tool aimed for simplicity, for sending e-mails of any complexity.
Mailer(Session) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Default constructor, stores the given mail session for later use. -
Mailer(String, Integer, String, String, TransportStrategy) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Overloaded constructor which produces a new Session on the fly. -
Mailer(String, Integer, String, String) - -Constructor for class org.codemonkey.simplejavamail.Mailer -
Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol. -
MailException - Exception in org.codemonkey.simplejavamail
This exception is used to communicate errors during the sending of email.
MailException(String) - -Constructor for exception org.codemonkey.simplejavamail.MailException -
  -
MailException(String, MessagingException) - -Constructor for exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_CONTENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_HOST - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_RECIPIENT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_SENDER - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_SUBJECT - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
MISSING_USERNAME - -Static variable in exception org.codemonkey.simplejavamail.MailException -
  -
-
-

-O

-
-
org.codemonkey.simplejavamail - package org.codemonkey.simplejavamail
 
-
-

-R

-
-
Recipient - Class in org.codemonkey.simplejavamail
An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
Recipient(String, String, Message.RecipientType) - -Constructor for class org.codemonkey.simplejavamail.Recipient -
Constructor; initializes this recipient object. -
-
-

-S

-
-
sendMail(Email) - -Method in class org.codemonkey.simplejavamail.Mailer -
Processes an Email instance into a completely configured Message. -
setDebug(boolean) - -Method in class org.codemonkey.simplejavamail.Mailer -
Actually sets Session.setDebug(boolean) so that it generates debug information. -
setEmailAddressValidationCriteria(EmailAddressValidationCriteria) - -Method in class org.codemonkey.simplejavamail.Mailer -
Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance. -
setFromAddress(String, String) - -Method in class org.codemonkey.simplejavamail.Email -
Sets the sender address. -
setReplyToAddress(String, String) - -Method in class org.codemonkey.simplejavamail.Email -
Sets the reply-to address (optional). -
setSubject(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for subject. -
setText(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for text. -
setTextHTML(String) - -Method in class org.codemonkey.simplejavamail.Email -
Bean setters for textHTML. -
-
-

-T

-
-
TransportStrategy - Enum in org.codemonkey.simplejavamail
Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
-
-

-V

-
-
validate(Email) - -Method in class org.codemonkey.simplejavamail.Mailer -
Validates an Email instance. -
valueOf(String) - -Static method in enum org.codemonkey.simplejavamail.TransportStrategy -
Returns the enum constant of this type with the specified name. -
values() - -Static method in enum org.codemonkey.simplejavamail.TransportStrategy -
Returns an array containing the constants of this enum type, in -the order they are declared. -
-
-A B C E G I M O R S T V - +
A B C E F G I M O R S T V  + + +

A

+
+
addAttachment(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds an attachment to the email message and generates the necessary DataSource with the given byte data.
+
+
addAttachment(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email
+
+
Overloaded method which sets an attachment on account of name and DataSource.
+
+
addAttachment(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds an attachment to the email message and generates the necessary DataSource with the given byte data.
+
+
addAttachment(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Overloaded method which sets an attachment on account of name and DataSource.
+
+
addEmbeddedImage(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte + data.
+
+
addEmbeddedImage(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email
+
+
Overloaded method which sets an embedded image on account of name and DataSource.
+
+
addHeader(String, Object) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds a header to the Email.headers list.
+
+
addHeader(String, Object) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a header to the headers list.
+
+
addRecipient(String, String, Message.RecipientType) - Method in class org.codemonkey.simplejavamail.Email
+
+
Adds a new Recipient to the list on account of name, address and recipient type (eg.
+
+
applyProperties(Properties) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Copies all property entries into the Session using Session.getProperties().
+
+
+ + + +

B

+
+
bcc(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.BCC.
+
+
bcc(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.BCC.
+
+
build() - Method in class org.codemonkey.simplejavamail.Email.Builder
+
 
+
Builder() - Constructor for class org.codemonkey.simplejavamail.Email.Builder
+
 
+
buildValidEmailPattern(EmailAddressValidationCriteria) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
 
+
+ + + +

C

+
+
cc(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.CC.
+
+
cc(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.CC.
+
+
createMailSession(String, Integer, String, String) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Actually instantiates and configures the Session instance.
+
+
+ + + +

E

+
+
Email - Class in org.codemonkey.simplejavamail
+
+
Email message with all necessary data for an effective mailing action, including attachments etc.
+
+
Email() - Constructor for class org.codemonkey.simplejavamail.Email
+
+
Constructor, creates all internal lists.
+
+
Email.Builder - Class in org.codemonkey.simplejavamail
+
+
Fluent interface Builder for Emails
+
+
EmailAddressValidationCriteria - Class in org.codemonkey.simplejavamail
+
+
Defines a set of restriction flags for email address validation.
+
+
EmailAddressValidationCriteria(boolean, boolean) - Constructor for class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
EmailValidationUtil - Class in org.codemonkey.simplejavamail
+
+
Validates an email address according to RFC 2822, using regular expressions.
+
+
embedImage(String, byte[], String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds an embedded image (attachment type) to the email message and generates the necessary DataSource with the given byte + data.
+
+
embedImage(String, DataSource) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Overloaded method which sets an embedded image on account of name and DataSource.
+
+
+ + + +

F

+
+
from(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the sender address.
+
+
+ + + +

G

+
+
generateProperties() - Method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Base implementation that simply returns an empty list of properties.
+
+
GENERIC_ERROR - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
getAddress() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.address;
+
+
getAttachments() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.attachments as unmodifiable list.
+
+
getEmbeddedImages() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.embeddedImages as unmodifiable list.
+
+
getFromRecipient() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.fromRecipient.
+
+
getHeaders() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.headers as unmodifiable map.
+
+
getName() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.name;
+
+
getRecipients() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.recipients as unmodifiable list.
+
+
getReplyToRecipient() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.replyToRecipient.
+
+
getSession() - Method in class org.codemonkey.simplejavamail.Mailer
+
+
In case Simple Java Mail falls short somehow, you can get a hold of the internal Session instance to debug or tweak.
+
+
getSubject() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.subject.
+
+
getText() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.text.
+
+
getTextHTML() - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean getter for Email.textHTML.
+
+
getType() - Method in class org.codemonkey.simplejavamail.Recipient
+
+
Bean getter for Recipient.type;
+
+
+ + + +

I

+
+
INVALID_ENCODING - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_RECIPIENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_REPLYTO - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
INVALID_SENDER - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
isAllowDomainLiterals() - Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
isAllowQuotedIdentifiers() - Method in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
 
+
isValid(String) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
+
Validates an e-mail with default validation flags that remains true to RFC 2822.
+
+
isValid(String, EmailAddressValidationCriteria) - Static method in class org.codemonkey.simplejavamail.EmailValidationUtil
+
+
Validates an e-mail with given validation flags.
+
+
+ + + +

M

+
+
Mailer - Class in org.codemonkey.simplejavamail
+
+
Mailing tool aimed for simplicity, for sending e-mails of any complexity.
+
+
Mailer(Session) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Default constructor, stores the given mail session for later use.
+
+
Mailer(String, Integer, String, String, TransportStrategy) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Overloaded constructor which produces a new Session on the fly.
+
+
Mailer(String, Integer, String, String) - Constructor for class org.codemonkey.simplejavamail.Mailer
+
+
Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
+
+
MailException - Exception in org.codemonkey.simplejavamail
+
+
This exception is used to communicate errors during the sending of email.
+
+
MailException(String) - Constructor for exception org.codemonkey.simplejavamail.MailException
+
 
+
MailException(String, MessagingException) - Constructor for exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_CONTENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_HOST - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_RECIPIENT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_SENDER - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_SUBJECT - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
MISSING_USERNAME - Static variable in exception org.codemonkey.simplejavamail.MailException
+
 
+
+ + + +

O

+
+
org.codemonkey.simplejavamail - package org.codemonkey.simplejavamail
+
 
+
+ + + +

R

+
+
Recipient - Class in org.codemonkey.simplejavamail
+
+
An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
+
+
Recipient(String, String, Message.RecipientType) - Constructor for class org.codemonkey.simplejavamail.Recipient
+
+
Constructor; initializes this recipient object.
+
+
replyTo(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the reply-to address (optional).
+
+
RFC_COMPLIANT - Static variable in class org.codemonkey.simplejavamail.EmailAddressValidationCriteria
+
+
Criteria which is most RFC 2822 compliant and allows all compiant address forms, including the more exotic ones.
+
+
+ + + +

S

+
+
sendMail(Email) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Processes an Email instance into a completely configured Message.
+
+
setDebug(boolean) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Actually sets Session.setDebug(boolean) so that it generates debug information.
+
+
setEmailAddressValidationCriteria(EmailAddressValidationCriteria) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Overrides the default email address validation restrictions when validating and sending emails using the current Mailer + instance.
+
+
setFromAddress(String, String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Sets the sender address.
+
+
setReplyToAddress(String, String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Sets the reply-to address (optional).
+
+
setSubject(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.subject.
+
+
setText(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.text.
+
+
setTextHTML(String) - Method in class org.codemonkey.simplejavamail.Email
+
+
Bean setters for Email.textHTML.
+
+
subject(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the subject.
+
+
+ + + +

T

+
+
text(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the text.
+
+
textHTML(String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Sets the textHTML.
+
+
to(String, String) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.TO.
+
+
to(Recipient) - Method in class org.codemonkey.simplejavamail.Email.Builder
+
+
Adds a new Recipient to the list on account of name, address with recipient type Message.RecipientType.TO.
+
+
TransportStrategy - Enum in org.codemonkey.simplejavamail
+
+
Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a + TransportStrategy implementation.
+
+
+ + + +

V

+
+
validate(Email) - Method in class org.codemonkey.simplejavamail.Mailer
+
+
Validates an Email instance.
+
+
valueOf(String) - Static method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Returns the enum constant of this type with the specified name.
+
+
values() - Static method in enum org.codemonkey.simplejavamail.TransportStrategy
+
+
Returns an array containing the constants of this enum type, in +the order they are declared.
+
+
+A B C E F G I M O R S T V 
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/index.html b/javadoc/users/index.html index 05104cfce..36c6bd3b0 100644 --- a/javadoc/users/index.html +++ b/javadoc/users/index.html @@ -1,36 +1,71 @@ - - - - - -Simple Java Mail API - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="org/codemonkey/simplejavamail/package-summary.html">Non-frame version.</A> - - - + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/codemonkey/simplejavamail/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/javadoc/users/org/codemonkey/simplejavamail/Email.Builder.html b/javadoc/users/org/codemonkey/simplejavamail/Email.Builder.html new file mode 100644 index 000000000..fb3511104 --- /dev/null +++ b/javadoc/users/org/codemonkey/simplejavamail/Email.Builder.html @@ -0,0 +1,653 @@ + + + + + +Email.Builder (Simple Java Mail API) + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.codemonkey.simplejavamail
+

Class Email.Builder

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/Email.html b/javadoc/users/org/codemonkey/simplejavamail/Email.html index 2957d2414..af57e1f3e 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/Email.html +++ b/javadoc/users/org/codemonkey/simplejavamail/Email.html @@ -1,693 +1,687 @@ - - - - - -Email (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Email

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Email
-
-
-
-
public class Email
extends java.lang.Object
- - -

-Email message with all necessary data for an effective mailing action, including attachments etc. -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

- +

+
org.codemonkey.simplejavamail
+

Class Email

+
+
+ +
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html b/javadoc/users/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html index c66f5ffe1..47eb150f0 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html +++ b/javadoc/users/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html @@ -1,310 +1,367 @@ - - - - - -EmailAddressValidationCriteria (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class EmailAddressValidationCriteria

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.EmailAddressValidationCriteria
-
-
-
-
public class EmailAddressValidationCriteria
extends java.lang.Object
- - -

-Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to - true. -

- -

-

-
Author:
-
Benny Bottema
-
See Also:
EmailAddressValidationCriteria(boolean, boolean)
-
- -

- +

+
org.codemonkey.simplejavamail
+

Class EmailAddressValidationCriteria

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/EmailValidationUtil.html b/javadoc/users/org/codemonkey/simplejavamail/EmailValidationUtil.html index 91a915e53..ae6462e34 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/EmailValidationUtil.html +++ b/javadoc/users/org/codemonkey/simplejavamail/EmailValidationUtil.html @@ -1,278 +1,301 @@ - - - - - -EmailValidationUtil (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":9,"i1":9,"i2":9}; +var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class EmailValidationUtil

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.EmailValidationUtil
-
-
-
-
public final class EmailValidationUtil
extends java.lang.Object
- - -

-Validates an email address according to RFC 2822, using regular expressions. -

- From the original author:
-

If you use this code, please keep the author information in tact and reference my site at leshazlewood.com. Thanks!
-

- Code sanitized by Benny Bottema (kept validation 100% in tact). -

- -

-

-
Author:
-
Les Hazlewood, Benny Bottema
-
See Also:
EmailAddressValidationCriteria
-
- -

- +

+
org.codemonkey.simplejavamail
+

Class EmailValidationUtil

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/MailException.html b/javadoc/users/org/codemonkey/simplejavamail/MailException.html index f8075f313..946082dee 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/MailException.html +++ b/javadoc/users/org/codemonkey/simplejavamail/MailException.html @@ -1,481 +1,496 @@ - - - - - -MailException (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class MailException

-
-java.lang.Object
-  extended by java.lang.Throwable
-      extended by java.lang.Exception
-          extended by java.lang.RuntimeException
-              extended by org.codemonkey.simplejavamail.MailException
-
-
-
All Implemented Interfaces:
java.io.Serializable
-
-
-
-
public final class MailException
extends java.lang.RuntimeException
- - -

-This exception is used to communicate errors during the sending of email. -

- -

-

-
Author:
-
Benny Bottema
-
See Also:
Serialized Form
-
- -

+

+
org.codemonkey.simplejavamail
+

Class MailException

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/Mailer.html b/javadoc/users/org/codemonkey/simplejavamail/Mailer.html index d6da79987..70f7f25cc 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/Mailer.html +++ b/javadoc/users/org/codemonkey/simplejavamail/Mailer.html @@ -1,480 +1,562 @@ - - - - - -Mailer (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Mailer

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Mailer
-
-
-
-
public class Mailer
extends java.lang.Object
- - -

-Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content, - embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL
-
- This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with Email - instances.
-
- The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some - mainstream client applications such as MS Outlook or Mozilla Thunderbird.
-
- Technically, the resulting email structure is as follows:
- -

- - root
-        - related
-                - alternative
-                        - mail text
-                        - mail html text
-                - embedded images
-        - attachments
- 
- -
- Usage example:
- -
- Email email = new Email();
- email.setFromAddress("lollypop", "lolly.pop@somemail.com");
- email.addRecipient("Sugar Cane", "sugar.cane@candystore.org", RecipientType.TO);
- email.setText("We should meet up!!");
- email.setTextHTML("<b>We should meet up!</b>");
- email.setSubject("Hey");
- new Mailer(preconfiguredMailSession).sendMail(email);
- // or:
- new Mailer("smtp.someserver.com", 25, "username", "password").sendMail(email);
+
+
org.codemonkey.simplejavamail
+

Class Mailer

+
+
+ +
+
    +
  • +
    +
    +
    public class Mailer
    +extends Object
    +
    Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content, + embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL
    +
    + This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with Email + instances.
    +
    + The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some + mainstream client applications such as MS Outlook or Mozilla Thunderbird.
    +
    + Technically, the resulting email structure is as follows:
    + +
    + - root
    +        - related
    +                - alternative
    +                        - mail text
    +                        - mail html text
    +                - embedded images
    +        - attachments
      
    -

    - -

    -

    -
    Author:
    -
    Benny Bottema
    -
    See Also:
    MimeEmailMessageWrapper, -Email
    -
    - -

    - + +
    + Usage example:
    + +

    + Email email = new Email();
    + email.setFromAddress("lollypop", "lolly.pop@somemail.com");
    + email.addRecipient("Sugar Cane", "sugar.cane@candystore.org", RecipientType.TO);
    + email.setText("We should meet up!!");
    + email.setTextHTML("<b>We should meet up!</b>");
    + email.setSubject("Hey");
    + new Mailer(preconfiguredMailSession).sendMail(email);
    + // or:
    + new Mailer("smtp.someserver.com", 25, "username", "password").sendMail(email);
    + 
    +
    +
    Author:
    +
    Benny Bottema
    +
    See Also:
    +
    MimeEmailMessageWrapper, +Email
    +
    +
  • +
+
+
+
    +
  • - - - - - - - - - - - - - - - -
    -Constructor Summary
    Mailer(javax.mail.Session session) - -
    -          Default constructor, stores the given mail session for later use.
    Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password) - -
    -          Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
    Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password, - TransportStrategy transportStrategy) - -
    -          Overloaded constructor which produces a new Session on the fly.
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      Mailer(javax.mail.Session session) +
      Default constructor, stores the given mail session for later use.
      +
      Mailer(String host, + Integer port, + String username, + String password) +
      Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
      +
      Mailer(String host, + Integer port, + String username, + String password, + TransportStrategy transportStrategy) +
      Overloaded constructor which produces a new Session on the fly.
      +
      +
    • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - javax.mail.SessioncreateMailSession(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password) - -
    -          Actually instantiates and configures the Session instance.
    - voidsendMail(Email email) - -
    -          Processes an Email instance into a completely configured Message.
    - voidsetDebug(boolean debug) - -
    -          Actually sets Session.setDebug(boolean) so that it generates debug information.
    - voidsetEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) - -
    -          Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance.
    - booleanvalidate(Email email) - -
    -          Validates an Email instance.
    - - - - - - - -
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    -  -

    - +

    +
  • +
+
+
+
    +
  • - - - - - - -
    -Constructor Detail
    - -

    -Mailer

    -
    -public Mailer(javax.mail.Session session)
    -
    -
    Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are - configured (host, port, authentication and transport protocol settings). -

    - Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain - literals and quoted identifiers (see EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean)). -

    -

    -
    Parameters:
    session - A preconfigured mail Session object with which a Message can be produced.
    -
    -
    - -

    -Mailer

    -
    -public Mailer(java.lang.String host,
    -              java.lang.Integer port,
    -              java.lang.String username,
    -              java.lang.String password,
    -              TransportStrategy transportStrategy)
    -
    -
    Overloaded constructor which produces a new Session on the fly. Use this if you don't have a mail session configured in your - web container, or Spring context etc. -

    - Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain - literals and quoted identifiers (see EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean)). -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null, but only if username is null as well.
    transportStrategy - The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
    -
    -
    - -

    -Mailer

    -
    -public Mailer(java.lang.String host,
    -              java.lang.Integer port,
    -              java.lang.String username,
    -              java.lang.String password)
    -
    -
    Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol. -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null, but only if username is null as well.
    See Also:
    Mailer(String, Integer, String, String, TransportStrategy)
    -
    - +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        Mailer

        +
        public Mailer(javax.mail.Session session)
        +
        Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are + configured (host, port, authentication and transport protocol settings). +

        + Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the + smtp server instead.

        +
        +
        Parameters:
        +
        session - A preconfigured mail Session object with which a Message can be produced.
        +
        +
      • +
      + + + +
        +
      • +

        Mailer

        +
        public Mailer(String host,
        +              Integer port,
        +              String username,
        +              String password,
        +              TransportStrategy transportStrategy)
        +
        Overloaded constructor which produces a new Session on the fly. Use this if you don't have a mail session configured in your + web container, or Spring context etc. +

        + Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the + smtp server instead.

        +
        +
        Parameters:
        +
        host - The address URL of the SMTP server to be used.
        +
        port - The port of the SMTP server.
        +
        username - An optional username, may be null.
        +
        password - An optional password, may be null, but only if username is null as well.
        +
        transportStrategy - The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
        +
        +
      • +
      + + + +
        +
      • +

        Mailer

        +
        public Mailer(String host,
        +              Integer port,
        +              String username,
        +              String password)
        +
        Overloaded constructor which produces a new Session on the fly, using default vanilla SMTP transport protocol.
        +
        +
        Parameters:
        +
        host - The address URL of the SMTP server to be used.
        +
        port - The port of the SMTP server.
        +
        username - An optional username, may be null.
        +
        password - An optional password, may be null, but only if username is null as well.
        +
        See Also:
        +
        Mailer(String, Integer, String, String, TransportStrategy)
        +
        +
      • +
      +
    • +
    - - - - - - -
    -Method Detail
    - -

    -createMailSession

    -
    -public javax.mail.Session createMailSession(java.lang.String host,
    -                                            java.lang.Integer port,
    -                                            java.lang.String username,
    -                                            java.lang.String password)
    -
    -
    Actually instantiates and configures the Session instance. Delegates resolving transport protocol specific properties to the - transportStrategy in two ways: -
      -
    1. request an initial property list which the strategy may pre-populate
    2. -
    3. by requesting the property names according to the respective transport protocol it handles (for the host property for example it - would be "mail.smtp.host" for SMTP and "mail.smtps.host" for SMTPS)
    4. -
    -

    -

    -
    Parameters:
    host - The address URL of the SMTP server to be used.
    port - The port of the SMTP server.
    username - An optional username, may be null.
    password - An optional password, may be null. -
    Returns:
    A fully configured Session instance complete with transport protocol settings.
    See Also:
    TransportStrategy.generateProperties(), -TransportStrategy.propertyNameHost(), -TransportStrategy.propertyNamePort(), -TransportStrategy.propertyNameUsername(), -TransportStrategy.propertyNameAuthenticate()
    -
    -
    -
    - -

    -setDebug

    -
    -public void setDebug(boolean debug)
    -
    -
    Actually sets Session.setDebug(boolean) so that it generates debug information. -

    -

    -
    Parameters:
    debug - Flag to indicate debug mode yes/no.
    -
    -
    -
    - -

    -sendMail

    -
    -public final void sendMail(Email email)
    -                    throws MailException
    -
    -
    Processes an Email instance into a completely configured Message. -

    - Sends the Sun JavaMail Message object using Session.getTransport(). It will call Service.connect() assuming - all connection details have been configured in the provided Session instance. -

    - Performs a call to Message.saveChanges() as the Sun JavaMail API indicates it is needed to configure the message headers and - providing a message id. -

    -

    -
    Parameters:
    email - The information for the email to be sent. -
    Throws: -
    MailException - Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending - etc.
    See Also:
    validate(Email), -prepareMessage(Email, MimeEmailMessageWrapper), -setRecipients(Email, Message), -setTexts(Email, MimeMultipart), -setEmbeddedImages(Email, MimeMultipart), -setAttachments(Email, MimeMultipart)
    -
    -
    -
    - -

    -validate

    -
    -public boolean validate(Email email)
    -                 throws MailException
    -
    -
    Validates an Email instance. Validation fails if the subject is missing, content is missing, or no recipients are defined. -

    -

    -
    Parameters:
    email - The email that needs to be configured correctly. -
    Returns:
    Always true (throws a MailException exception if validation fails). -
    Throws: -
    MailException - Is being thrown in any of the above causes.
    See Also:
    EmailValidationUtil
    -
    -
    -
    - -

    -setEmailAddressValidationCriteria

    -
    -public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria)
    -
    -
    Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance. -

    -

    -
    Parameters:
    emailAddressValidationCriteria - Refer to - EmailAddressValidationCriteria.EmailAddressValidationCriteria(boolean, boolean).
    -
    -
    + +
  • +
+
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/Recipient.html b/javadoc/users/org/codemonkey/simplejavamail/Recipient.html index 267ae1bde..c1db239c0 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/Recipient.html +++ b/javadoc/users/org/codemonkey/simplejavamail/Recipient.html @@ -1,310 +1,325 @@ - - - - - -Recipient (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":10,"i2":10}; +var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Class Recipient

-
-java.lang.Object
-  extended by org.codemonkey.simplejavamail.Recipient
-
-
-
-
public final class Recipient
extends java.lang.Object
-
- -

-An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC). -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

- +

+
org.codemonkey.simplejavamail
+

Class Recipient

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/TransportStrategy.html b/javadoc/users/org/codemonkey/simplejavamail/TransportStrategy.html index 9784c4be3..9637c61f7 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/TransportStrategy.html +++ b/javadoc/users/org/codemonkey/simplejavamail/TransportStrategy.html @@ -1,393 +1,405 @@ - - - - - -TransportStrategy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> +var methods = {"i0":10,"i1":9,"i2":9}; +var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; +var altColor = "altColor"; +var rowColor = "rowColor"; +var tableTab = "tableTab"; +var activeTableTab = "activeTableTab"; + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.codemonkey.simplejavamail -
-Enum TransportStrategy

-
-java.lang.Object
-  extended by java.lang.Enum<TransportStrategy>
-      extended by org.codemonkey.simplejavamail.TransportStrategy
-
-
-
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<TransportStrategy>
-
-
-
-
public enum TransportStrategy
extends java.lang.Enum<TransportStrategy>
- - -

-Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation. -

- -

-

-
Author:
-
Benny Bottema
-
-
- -

+

+
org.codemonkey.simplejavamail
+

Enum TransportStrategy

+
+
+ +
+ +
+
+ +
+
+ +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.Builder.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.Builder.html new file mode 100644 index 000000000..fbe5d7861 --- /dev/null +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.Builder.html @@ -0,0 +1,238 @@ + + + + + +Uses of Class org.codemonkey.simplejavamail.Email.Builder (Simple Java Mail API) + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Uses of Class
org.codemonkey.simplejavamail.Email.Builder

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.html index 5b8becef8..4f6b31800 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/Email.html @@ -1,173 +1,169 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Email (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Email

-
- - - - - -
-Uses of Email in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type Email
- voidMailer.sendMail(Email email) - -
-          Processes an Email instance into a completely configured Message.
- booleanMailer.validate(Email email) - -
-          Validates an Email instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Email

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html index bda9072d3..34400b409 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailAddressValidationCriteria.html @@ -1,183 +1,177 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.EmailAddressValidationCriteria (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.EmailAddressValidationCriteria

-
- - - - - -
-Uses of EmailAddressValidationCriteria in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail with parameters of type EmailAddressValidationCriteria
-protected static java.util.regex.PatternEmailValidationUtil.buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) - -
-           
-static booleanEmailValidationUtil.isValid(java.lang.String email, - EmailAddressValidationCriteria emailAddressValidationCriteria) - -
-          Validates an e-mail with given validation flags.
- voidMailer.setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) - -
-          Overrides the default email address validation restrictions when validating and sending emails using the current Mailer - instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.EmailAddressValidationCriteria

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html index 306752b9e..f589977e9 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/EmailValidationUtil.html @@ -1,142 +1,123 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.EmailValidationUtil (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.EmailValidationUtil

-
-No usage of org.codemonkey.simplejavamail.EmailValidationUtil -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.EmailValidationUtil

+
+
No usage of org.codemonkey.simplejavamail.EmailValidationUtil
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/MailException.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/MailException.html index 51d6ab44b..9276566c1 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/MailException.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/MailException.html @@ -1,173 +1,156 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.MailException (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.MailException

-
- - - - - -
-Uses of MailException in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that throw MailException
- voidMailer.sendMail(Email email) - -
-          Processes an Email instance into a completely configured Message.
- booleanMailer.validate(Email email) - -
-          Validates an Email instance.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.MailException

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/Mailer.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/Mailer.html index feb597b97..49cb82290 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/Mailer.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/Mailer.html @@ -1,142 +1,123 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Mailer (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Mailer

-
-No usage of org.codemonkey.simplejavamail.Mailer -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Mailer

+
+
No usage of org.codemonkey.simplejavamail.Mailer
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/Recipient.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/Recipient.html index 67e961177..0e6de4f3d 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/Recipient.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/Recipient.html @@ -1,189 +1,198 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.Recipient (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.Recipient

-
- - - - - -
-Uses of Recipient in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return Recipient
- RecipientEmail.getFromRecipient() - -
-          Bean getter for Email.fromRecipient.
- RecipientEmail.getReplyToRecipient() - -
-          Bean getter for Email.replyToRecipient.
-  -

- - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return types with arguments of type Recipient
- java.util.List<Recipient>Email.getRecipients() - -
-          Bean getter for Email.recipients as unmodifiable list.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.Recipient

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/class-use/TransportStrategy.html b/javadoc/users/org/codemonkey/simplejavamail/class-use/TransportStrategy.html index 33cc93d45..ba8b982fa 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/class-use/TransportStrategy.html +++ b/javadoc/users/org/codemonkey/simplejavamail/class-use/TransportStrategy.html @@ -1,192 +1,174 @@ - - - - - -Uses of Class org.codemonkey.simplejavamail.TransportStrategy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Class
org.codemonkey.simplejavamail.TransportStrategy

-
- - - - - -
-Uses of TransportStrategy in org.codemonkey.simplejavamail
-  -

- - - - - - - - - - - - - -
Methods in org.codemonkey.simplejavamail that return TransportStrategy
-static TransportStrategyTransportStrategy.valueOf(java.lang.String name) - -
-          Returns the enum constant of this type with the specified name.
-static TransportStrategy[]TransportStrategy.values() - -
-          Returns an array containing the constants of this enum type, in -the order they are declared.
-  -

- - - - - - - - -
Constructors in org.codemonkey.simplejavamail with parameters of type TransportStrategy
Mailer(java.lang.String host, - java.lang.Integer port, - java.lang.String username, - java.lang.String password, - TransportStrategy transportStrategy) - -
-          Overloaded constructor which produces a new Session on the fly.
-  -

-


- - +
+

Uses of Class
org.codemonkey.simplejavamail.TransportStrategy

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/package-frame.html b/javadoc/users/org/codemonkey/simplejavamail/package-frame.html index 831fe8d55..f7fe23476 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/package-frame.html +++ b/javadoc/users/org/codemonkey/simplejavamail/package-frame.html @@ -1,62 +1,33 @@ - - - - - -org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - - - - - -org.codemonkey.simplejavamail - - - - -
-Classes  - -
-Email -
-EmailAddressValidationCriteria -
-EmailValidationUtil -
-Mailer -
-Recipient
- - - - - - -
-Enums  - -
-TransportStrategy
- - - - - - -
-Exceptions  - -
-MailException
- - - - + + + + +org.codemonkey.simplejavamail (Simple Java Mail API) + + + + + +

org.codemonkey.simplejavamail

+
+

Classes

+ +

Enums

+ +

Exceptions

+ +
+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/package-summary.html b/javadoc/users/org/codemonkey/simplejavamail/package-summary.html index 5904a2e1c..8c6a310b3 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/package-summary.html +++ b/javadoc/users/org/codemonkey/simplejavamail/package-summary.html @@ -1,200 +1,208 @@ - - - - - -org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-

-Package org.codemonkey.simplejavamail -

- - - - - - - - - - - - - - - - - - - - - - - - - -
-Class Summary
EmailEmail message with all necessary data for an effective mailing action, including attachments etc.
EmailAddressValidationCriteriaDefines a set of restriction flags for email address validation.
EmailValidationUtilValidates an email address according to RFC 2822, using regular expressions.
MailerMailing tool aimed for simplicity, for sending e-mails of any complexity.
RecipientAn immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
-  - -

- - - - - - - - - -
-Enum Summary
TransportStrategyDefines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
-  - -

- - - - - - - - - -
-Exception Summary
MailExceptionThis exception is used to communicate errors during the sending of email.
-  - -

-

-
-
- - +
+

Package org.codemonkey.simplejavamail

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/package-tree.html b/javadoc/users/org/codemonkey/simplejavamail/package-tree.html index 43fb5dd42..96d6328b5 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/package-tree.html +++ b/javadoc/users/org/codemonkey/simplejavamail/package-tree.html @@ -1,165 +1,162 @@ - - - - - -org.codemonkey.simplejavamail Class Hierarchy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For Package org.codemonkey.simplejavamail -

-
-

-Class Hierarchy -

- -

-Enum Hierarchy -

- -
- - +
+

Hierarchy For Package org.codemonkey.simplejavamail

+
+
+

Class Hierarchy

+ +

Enum Hierarchy

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/org/codemonkey/simplejavamail/package-use.html b/javadoc/users/org/codemonkey/simplejavamail/package-use.html index f1fc96dd1..0f2e86db2 100644 --- a/javadoc/users/org/codemonkey/simplejavamail/package-use.html +++ b/javadoc/users/org/codemonkey/simplejavamail/package-use.html @@ -1,180 +1,169 @@ - - - - - -Uses of Package org.codemonkey.simplejavamail (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Uses of Package
org.codemonkey.simplejavamail

-
- - - - - - - - - - - - - - - - - - - - -
-Classes in org.codemonkey.simplejavamail used by org.codemonkey.simplejavamail
Email - -
-          Email message with all necessary data for an effective mailing action, including attachments etc.
EmailAddressValidationCriteria - -
-          Defines a set of restriction flags for email address validation.
MailException - -
-          This exception is used to communicate errors during the sending of email.
Recipient - -
-          An immutable recipient object, with a name, emailadres and recipient type (eg Message.RecipientType.BCC).
TransportStrategy - -
-          Defines the various types of transport protocols and implements respective properties so that a Session may be configured using a - TransportStrategy implementation.
-  -

-


- - +
+

Uses of Package
org.codemonkey.simplejavamail

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/overview-tree.html b/javadoc/users/overview-tree.html index 52d2c56f6..a0e2bb022 100644 --- a/javadoc/users/overview-tree.html +++ b/javadoc/users/overview-tree.html @@ -1,167 +1,166 @@ - - - - - -Class Hierarchy (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
org.codemonkey.simplejavamail
-
-

-Class Hierarchy -

- -

-Enum Hierarchy -

- -
- - +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +

Enum Hierarchy

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/script.js b/javadoc/users/script.js new file mode 100644 index 000000000..b34635693 --- /dev/null +++ b/javadoc/users/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/javadoc/users/serialized-form.html b/javadoc/users/serialized-form.html index 66cd65618..e2e39a960 100644 --- a/javadoc/users/serialized-form.html +++ b/javadoc/users/serialized-form.html @@ -1,161 +1,136 @@ - - - - - -Serialized Form (Simple Java Mail API) - - - - - - - + + + - - - - - -
- - + catch(err) { + } +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Serialized Form

-
-
- - - - - -
-Package org.codemonkey.simplejavamail
- -

- - - - - -
-Class org.codemonkey.simplejavamail.MailException extends java.lang.RuntimeException implements Serializable
- -

- -

-


- - +
+

Serialized Form

+
+
+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
-Copyright © 2009 under Apache v2 license. - - +

Copyright © 2009 under Apache v2 license.

+ + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.Builder.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.Builder.html new file mode 100644 index 000000000..c273d9ad0 --- /dev/null +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.Builder.html @@ -0,0 +1,599 @@ + + + +Source code + + + +
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.ArrayList;
+004import java.util.Collections;
+005import java.util.HashMap;
+006import java.util.List;
+007import java.util.Map;
+008
+009import javax.activation.DataSource;
+010import javax.mail.Message.RecipientType;
+011import javax.mail.util.ByteArrayDataSource;
+012
+013/**
+014 * Email message with all necessary data for an effective mailing action, including attachments etc.
+015 *
+016 * @author Benny Bottema
+017 */
+018public class Email {
+019        /**
+020         * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
+021         */
+022        private Recipient fromRecipient;
+023        /**
+024         * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+025         */
+026        private Recipient replyToRecipient;
+027
+028        /**
+029         * The email message body in plain text.
+030         */
+031        private String text;
+032
+033        /**
+034         * The email message body in html.
+035         */
+036        private String textHTML;
+037
+038        /**
+039         * The subject of the email message.
+040         */
+041        private String subject;
+042
+043        /**
+044         * List of {@link Recipient}.
+045         */
+046        private final List<Recipient> recipients;
+047
+048        /**
+049         * List of {@link AttachmentResource}.
+050         */
+051        private final List<AttachmentResource> embeddedImages;
+052
+053        /**
+054         * List of {@link AttachmentResource}.
+055         */
+056        private final List<AttachmentResource> attachments;
+057
+058        /**
+059         * Map of header name and values, such as <code>X-Priority</code> etc.
+060         */
+061        private final Map<String, String> headers;
+062
+063        /**
+064         * Constructor, creates all internal lists.
+065         */
+066        public Email() {
+067                recipients = new ArrayList<Recipient>();
+068                embeddedImages = new ArrayList<AttachmentResource>();
+069                attachments = new ArrayList<AttachmentResource>();
+070                headers = new HashMap<String, String>();
+071        }
+072
+073        /**
+074         * Sets the sender address.
+075         *
+076         * @param name The sender's name.
+077         * @param fromAddress The sender's email address.
+078         */
+079        public void setFromAddress(final String name, final String fromAddress) {
+080                fromRecipient = new Recipient(name, fromAddress, null);
+081        }
+082
+083        /**
+084         * Sets the reply-to address (optional).
+085         *
+086         * @param name The replied-to-receiver name.
+087         * @param replyToAddress The replied-to-receiver email address.
+088         */
+089        public void setReplyToAddress(final String name, final String replyToAddress) {
+090                replyToRecipient = new Recipient(name, replyToAddress, null);
+091        }
+092
+093        /**
+094         * Bean setters for {@link #subject}.
+095         */
+096        public void setSubject(final String subject) {
+097                this.subject = subject;
+098        }
+099
+100        /**
+101         * Bean setters for {@link #text}.
+102         */
+103        public void setText(final String text) {
+104                this.text = text;
+105        }
+106
+107        /**
+108         * Bean setters for {@link #textHTML}.
+109         */
+110        public void setTextHTML(final String textHTML) {
+111                this.textHTML = textHTML;
+112        }
+113
+114        /**
+115         * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
+116         *
+117         * @param name The name of the recipient.
+118         * @param address The emailadres of the recipient.
+119         * @param type The type of receiver (eg. {@link RecipientType#CC}).
+120         * @see #recipients
+121         * @see Recipient
+122         * @see RecipientType
+123         */
+124        public void addRecipient(final String name, final String address, final RecipientType type) {
+125                recipients.add(new Recipient(name, address, type));
+126        }
+127
+128        /**
+129         * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+130         * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+131         * {@link ByteArrayDataSource}.
+132         *
+133         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+134         * @param data The byte data of the image to be embedded.
+135         * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+136         * @see ByteArrayDataSource
+137         * @see #addEmbeddedImage(String, DataSource)
+138         */
+139        public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
+140                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+141                dataSource.setName(name);
+142                addEmbeddedImage(name, dataSource);
+143        }
+144
+145        /**
+146         * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+147         *
+148         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+149         * @param imagedata The image data.
+150         */
+151        public void addEmbeddedImage(final String name, final DataSource imagedata) {
+152                embeddedImages.add(new AttachmentResource(name, imagedata));
+153        }
+154
+155        /**
+156         * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+157         * <p>
+158         * example: <code>email.addHeader("X-Priority", 2)</code>
+159         *
+160         * @param name The name of the header.
+161         * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+162         */
+163        public void addHeader(final String name, final Object value) {
+164                headers.put(name, String.valueOf(value));
+165        }
+166
+167        /**
+168         * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+169         * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+170         *
+171         * @param name The name of the extension (eg. filename including extension).
+172         * @param data The byte data of the attachment.
+173         * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+174         * @see ByteArrayDataSource
+175         * @see #addAttachment(String, DataSource)
+176         */
+177        public void addAttachment(final String name, final byte[] data, final String mimetype) {
+178                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+179                dataSource.setName(name);
+180                addAttachment(name, dataSource);
+181        }
+182
+183        /**
+184         * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+185         *
+186         * @param name The name of the attachment (eg. 'filename.ext').
+187         * @param filedata The attachment data.
+188         */
+189        public void addAttachment(final String name, final DataSource filedata) {
+190                attachments.add(new AttachmentResource(name, filedata));
+191        }
+192
+193        /**
+194         * Bean getter for {@link #fromRecipient}.
+195         */
+196        public Recipient getFromRecipient() {
+197                return fromRecipient;
+198        }
+199
+200        /**
+201         * Bean getter for {@link #replyToRecipient}.
+202         */
+203        public Recipient getReplyToRecipient() {
+204                return replyToRecipient;
+205        }
+206
+207        /**
+208         * Bean getter for {@link #subject}.
+209         */
+210        public String getSubject() {
+211                return subject;
+212        }
+213
+214        /**
+215         * Bean getter for {@link #text}.
+216         */
+217        public String getText() {
+218                return text;
+219        }
+220
+221        /**
+222         * Bean getter for {@link #textHTML}.
+223         */
+224        public String getTextHTML() {
+225                return textHTML;
+226        }
+227
+228        /**
+229         * Bean getter for {@link #attachments} as unmodifiable list.
+230         */
+231        public List<AttachmentResource> getAttachments() {
+232                return Collections.unmodifiableList(attachments);
+233        }
+234
+235        /**
+236         * Bean getter for {@link #embeddedImages} as unmodifiable list.
+237         */
+238        public List<AttachmentResource> getEmbeddedImages() {
+239                return Collections.unmodifiableList(embeddedImages);
+240        }
+241
+242        /**
+243         * Bean getter for {@link #recipients} as unmodifiable list.
+244         */
+245        public List<Recipient> getRecipients() {
+246                return Collections.unmodifiableList(recipients);
+247        }
+248
+249        /**
+250         * Bean getter for {@link #headers} as unmodifiable map.
+251         */
+252        public Map<String, String> getHeaders() {
+253                return Collections.unmodifiableMap(headers);
+254        }
+255
+256        /**
+257         * Fluent interface Builder for Emails
+258         * @author Jared Stewart
+259         */
+260        public static class Builder {
+261                private Recipient fromRecipient;
+262                /**
+263                 * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+264                 */
+265                private Recipient replyToRecipient;
+266
+267                /**
+268                 * The email message body in plain text.
+269                 */
+270                private String text;
+271
+272                /**
+273                 * The email message body in html.
+274                 */
+275                private String textHTML;
+276
+277                /**
+278                 * The subject of the email message.
+279                 */
+280                private String subject;
+281
+282                /**
+283                 * List of {@link Recipient}.
+284                 */
+285                private final List<Recipient> recipients;
+286
+287                /**
+288                 * List of {@link AttachmentResource}.
+289                 */
+290                private final List<AttachmentResource> embeddedImages;
+291
+292                /**
+293                 * List of {@link AttachmentResource}.
+294                 */
+295                private final List<AttachmentResource> attachments;
+296
+297                /**
+298                 * Map of header name and values, such as <code>X-Priority</code> etc.
+299                 */
+300                private final Map<String, String> headers;
+301
+302                private Email email;
+303
+304                public Builder() {
+305                        recipients = new ArrayList<Recipient>();
+306                        embeddedImages = new ArrayList<AttachmentResource>();
+307                        attachments = new ArrayList<AttachmentResource>();
+308                        headers = new HashMap<String, String>();
+309                }
+310
+311                /**
+312                 *
+313                 */
+314                public Email build() {
+315                        return new Email(this);
+316                }
+317
+318                /**
+319                 * Sets the sender address.
+320                 *
+321                 * @param name The sender's name.
+322                 * @param fromAddress The sender's email address.
+323                 */
+324                public Builder from(final String name, final String fromAddress){
+325                        this.fromRecipient = new Recipient(name, fromAddress, null);
+326                        return this;
+327                }
+328
+329                /**
+330                 * Sets the reply-to address (optional).
+331                 *
+332                 * @param name The replied-to-receiver name.
+333                 * @param replyToAddress The replied-to-receiver email address.
+334                 */
+335                public Builder replyTo(final String name, final String replyToAddress) {
+336                        this.replyToRecipient = new Recipient(name, replyToAddress, null);
+337                        return this;
+338                }
+339
+340
+341                /**
+342                 * Sets the {@link #subject}.
+343                 */
+344                public Builder subject(final String subject) {
+345                        this.subject = subject;
+346                        return this;
+347                }
+348
+349                /**
+350                 * Sets the {@link #text}.
+351                 */
+352                public Builder text(final String text) {
+353                        this.text = text;
+354                        return this;
+355                }
+356
+357                /**
+358                 * Sets the {@link #textHTML}.
+359                 */
+360                public Builder textHTML(final String textHTML) {
+361                        this.textHTML = textHTML;
+362                        return this;
+363                }
+364
+365                /**
+366                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+367                 *
+368                 * @param name The name of the recipient.
+369                 * @param address The emailaddress of the recipient.
+370                 * @see #recipients
+371                 * @see Recipient
+372                 */
+373                public Builder to(final String name, final String address) {
+374                        recipients.add(new Recipient(name, address, RecipientType.TO));
+375                        return this;
+376                }
+377
+378                /**
+379                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+380                 *
+381                 * @param recipient The recipent whose name and address to use
+382                 * @see #recipients
+383                 * @see Recipient
+384                 */
+385                public Builder to(final Recipient recipient) {
+386                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.TO));
+387                        return this;
+388                }
+389
+390
+391
+392                /**
+393                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+394                 *
+395                 * @param name The name of the recipient.
+396                 * @param address The emailaddress of the recipient.
+397                 * @see #recipients
+398                 * @see Recipient
+399                 */
+400                public Builder cc(final String name, final String address) {
+401                        recipients.add(new Recipient(name, address, RecipientType.CC));
+402                        return this;
+403                }
+404
+405                /**
+406                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+407                 *
+408                 * @param recipient The recipent whose name and address to use
+409                 * @see #recipients
+410                 * @see Recipient
+411                 */
+412                public Builder cc(final Recipient recipient) {
+413                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.CC));
+414                        return this;
+415                }
+416
+417                /**
+418                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+419                 *
+420                 * @param name The name of the recipient.
+421                 * @param address The emailaddress of the recipient.
+422                 * @see #recipients
+423                 * @see Recipient
+424                 */
+425                public Builder bcc(final String name, final String address) {
+426                        recipients.add(new Recipient(name, address, RecipientType.BCC));
+427                        return this;
+428                }
+429
+430                /**
+431                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+432                 *
+433                 * @param recipient The recipent whose name and address to use
+434                 * @see #recipients
+435                 * @see Recipient
+436                 */
+437                public Builder bcc(final Recipient recipient) {
+438                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.BCC));
+439                        return this;
+440                }
+441
+442                /**
+443                 * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+444                 * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+445                 * {@link ByteArrayDataSource}.
+446                 *
+447                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+448                 * @param data The byte data of the image to be embedded.
+449                 * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+450                 * @see ByteArrayDataSource
+451                 * @see #addEmbeddedImage(String, DataSource)
+452                 */
+453                public Builder embedImage(final String name, final byte[] data, final String mimetype) {
+454                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+455                        dataSource.setName(name);
+456                        return embedImage(name, dataSource);
+457                }
+458
+459                /**
+460                 * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+461                 *
+462                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+463                 * @param imagedata The image data.
+464                 */
+465                public Builder embedImage(final String name, final DataSource imagedata) {
+466                        embeddedImages.add(new AttachmentResource(name, imagedata));
+467                        return this;
+468                }
+469
+470                /**
+471                 * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+472                 * <p>
+473                 * example: <code>email.addHeader("X-Priority", 2)</code>
+474                 *
+475                 * @param name The name of the header.
+476                 * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+477                 */
+478                public Builder addHeader(final String name, final Object value) {
+479                        headers.put(name, String.valueOf(value));
+480                        return this;
+481                }
+482
+483                /**
+484                 * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+485                 * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+486                 *
+487                 * @param name The name of the extension (eg. filename including extension).
+488                 * @param data The byte data of the attachment.
+489                 * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+490                 * @see ByteArrayDataSource
+491                 * @see #addAttachment(String, DataSource)
+492                 */
+493                public void addAttachment(final String name, final byte[] data, final String mimetype) {
+494                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+495                        dataSource.setName(name);
+496                        addAttachment(name, dataSource);
+497                }
+498
+499                /**
+500                 * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+501                 *
+502                 * @param name The name of the attachment (eg. 'filename.ext').
+503                 * @param filedata The attachment data.
+504                 */
+505                public void addAttachment(final String name, final DataSource filedata) {
+506                        attachments.add(new AttachmentResource(name, filedata));
+507                }
+508
+509        }
+510
+511        /**
+512         * Constructor for the Builder class
+513         * @param builder The builder from which to create the email.
+514         */
+515        private Email(Builder builder) {
+516                recipients = builder.recipients;
+517                embeddedImages = builder.embeddedImages;
+518                attachments = builder.attachments;
+519                headers = builder.headers;
+520
+521                fromRecipient = builder.fromRecipient;
+522                replyToRecipient = builder.replyToRecipient;
+523                text = builder.text;
+524                textHTML = builder.textHTML;
+525                subject = builder.subject;
+526        }
+527}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.html index 179dfa8e3..be488641e 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/Email.html @@ -1,261 +1,538 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.util.ArrayList;
-004    import java.util.Collections;
-005    import java.util.HashMap;
-006    import java.util.List;
-007    import java.util.Map;
-008    
-009    import javax.activation.DataSource;
-010    import javax.mail.Message.RecipientType;
-011    import javax.mail.util.ByteArrayDataSource;
-012    
-013    /**
-014     * Email message with all necessary data for an effective mailing action, including attachments etc.
-015     * 
-016     * @author Benny Bottema
-017     */
-018    public class Email {
-019            /**
-020             * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
-021             */
-022            private Recipient fromRecipient;
-023            /**
-024             * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
-025             */
-026            private Recipient replyToRecipient;
-027    
-028            /**
-029             * The email message body in plain text.
-030             */
-031            private String text;
-032    
-033            /**
-034             * The email message body in html.
-035             */
-036            private String textHTML;
-037    
-038            /**
-039             * The subject of the email message.
-040             */
-041            private String subject;
-042    
-043            /**
-044             * List of {@link Recipient}.
-045             */
-046            private final List<Recipient> recipients;
-047    
-048            /**
-049             * List of {@link AttachmentResource}.
-050             */
-051            private final List<AttachmentResource> embeddedImages;
-052    
-053            /**
-054             * List of {@link AttachmentResource}.
-055             */
-056            private final List<AttachmentResource> attachments;
-057    
-058            /**
-059             * Map of header name and values, such as <code>X-Priority</code> etc.
-060             */
-061            private final Map<String, String> headers;
-062    
-063            /**
-064             * Constructor, creates all internal lists.
-065             */
-066            public Email() {
-067                    recipients = new ArrayList<Recipient>();
-068                    embeddedImages = new ArrayList<AttachmentResource>();
-069                    attachments = new ArrayList<AttachmentResource>();
-070                    headers = new HashMap<String, String>();
-071            }
-072    
-073            /**
-074             * Sets the sender address.
-075             * 
-076             * @param name The sender's name.
-077             * @param fromAddress The sender's email address.
-078             */
-079            public void setFromAddress(final String name, final String fromAddress) {
-080                    fromRecipient = new Recipient(name, fromAddress, null);
-081            }
-082    
-083            /**
-084             * Sets the reply-to address (optional).
-085             * 
-086             * @param name The replied-to-receiver name.
-087             * @param replyToAddress The replied-to-receiver email address.
-088             */
-089            public void setReplyToAddress(final String name, final String replyToAddress) {
-090                    replyToRecipient = new Recipient(name, replyToAddress, null);
-091            }
-092    
-093            /**
-094             * Bean setters for {@link #subject}.
-095             */
-096            public void setSubject(final String subject) {
-097                    this.subject = subject;
-098            }
-099    
-100            /**
-101             * Bean setters for {@link #text}.
-102             */
-103            public void setText(final String text) {
-104                    this.text = text;
-105            }
-106    
-107            /**
-108             * Bean setters for {@link #textHTML}.
-109             */
-110            public void setTextHTML(final String textHTML) {
-111                    this.textHTML = textHTML;
-112            }
-113    
-114            /**
-115             * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
-116             * 
-117             * @param name The name of the recipient.
-118             * @param address The emailadres of the recipient.
-119             * @param type The type of receiver (eg. {@link RecipientType#CC}).
-120             * @see #recipients
-121             * @see Recipient
-122             * @see RecipientType
-123             */
-124            public void addRecipient(final String name, final String address, final RecipientType type) {
-125                    recipients.add(new Recipient(name, address, type));
-126            }
-127    
-128            /**
-129             * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
-130             * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
-131             * {@link ByteArrayDataSource}.
-132             * 
-133             * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
-134             * @param data The byte data of the image to be embedded.
-135             * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
-136             * @see ByteArrayDataSource
-137             * @see #addEmbeddedImage(String, DataSource)
-138             */
-139            public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
-140                    final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
-141                    dataSource.setName(name);
-142                    addEmbeddedImage(name, dataSource);
-143            }
-144    
-145            /**
-146             * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
-147             * 
-148             * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
-149             * @param imagedata The image data.
-150             */
-151            public void addEmbeddedImage(final String name, final DataSource imagedata) {
-152                    embeddedImages.add(new AttachmentResource(name, imagedata));
-153            }
-154    
-155            /**
-156             * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
-157             * <p>
-158             * example: <code>email.addHeader("X-Priority", 2)</code>
-159             * 
-160             * @param name The name of the header.
-161             * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
-162             */
-163            public void addHeader(final String name, final Object value) {
-164                    headers.put(name, String.valueOf(value));
-165            }
-166    
-167            /**
-168             * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
-169             * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
-170             * 
-171             * @param name The name of the extension (eg. filename including extension).
-172             * @param data The byte data of the attachment.
-173             * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
-174             * @see ByteArrayDataSource
-175             * @see #addAttachment(String, DataSource)
-176             */
-177            public void addAttachment(final String name, final byte[] data, final String mimetype) {
-178                    final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
-179                    dataSource.setName(name);
-180                    addAttachment(name, dataSource);
-181            }
-182    
-183            /**
-184             * Overloaded method which sets an attachment on account of name and {@link DataSource}.
-185             * 
-186             * @param name The name of the attachment (eg. 'filename.ext').
-187             * @param filedata The attachment data.
-188             */
-189            public void addAttachment(final String name, final DataSource filedata) {
-190                    attachments.add(new AttachmentResource(name, filedata));
-191            }
-192    
-193            /**
-194             * Bean getter for {@link #fromRecipient}.
-195             */
-196            public Recipient getFromRecipient() {
-197                    return fromRecipient;
-198            }
-199    
-200            /**
-201             * Bean getter for {@link #replyToRecipient}.
-202             */
-203            public Recipient getReplyToRecipient() {
-204                    return replyToRecipient;
-205            }
-206    
-207            /**
-208             * Bean getter for {@link #subject}.
-209             */
-210            public String getSubject() {
-211                    return subject;
-212            }
-213    
-214            /**
-215             * Bean getter for {@link #text}.
-216             */
-217            public String getText() {
-218                    return text;
-219            }
-220    
-221            /**
-222             * Bean getter for {@link #textHTML}.
-223             */
-224            public String getTextHTML() {
-225                    return textHTML;
-226            }
-227    
-228            /**
-229             * Bean getter for {@link #attachments} as unmodifiable list.
-230             */
-231            public List<AttachmentResource> getAttachments() {
-232                    return Collections.unmodifiableList(attachments);
-233            }
-234    
-235            /**
-236             * Bean getter for {@link #embeddedImages} as unmodifiable list.
-237             */
-238            public List<AttachmentResource> getEmbeddedImages() {
-239                    return Collections.unmodifiableList(embeddedImages);
-240            }
-241    
-242            /**
-243             * Bean getter for {@link #recipients} as unmodifiable list.
-244             */
-245            public List<Recipient> getRecipients() {
-246                    return Collections.unmodifiableList(recipients);
-247            }
-248    
-249            /**
-250             * Bean getter for {@link #headers} as unmodifiable map.
-251             */
-252            public Map<String, String> getHeaders() {
-253                    return Collections.unmodifiableMap(headers);
-254            }
-255    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.ArrayList;
+004import java.util.Collections;
+005import java.util.HashMap;
+006import java.util.List;
+007import java.util.Map;
+008
+009import javax.activation.DataSource;
+010import javax.mail.Message.RecipientType;
+011import javax.mail.util.ByteArrayDataSource;
+012
+013/**
+014 * Email message with all necessary data for an effective mailing action, including attachments etc.
+015 *
+016 * @author Benny Bottema
+017 */
+018public class Email {
+019        /**
+020         * The sender of the email. Can be used in conjunction with {@link #replyToRecipient}.
+021         */
+022        private Recipient fromRecipient;
+023        /**
+024         * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+025         */
+026        private Recipient replyToRecipient;
+027
+028        /**
+029         * The email message body in plain text.
+030         */
+031        private String text;
+032
+033        /**
+034         * The email message body in html.
+035         */
+036        private String textHTML;
+037
+038        /**
+039         * The subject of the email message.
+040         */
+041        private String subject;
+042
+043        /**
+044         * List of {@link Recipient}.
+045         */
+046        private final List<Recipient> recipients;
+047
+048        /**
+049         * List of {@link AttachmentResource}.
+050         */
+051        private final List<AttachmentResource> embeddedImages;
+052
+053        /**
+054         * List of {@link AttachmentResource}.
+055         */
+056        private final List<AttachmentResource> attachments;
+057
+058        /**
+059         * Map of header name and values, such as <code>X-Priority</code> etc.
+060         */
+061        private final Map<String, String> headers;
+062
+063        /**
+064         * Constructor, creates all internal lists.
+065         */
+066        public Email() {
+067                recipients = new ArrayList<Recipient>();
+068                embeddedImages = new ArrayList<AttachmentResource>();
+069                attachments = new ArrayList<AttachmentResource>();
+070                headers = new HashMap<String, String>();
+071        }
+072
+073        /**
+074         * Sets the sender address.
+075         *
+076         * @param name The sender's name.
+077         * @param fromAddress The sender's email address.
+078         */
+079        public void setFromAddress(final String name, final String fromAddress) {
+080                fromRecipient = new Recipient(name, fromAddress, null);
+081        }
+082
+083        /**
+084         * Sets the reply-to address (optional).
+085         *
+086         * @param name The replied-to-receiver name.
+087         * @param replyToAddress The replied-to-receiver email address.
+088         */
+089        public void setReplyToAddress(final String name, final String replyToAddress) {
+090                replyToRecipient = new Recipient(name, replyToAddress, null);
+091        }
+092
+093        /**
+094         * Bean setters for {@link #subject}.
+095         */
+096        public void setSubject(final String subject) {
+097                this.subject = subject;
+098        }
+099
+100        /**
+101         * Bean setters for {@link #text}.
+102         */
+103        public void setText(final String text) {
+104                this.text = text;
+105        }
+106
+107        /**
+108         * Bean setters for {@link #textHTML}.
+109         */
+110        public void setTextHTML(final String textHTML) {
+111                this.textHTML = textHTML;
+112        }
+113
+114        /**
+115         * Adds a new {@link Recipient} to the list on account of name, address and recipient type (eg. {@link RecipientType#CC}).
+116         *
+117         * @param name The name of the recipient.
+118         * @param address The emailadres of the recipient.
+119         * @param type The type of receiver (eg. {@link RecipientType#CC}).
+120         * @see #recipients
+121         * @see Recipient
+122         * @see RecipientType
+123         */
+124        public void addRecipient(final String name, final String address, final RecipientType type) {
+125                recipients.add(new Recipient(name, address, type));
+126        }
+127
+128        /**
+129         * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+130         * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+131         * {@link ByteArrayDataSource}.
+132         *
+133         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+134         * @param data The byte data of the image to be embedded.
+135         * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+136         * @see ByteArrayDataSource
+137         * @see #addEmbeddedImage(String, DataSource)
+138         */
+139        public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) {
+140                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+141                dataSource.setName(name);
+142                addEmbeddedImage(name, dataSource);
+143        }
+144
+145        /**
+146         * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+147         *
+148         * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+149         * @param imagedata The image data.
+150         */
+151        public void addEmbeddedImage(final String name, final DataSource imagedata) {
+152                embeddedImages.add(new AttachmentResource(name, imagedata));
+153        }
+154
+155        /**
+156         * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+157         * <p>
+158         * example: <code>email.addHeader("X-Priority", 2)</code>
+159         *
+160         * @param name The name of the header.
+161         * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+162         */
+163        public void addHeader(final String name, final Object value) {
+164                headers.put(name, String.valueOf(value));
+165        }
+166
+167        /**
+168         * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+169         * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+170         *
+171         * @param name The name of the extension (eg. filename including extension).
+172         * @param data The byte data of the attachment.
+173         * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+174         * @see ByteArrayDataSource
+175         * @see #addAttachment(String, DataSource)
+176         */
+177        public void addAttachment(final String name, final byte[] data, final String mimetype) {
+178                final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+179                dataSource.setName(name);
+180                addAttachment(name, dataSource);
+181        }
+182
+183        /**
+184         * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+185         *
+186         * @param name The name of the attachment (eg. 'filename.ext').
+187         * @param filedata The attachment data.
+188         */
+189        public void addAttachment(final String name, final DataSource filedata) {
+190                attachments.add(new AttachmentResource(name, filedata));
+191        }
+192
+193        /**
+194         * Bean getter for {@link #fromRecipient}.
+195         */
+196        public Recipient getFromRecipient() {
+197                return fromRecipient;
+198        }
+199
+200        /**
+201         * Bean getter for {@link #replyToRecipient}.
+202         */
+203        public Recipient getReplyToRecipient() {
+204                return replyToRecipient;
+205        }
+206
+207        /**
+208         * Bean getter for {@link #subject}.
+209         */
+210        public String getSubject() {
+211                return subject;
+212        }
+213
+214        /**
+215         * Bean getter for {@link #text}.
+216         */
+217        public String getText() {
+218                return text;
+219        }
+220
+221        /**
+222         * Bean getter for {@link #textHTML}.
+223         */
+224        public String getTextHTML() {
+225                return textHTML;
+226        }
+227
+228        /**
+229         * Bean getter for {@link #attachments} as unmodifiable list.
+230         */
+231        public List<AttachmentResource> getAttachments() {
+232                return Collections.unmodifiableList(attachments);
+233        }
+234
+235        /**
+236         * Bean getter for {@link #embeddedImages} as unmodifiable list.
+237         */
+238        public List<AttachmentResource> getEmbeddedImages() {
+239                return Collections.unmodifiableList(embeddedImages);
+240        }
+241
+242        /**
+243         * Bean getter for {@link #recipients} as unmodifiable list.
+244         */
+245        public List<Recipient> getRecipients() {
+246                return Collections.unmodifiableList(recipients);
+247        }
+248
+249        /**
+250         * Bean getter for {@link #headers} as unmodifiable map.
+251         */
+252        public Map<String, String> getHeaders() {
+253                return Collections.unmodifiableMap(headers);
+254        }
+255
+256        /**
+257         * Fluent interface Builder for Emails
+258         * @author Jared Stewart
+259         */
+260        public static class Builder {
+261                private Recipient fromRecipient;
+262                /**
+263                 * The reply-to-address, optional. Can be used in conjunction with {@link #fromRecipient}.
+264                 */
+265                private Recipient replyToRecipient;
+266
+267                /**
+268                 * The email message body in plain text.
+269                 */
+270                private String text;
+271
+272                /**
+273                 * The email message body in html.
+274                 */
+275                private String textHTML;
+276
+277                /**
+278                 * The subject of the email message.
+279                 */
+280                private String subject;
+281
+282                /**
+283                 * List of {@link Recipient}.
+284                 */
+285                private final List<Recipient> recipients;
+286
+287                /**
+288                 * List of {@link AttachmentResource}.
+289                 */
+290                private final List<AttachmentResource> embeddedImages;
+291
+292                /**
+293                 * List of {@link AttachmentResource}.
+294                 */
+295                private final List<AttachmentResource> attachments;
+296
+297                /**
+298                 * Map of header name and values, such as <code>X-Priority</code> etc.
+299                 */
+300                private final Map<String, String> headers;
+301
+302                private Email email;
+303
+304                public Builder() {
+305                        recipients = new ArrayList<Recipient>();
+306                        embeddedImages = new ArrayList<AttachmentResource>();
+307                        attachments = new ArrayList<AttachmentResource>();
+308                        headers = new HashMap<String, String>();
+309                }
+310
+311                /**
+312                 *
+313                 */
+314                public Email build() {
+315                        return new Email(this);
+316                }
+317
+318                /**
+319                 * Sets the sender address.
+320                 *
+321                 * @param name The sender's name.
+322                 * @param fromAddress The sender's email address.
+323                 */
+324                public Builder from(final String name, final String fromAddress){
+325                        this.fromRecipient = new Recipient(name, fromAddress, null);
+326                        return this;
+327                }
+328
+329                /**
+330                 * Sets the reply-to address (optional).
+331                 *
+332                 * @param name The replied-to-receiver name.
+333                 * @param replyToAddress The replied-to-receiver email address.
+334                 */
+335                public Builder replyTo(final String name, final String replyToAddress) {
+336                        this.replyToRecipient = new Recipient(name, replyToAddress, null);
+337                        return this;
+338                }
+339
+340
+341                /**
+342                 * Sets the {@link #subject}.
+343                 */
+344                public Builder subject(final String subject) {
+345                        this.subject = subject;
+346                        return this;
+347                }
+348
+349                /**
+350                 * Sets the {@link #text}.
+351                 */
+352                public Builder text(final String text) {
+353                        this.text = text;
+354                        return this;
+355                }
+356
+357                /**
+358                 * Sets the {@link #textHTML}.
+359                 */
+360                public Builder textHTML(final String textHTML) {
+361                        this.textHTML = textHTML;
+362                        return this;
+363                }
+364
+365                /**
+366                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+367                 *
+368                 * @param name The name of the recipient.
+369                 * @param address The emailaddress of the recipient.
+370                 * @see #recipients
+371                 * @see Recipient
+372                 */
+373                public Builder to(final String name, final String address) {
+374                        recipients.add(new Recipient(name, address, RecipientType.TO));
+375                        return this;
+376                }
+377
+378                /**
+379                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#TO}.
+380                 *
+381                 * @param recipient The recipent whose name and address to use
+382                 * @see #recipients
+383                 * @see Recipient
+384                 */
+385                public Builder to(final Recipient recipient) {
+386                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.TO));
+387                        return this;
+388                }
+389
+390
+391
+392                /**
+393                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+394                 *
+395                 * @param name The name of the recipient.
+396                 * @param address The emailaddress of the recipient.
+397                 * @see #recipients
+398                 * @see Recipient
+399                 */
+400                public Builder cc(final String name, final String address) {
+401                        recipients.add(new Recipient(name, address, RecipientType.CC));
+402                        return this;
+403                }
+404
+405                /**
+406                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#CC}.
+407                 *
+408                 * @param recipient The recipent whose name and address to use
+409                 * @see #recipients
+410                 * @see Recipient
+411                 */
+412                public Builder cc(final Recipient recipient) {
+413                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.CC));
+414                        return this;
+415                }
+416
+417                /**
+418                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+419                 *
+420                 * @param name The name of the recipient.
+421                 * @param address The emailaddress of the recipient.
+422                 * @see #recipients
+423                 * @see Recipient
+424                 */
+425                public Builder bcc(final String name, final String address) {
+426                        recipients.add(new Recipient(name, address, RecipientType.BCC));
+427                        return this;
+428                }
+429
+430                /**
+431                 * Adds a new {@link Recipient} to the list on account of name, address with recipient type {@link RecipientType#BCC}.
+432                 *
+433                 * @param recipient The recipent whose name and address to use
+434                 * @see #recipients
+435                 * @see Recipient
+436                 */
+437                public Builder bcc(final Recipient recipient) {
+438                        recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), RecipientType.BCC));
+439                        return this;
+440                }
+441
+442                /**
+443                 * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte
+444                 * data. Then delegates to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a
+445                 * {@link ByteArrayDataSource}.
+446                 *
+447                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:signature&gt;').
+448                 * @param data The byte data of the image to be embedded.
+449                 * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg").
+450                 * @see ByteArrayDataSource
+451                 * @see #addEmbeddedImage(String, DataSource)
+452                 */
+453                public Builder embedImage(final String name, final byte[] data, final String mimetype) {
+454                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+455                        dataSource.setName(name);
+456                        return embedImage(name, dataSource);
+457                }
+458
+459                /**
+460                 * Overloaded method which sets an embedded image on account of name and {@link DataSource}.
+461                 *
+462                 * @param name The name of the image as being referred to from the message content body (eg. '&lt;cid:embeddedimage&gt;').
+463                 * @param imagedata The image data.
+464                 */
+465                public Builder embedImage(final String name, final DataSource imagedata) {
+466                        embeddedImages.add(new AttachmentResource(name, imagedata));
+467                        return this;
+468                }
+469
+470                /**
+471                 * Adds a header to the {@link #headers} list. The value is stored as a <code>String</code>.
+472                 * <p>
+473                 * example: <code>email.addHeader("X-Priority", 2)</code>
+474                 *
+475                 * @param name The name of the header.
+476                 * @param value The value of the header, which will be stored using {@link String#valueOf(Object)}.
+477                 */
+478                public Builder addHeader(final String name, final Object value) {
+479                        headers.put(name, String.valueOf(value));
+480                        return this;
+481                }
+482
+483                /**
+484                 * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to
+485                 * {@link #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}.
+486                 *
+487                 * @param name The name of the extension (eg. filename including extension).
+488                 * @param data The byte data of the attachment.
+489                 * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf").
+490                 * @see ByteArrayDataSource
+491                 * @see #addAttachment(String, DataSource)
+492                 */
+493                public void addAttachment(final String name, final byte[] data, final String mimetype) {
+494                        final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
+495                        dataSource.setName(name);
+496                        addAttachment(name, dataSource);
+497                }
+498
+499                /**
+500                 * Overloaded method which sets an attachment on account of name and {@link DataSource}.
+501                 *
+502                 * @param name The name of the attachment (eg. 'filename.ext').
+503                 * @param filedata The attachment data.
+504                 */
+505                public void addAttachment(final String name, final DataSource filedata) {
+506                        attachments.add(new AttachmentResource(name, filedata));
+507                }
+508
+509        }
+510
+511        /**
+512         * Constructor for the Builder class
+513         * @param builder The builder from which to create the email.
+514         */
+515        private Email(Builder builder) {
+516                recipients = builder.recipients;
+517                embeddedImages = builder.embeddedImages;
+518                attachments = builder.attachments;
+519                headers = builder.headers;
+520
+521                fromRecipient = builder.fromRecipient;
+522                replyToRecipient = builder.replyToRecipient;
+523                text = builder.text;
+524                textHTML = builder.textHTML;
+525                subject = builder.subject;
+526        }
+527}
 
 
 
@@ -316,6 +593,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html index 5668d5e94..3f82dbd12 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailAddressValidationCriteria.html @@ -1,64 +1,75 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    /**
-004     * Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to
-005     * <code>true</code>.
-006     * 
-007     * @author Benny Bottema
-008     * @see #EmailAddressValidationCriteria(boolean, boolean)
-009     */
-010    public class EmailAddressValidationCriteria {
-011            private final boolean allowDomainLiterals;
-012            private final boolean allowQuotedIdentifiers;
-013    
-014            /**
-015             * @param allowDomainLiterals <ul>
-016             *            <li>This flag states whether domain literals are allowed in the email address, e.g.:
-017             *            <p>
-018             *            <tt>someone@[192.168.1.100]</tt> or <br/>
-019             *            <tt>john.doe@[23:33:A2:22:16:1F]</tt> or <br/>
-020             *            <tt>me@[my computer]</tt>
-021             *            </p>
-022             *            <p>
-023             *            The RFC says these are valid email addresses, but most people don't like allowing them. If you don't want to allow them,
-024             *            and only want to allow valid domain names (<a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>, x.y.z.com, etc),
-025             *            change this constant to <tt>false</tt>.
-026             *            <p>
-027             *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
-028             *            application.
-029             *            </li>
-030             *            </ul>
-031             * @param allowQuotedIdentifiers <ul>
-032             *            <li>This flag states whether quoted identifiers are allowed (using quotes and angle brackets around the raw address) are
-033             *            allowed, e.g.:
-034             *            <p>
-035             *            <tt>"John Smith" &lt;john.smith@somewhere.com&gt;</tt>
-036             *            <p>
-037             *            The RFC says this is a valid mailbox. If you don't want to allow this, because for example, you only want users to enter
-038             *            in a raw address (<tt>john.smith@somewhere.com</tt> - no quotes or angle brackets), then change this constant to
-039             *            <tt>false</tt>.
-040             *            <p>
-041             *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
-042             *            application.
-043             *            </li>
-044             *            </ul>
-045             */
-046            public EmailAddressValidationCriteria(boolean allowDomainLiterals, boolean allowQuotedIdentifiers) {
-047                    this.allowDomainLiterals = allowDomainLiterals;
-048                    this.allowQuotedIdentifiers = allowQuotedIdentifiers;
-049            }
-050    
-051            public final boolean isAllowDomainLiterals() {
-052                    return allowDomainLiterals;
-053            }
-054    
-055            public final boolean isAllowQuotedIdentifiers() {
-056                    return allowQuotedIdentifiers;
-057            }
-058    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003/**
+004 * Defines a set of restriction flags for email address validation. To remain completely true to RFC 2822, all flags should be set to
+005 * <code>true</code>.
+006 * 
+007 * @author Benny Bottema
+008 * @see #EmailAddressValidationCriteria(boolean, boolean)
+009 */
+010public class EmailAddressValidationCriteria {
+011
+012        private final boolean allowDomainLiterals;
+013        private final boolean allowQuotedIdentifiers;
+014
+015        /**
+016         * Criteria which is most RFC 2822 compliant and allows all compiant address forms, including the more exotic ones.
+017         * 
+018         * @see #EmailAddressValidationCriteria(boolean, boolean)
+019         */
+020        public static final EmailAddressValidationCriteria RFC_COMPLIANT = new EmailAddressValidationCriteria(true, true);
+021
+022        /**
+023         * @param allowDomainLiterals <ul>
+024         *            <li>This flag states whether domain literals are allowed in the email address, e.g.:
+025         *            <p>
+026         *            <tt>someone@[192.168.1.100]</tt> or <br>
+027         *            <tt>john.doe@[23:33:A2:22:16:1F]</tt> or <br>
+028         *            <tt>me@[my computer]</tt>
+029         *            </p>
+030         *            <p>
+031         *            The RFC says these are valid email addresses, but most people don't like allowing them. If you don't want to allow them,
+032         *            and only want to allow valid domain names (<a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>, x.y.z.com, etc),
+033         *            change this constant to <tt>false</tt>.
+034         *            <p>
+035         *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
+036         *            application.</li>
+037         *            </ul>
+038         * @param allowQuotedIdentifiers <ul>
+039         *            <li>This flag states whether quoted identifiers are allowed (using quotes and angle brackets around the raw address) are
+040         *            allowed, e.g.:
+041         *            <p>
+042         *            <tt>"John Smith" &lt;john.smith@somewhere.com&gt;</tt>
+043         *            <p>
+044         *            The RFC says this is a valid mailbox. If you don't want to allow this, because for example, you only want users to enter
+045         *            in a raw address (<tt>john.smith@somewhere.com</tt> - no quotes or angle brackets), then change this constant to
+046         *            <tt>false</tt>.
+047         *            <p>
+048         *            Its default value is <tt>true</tt> to remain RFC 2822 compliant, but you should set it depending on what you need for your
+049         *            application.</li>
+050         *            </ul>
+051         */
+052        public EmailAddressValidationCriteria(boolean allowDomainLiterals, boolean allowQuotedIdentifiers) {
+053                this.allowDomainLiterals = allowDomainLiterals;
+054                this.allowQuotedIdentifiers = allowQuotedIdentifiers;
+055        }
+056
+057        public final boolean isAllowDomainLiterals() {
+058                return allowDomainLiterals;
+059        }
+060
+061        public final boolean isAllowQuotedIdentifiers() {
+062                return allowQuotedIdentifiers;
+063        }
+064}
 
 
 
@@ -119,6 +130,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html index bb2347e46..3b01118fc 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/EmailValidationUtil.html @@ -1,113 +1,118 @@ - - -
-001    /*
-002     * Copyright 2008 Les Hazlewood Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
-003     * file except in compliance with the License. You may obtain a copy of the License at
-004     * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
-005     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
-006     * either express or implied. See the License for the specific language governing permissions and limitations under the
-007     * License.
-008     */
-009    package org.codemonkey.simplejavamail;
-010    
-011    import java.util.regex.Pattern;
-012    
-013    /**
-014     * Validates an email address according to <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>, using regular expressions.
-015     * <p>
-016     * From the original author: <br />
-017     * <blockquote> If you use this code, please keep the author information in tact and reference my site at <a
-018     * href="http://www.leshazlewood.com">leshazlewood.com</a>. Thanks! </blockquote>
-019     * <p>
-020     * Code sanitized by Benny Bottema (kept validation 100% in tact).
-021     * 
-022     * @author Les Hazlewood, Benny Bottema
-023     * @see EmailAddressValidationCriteria
-024     */
-025    public final class EmailValidationUtil {
-026    
-027            /**
-028             * Private constructor; this is a utility class with static methods only, not designed for extension.
-029             */
-030            private EmailValidationUtil() {
-031                    //
-032            }
-033    
-034            /**
-035             * Validates an e-mail with default validation flags that remains <code>true</code> to RFC 2822. This means allowing both domain
-036             * literals and quoted identifiers.
-037             * 
-038             * @param email A complete email address.
-039             * @return Whether the e-mail address is compliant with RFC 2822.
-040             * @see EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)
-041             */
-042            public static boolean isValid(final String email) {
-043                    return isValid(email, new EmailAddressValidationCriteria(true, true));
-044            }
-045    
-046            /**
-047             * Validates an e-mail with given validation flags.
-048             * 
-049             * @param email A complete email address.
-050             * @param emailAddressValidationCriteria A set of flags that restrict or relax RFC 2822 compliance.
-051             * @return Whether the e-mail address is compliant with RFC 2822, configured using the passed in {@link EmailAddressValidationCriteria}.
-052             * @see EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)
-053             */
-054            public static boolean isValid(final String email, final EmailAddressValidationCriteria emailAddressValidationCriteria) {
-055                    return buildValidEmailPattern(emailAddressValidationCriteria).matcher(email).matches();
-056            }
-057    
-058            protected static Pattern buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) {
-059                    // RFC 2822 2.2.2 Structured Header Field Bodies
-060                    final String wsp = "[ \\t]"; // space or tab
-061                    final String fwsp = wsp + "*";
-062                    // RFC 2822 3.2.1 Primitive tokens
-063                    final String dquote = "\\\"";
-064                    // ASCII Control characters excluding white space:
-065                    final String noWsCtl = "\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F";
-066                    // all ASCII characters except CR and LF:
-067                    final String asciiText = "[\\x01-\\x09\\x0B\\x0C\\x0E-\\x7F]";
-068                    // RFC 2822 3.2.2 Quoted characters:
-069                    // single backslash followed by a text char
-070                    final String quotedPair = "(\\\\" + asciiText + ")";
-071                    // RFC 2822 3.2.4 Atom:
-072                    final String atext = "[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
-073                    final String atom = fwsp + atext + "+" + fwsp;
-074                    final String dotAtomText = atext + "+" + "(" + "\\." + atext + "+)*";
-075                    final String dotAtom = fwsp + "(" + dotAtomText + ")" + fwsp;
-076                    // RFC 2822 3.2.5 Quoted strings:
-077                    // noWsCtl and the rest of ASCII except the doublequote and backslash characters:
-078                    final String qtext = "[" + noWsCtl + "\\x21\\x23-\\x5B\\x5D-\\x7E]";
-079                    final String qcontent = "(" + qtext + "|" + quotedPair + ")";
-080                    final String quotedString = dquote + "(" + fwsp + qcontent + ")*" + fwsp + dquote;
-081                    // RFC 2822 3.2.6 Miscellaneous tokens
-082                    final String word = "((" + atom + ")|(" + quotedString + "))";
-083                    final String phrase = word + "+"; // one or more words.
-084                    // RFC 1035 tokens for domain names:
-085                    final String letter = "[a-zA-Z]";
-086                    final String letDig = "[a-zA-Z0-9]";
-087                    final String letDigHyp = "[a-zA-Z0-9-]";
-088                    final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + ")?";
-089                    final String rfc1035DomainName = rfcLabel + "(\\." + rfcLabel + ")*\\." + letter + "{2,6}";
-090                    // RFC 2822 3.4 Address specification
-091                    // domain text - non white space controls and the rest of ASCII chars not including [, ], or \:
-092                    final String dtext = "[" + noWsCtl + "\\x21-\\x5A\\x5E-\\x7E]";
-093                    final String dcontent = dtext + "|" + quotedPair;
-094                    final String domainLiteral = "\\[" + "(" + fwsp + dcontent + "+)*" + fwsp + "\\]";
-095                    final String rfc2822Domain = "(" + dotAtom + "|" + domainLiteral + ")";
-096                    final String domain = parameterObject.isAllowDomainLiterals() ? rfc2822Domain : rfc1035DomainName;
-097                    final String localPart = "((" + dotAtom + ")|(" + quotedString + "))";
-098                    final String addrSpec = localPart + "@" + domain;
-099                    final String angleAddr = "<" + addrSpec + ">";
-100                    final String nameAddr = "(" + phrase + ")?" + fwsp + angleAddr;
-101                    final String mailbox = nameAddr + "|" + addrSpec;
-102                    // now compile a pattern for efficient re-use:
-103                    // if we're allowing quoted identifiers or not:
-104                    final String patternString = parameterObject.isAllowQuotedIdentifiers() ? mailbox : addrSpec;
-105                    return Pattern.compile(patternString);
-106            }
-107    }
+
+
+
+Source code
+
+
+
+
+
001/*
+002 * Copyright 2008 Les Hazlewood Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
+003 * file except in compliance with the License. You may obtain a copy of the License at
+004 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
+005 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+006 * either express or implied. See the License for the specific language governing permissions and limitations under the
+007 * License.
+008 */
+009package org.codemonkey.simplejavamail;
+010
+011import java.util.regex.Pattern;
+012
+013/**
+014 * Validates an email address according to <a href="http://www.ietf.org/rfc/rfc2822.txt">RFC 2822</a>, using regular expressions.
+015 * <p>
+016 * From the original author: <br>
+017 * <blockquote> If you use this code, please keep the author information in tact and reference my site at <a
+018 * href="http://www.leshazlewood.com">leshazlewood.com</a>. Thanks! </blockquote>
+019 * <p>
+020 * Code sanitized by Benny Bottema (kept validation 100% in tact).
+021 * 
+022 * @author Les Hazlewood, Benny Bottema
+023 * @see EmailAddressValidationCriteria
+024 */
+025public final class EmailValidationUtil {
+026
+027        /**
+028         * Private constructor; this is a utility class with static methods only, not designed for extension.
+029         */
+030        private EmailValidationUtil() {
+031                //
+032        }
+033
+034        /**
+035         * Validates an e-mail with default validation flags that remains <code>true</code> to RFC 2822. This means allowing both domain
+036         * literals and quoted identifiers.
+037         * 
+038         * @param email A complete email address.
+039         * @return Whether the e-mail address is compliant with RFC 2822.
+040         * @see EmailAddressValidationCriteria#RFC_COMPLIANT
+041         */
+042        public static boolean isValid(final String email) {
+043                return isValid(email, EmailAddressValidationCriteria.RFC_COMPLIANT);
+044        }
+045
+046        /**
+047         * Validates an e-mail with given validation flags.
+048         * 
+049         * @param email A complete email address.
+050         * @param emailAddressValidationCriteria A set of flags that restrict or relax RFC 2822 compliance.
+051         * @return Whether the e-mail address is compliant with RFC 2822, configured using the passed in {@link EmailAddressValidationCriteria}.
+052         * @see EmailAddressValidationCriteria#RFC_COMPLIANT
+053         */
+054        public static boolean isValid(final String email, final EmailAddressValidationCriteria emailAddressValidationCriteria) {
+055                return buildValidEmailPattern(emailAddressValidationCriteria).matcher(email).matches();
+056        }
+057
+058        protected static Pattern buildValidEmailPattern(EmailAddressValidationCriteria parameterObject) {
+059                // RFC 2822 2.2.2 Structured Header Field Bodies
+060                final String wsp = "[ \\t]"; // space or tab
+061                final String fwsp = wsp + "*";
+062                // RFC 2822 3.2.1 Primitive tokens
+063                final String dquote = "\\\"";
+064                // ASCII Control characters excluding white space:
+065                final String noWsCtl = "\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F";
+066                // all ASCII characters except CR and LF:
+067                final String asciiText = "[\\x01-\\x09\\x0B\\x0C\\x0E-\\x7F]";
+068                // RFC 2822 3.2.2 Quoted characters:
+069                // single backslash followed by a text char
+070                final String quotedPair = "(\\\\" + asciiText + ")";
+071                // RFC 2822 3.2.4 Atom:
+072                final String atext = "[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]";
+073                final String atom = fwsp + atext + "+" + fwsp;
+074                final String dotAtomText = atext + "+" + "(" + "\\." + atext + "+)*";
+075                final String dotAtom = fwsp + "(" + dotAtomText + ")" + fwsp;
+076                // RFC 2822 3.2.5 Quoted strings:
+077                // noWsCtl and the rest of ASCII except the doublequote and backslash characters:
+078                final String qtext = "[" + noWsCtl + "\\x21\\x23-\\x5B\\x5D-\\x7E]";
+079                final String qcontent = "(" + qtext + "|" + quotedPair + ")";
+080                final String quotedString = dquote + "(" + fwsp + qcontent + ")*" + fwsp + dquote;
+081                // RFC 2822 3.2.6 Miscellaneous tokens
+082                final String word = "((" + atom + ")|(" + quotedString + "))";
+083                final String phrase = word + "+"; // one or more words.
+084                // RFC 1035 tokens for domain names:
+085                final String letter = "[a-zA-Z]";
+086                final String letDig = "[a-zA-Z0-9]";
+087                final String letDigHyp = "[a-zA-Z0-9-]";
+088                final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + ")?";
+089                final String rfc1035DomainName = rfcLabel + "(\\." + rfcLabel + ")*\\." + letter + "{2,6}";
+090                // RFC 2822 3.4 Address specification
+091                // domain text - non white space controls and the rest of ASCII chars not including [, ], or \:
+092                final String dtext = "[" + noWsCtl + "\\x21-\\x5A\\x5E-\\x7E]";
+093                final String dcontent = dtext + "|" + quotedPair;
+094                final String domainLiteral = "\\[" + "(" + fwsp + dcontent + "+)*" + fwsp + "\\]";
+095                final String rfc2822Domain = "(" + dotAtom + "|" + domainLiteral + ")";
+096                final String domain = parameterObject.isAllowDomainLiterals() ? rfc2822Domain : rfc1035DomainName;
+097                final String localPart = "((" + dotAtom + ")|(" + quotedString + "))";
+098                final String addrSpec = localPart + "@" + domain;
+099                final String angleAddr = "<" + addrSpec + ">";
+100                final String nameAddr = "(" + phrase + ")?" + fwsp + angleAddr;
+101                final String mailbox = nameAddr + "|" + addrSpec;
+102                // now compile a pattern for efficient re-use:
+103                // if we're allowing quoted identifiers or not:
+104                final String patternString = parameterObject.isAllowQuotedIdentifiers() ? mailbox : addrSpec;
+105                return Pattern.compile(patternString);
+106        }
+107}
 
 
 
@@ -168,6 +173,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/MailException.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/MailException.html index 8c88b4380..26a9c9ab4 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/MailException.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/MailException.html @@ -1,38 +1,43 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import javax.mail.MessagingException;
-004    
-005    /**
-006     * This exception is used to communicate errors during the sending of email.
-007     * 
-008     * @author Benny Bottema
-009     */
-010    @SuppressWarnings("serial")
-011    public final class MailException extends RuntimeException {
-012    
-013            protected static final String GENERIC_ERROR = "Generic error: %s";
-014            protected static final String MISSING_HOST = "Can't send an email without host";
-015            protected static final String MISSING_USERNAME = "Can't have a password without username";
-016            protected static final String INVALID_ENCODING = "Encoding not accepted: %s";
-017            protected static final String INVALID_RECIPIENT = "Invalid TO address: %s";
-018            protected static final String INVALID_REPLYTO = "Invalid REPLY TO address: %s";
-019            protected static final String INVALID_SENDER = "Invalid FROM address: %s";
-020            protected static final String MISSING_SENDER = "Email is not valid: missing sender";
-021            protected static final String MISSING_RECIPIENT = "Email is not valid: missing recipients";
-022            protected static final String MISSING_SUBJECT = "Email is not valid: missing subject";
-023            protected static final String MISSING_CONTENT = "Email is not valid: missing content body";
-024    
-025            protected MailException(final String message) {
-026                    super(message);
-027            }
-028    
-029            protected MailException(final String message, final MessagingException cause) {
-030                    super(message, cause);
-031            }
-032    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import javax.mail.MessagingException;
+004
+005/**
+006 * This exception is used to communicate errors during the sending of email.
+007 * 
+008 * @author Benny Bottema
+009 */
+010@SuppressWarnings("serial")
+011public final class MailException extends RuntimeException {
+012
+013        protected static final String GENERIC_ERROR = "Generic error: %s";
+014        protected static final String MISSING_HOST = "Can't send an email without host";
+015        protected static final String MISSING_USERNAME = "Can't have a password without username";
+016        protected static final String INVALID_ENCODING = "Encoding not accepted: %s";
+017        protected static final String INVALID_RECIPIENT = "Invalid TO address: %s";
+018        protected static final String INVALID_REPLYTO = "Invalid REPLY TO address: %s";
+019        protected static final String INVALID_SENDER = "Invalid FROM address: %s";
+020        protected static final String MISSING_SENDER = "Email is not valid: missing sender";
+021        protected static final String MISSING_RECIPIENT = "Email is not valid: missing recipients";
+022        protected static final String MISSING_SUBJECT = "Email is not valid: missing subject";
+023        protected static final String MISSING_CONTENT = "Email is not valid: missing content body";
+024
+025        protected MailException(final String message) {
+026                super(message);
+027        }
+028
+029        protected MailException(final String message, final MessagingException cause) {
+030                super(message, cause);
+031        }
+032}
 
 
 
@@ -93,6 +98,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/Mailer.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/Mailer.html index d0e5df973..11c78bc17 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/Mailer.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/Mailer.html @@ -1,526 +1,558 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.io.UnsupportedEncodingException;
-004    import java.util.Date;
-005    import java.util.Map;
-006    import java.util.Properties;
-007    
-008    import javax.activation.DataHandler;
-009    import javax.activation.DataSource;
-010    import javax.mail.Address;
-011    import javax.mail.Authenticator;
-012    import javax.mail.BodyPart;
-013    import javax.mail.Message;
-014    import javax.mail.MessagingException;
-015    import javax.mail.Part;
-016    import javax.mail.PasswordAuthentication;
-017    import javax.mail.Session;
-018    import javax.mail.Transport;
-019    import javax.mail.internet.InternetAddress;
-020    import javax.mail.internet.MimeBodyPart;
-021    import javax.mail.internet.MimeMessage;
-022    import javax.mail.internet.MimeMultipart;
-023    import javax.mail.internet.MimeUtility;
-024    
-025    import org.apache.log4j.Logger;
-026    
-027    /**
-028     * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
-029     * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br />
-030     * <br />
-031     * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
-032     * instances. <br />
-033     * <br />
-034     * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
-035     * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br />
-036     * <br />
-037     * Technically, the resulting email structure is as follows:<br />
-038     * 
-039     * <pre>
-040     * - root
-041     *      - related
-042     *              - alternative
-043     *                      - mail text
-044     *                      - mail html text
-045     *              - embedded images
-046     *      - attachments
-047     * </pre>
-048     * 
-049     * <br />
-050     * Usage example:<br />
-051     * 
-052     * <pre>
-053     * Email email = new Email();
-054     * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
-055     * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
-056     * email.setText(&quot;We should meet up!!&quot;);
-057     * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
-058     * email.setSubject(&quot;Hey&quot;);
-059     * new Mailer(preconfiguredMailSession).sendMail(email);
-060     * // or:
-061     * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
-062     * </pre>
-063     * 
-064     * @author Benny Bottema
-065     * @see MimeEmailMessageWrapper
-066     * @see Email
-067     */
-068    public class Mailer {
-069    
-070            private static final Logger logger = Logger.getLogger(Mailer.class);
-071            
-072            /**
-073             * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
-074             */
-075            private static final String CHARACTER_ENCODING = "UTF-8";
-076    
-077            /**
-078             * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
-079             * directly, when no <code>Session</code> instance was provided.
-080             * 
-081             * @see #Mailer(Session)
-082             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-083             */
-084            private final Session session;
-085    
-086            /**
-087             * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
-088             * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
-089             */
-090            private TransportStrategy transportStrategy;
-091    
-092            /**
-093             * Email address restriction flags set either by constructor or overridden by getter by user.
-094             * 
-095             * @see EmailAddressValidationCriteria
-096             */
-097            private EmailAddressValidationCriteria emailAddressValidationCriteria;
-098    
-099            /**
-100             * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
-101             * configured (host, port, authentication and transport protocol settings).
-102             * <p>
-103             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-104             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-105             * 
-106             * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
-107             */
-108            public Mailer(final Session session) {
-109                    this.session = session;
-110                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-111            }
-112    
-113            /**
-114             * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
-115             * web container, or Spring context etc.
-116             * <p>
-117             * Also defines a default email address validation criteria object, which remains true to RFC 2822, meaning allowing both domain
-118             * literals and quoted identifiers (see {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}).
-119             * 
-120             * @param host The address URL of the SMTP server to be used.
-121             * @param port The port of the SMTP server.
-122             * @param username An optional username, may be <code>null</code>.
-123             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-124             * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
-125             */
-126            public Mailer(final String host, final Integer port, final String username, final String password,
-127                            final TransportStrategy transportStrategy) {
-128                    // we're doing these validations manually instead of using Apache Commons to avoid another dependency
-129                    if (host == null || host.trim().equals("")) {
-130                            throw new MailException(MailException.MISSING_HOST);
-131                    } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
-132                            throw new MailException(MailException.MISSING_USERNAME);
-133                    }
-134                    this.transportStrategy = transportStrategy;
-135                    this.session = createMailSession(host, port, username, password);
-136                    this.emailAddressValidationCriteria = new EmailAddressValidationCriteria(true, true);
-137            }
-138    
-139            /**
-140             * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
-141             * {@link #transportStrategy} in two ways:
-142             * <ol>
-143             * <li>request an initial property list which the strategy may pre-populate</li>
-144             * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
-145             * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
-146             * </ol>
-147             * 
-148             * @param host The address URL of the SMTP server to be used.
-149             * @param port The port of the SMTP server.
-150             * @param username An optional username, may be <code>null</code>.
-151             * @param password An optional password, may be <code>null</code>.
-152             * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
-153             * @see TransportStrategy#generateProperties()
-154             * @see TransportStrategy#propertyNameHost()
-155             * @see TransportStrategy#propertyNamePort()
-156             * @see TransportStrategy#propertyNameUsername()
-157             * @see TransportStrategy#propertyNameAuthenticate()
-158             */
-159            public Session createMailSession(final String host, final Integer port, final String username, final String password) {
-160                    if (transportStrategy == null) {
-161                            logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
-162                            transportStrategy = TransportStrategy.SMTP_PLAIN;
-163                    }
-164                    Properties props = transportStrategy.generateProperties();
-165                    props.put(transportStrategy.propertyNameHost(), host);
-166                    if (port != null) {
-167                            props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
-168                    } else {
-169                            // let JavaMail's Transport objects determine deault port base don the used protocol
-170                    }
-171    
-172                    if (username != null) {
-173                            props.put(transportStrategy.propertyNameUsername(), username);
-174                    }
-175    
-176                    if (password != null) {
-177                            props.put(transportStrategy.propertyNameAuthenticate(), "true");
-178                            return Session.getInstance(props, new Authenticator() {
-179                                    @Override
-180                                    protected PasswordAuthentication getPasswordAuthentication() {
-181                                            return new PasswordAuthentication(username, password);
-182                                    }
-183                            });
-184                    } else {
-185                            return Session.getInstance(props);
-186                    }
-187            }
-188    
-189            /**
-190             * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
-191             * 
-192             * @param host The address URL of the SMTP server to be used.
-193             * @param port The port of the SMTP server.
-194             * @param username An optional username, may be <code>null</code>.
-195             * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
-196             * @see #Mailer(String, Integer, String, String, TransportStrategy)
-197             */
-198            public Mailer(final String host, final Integer port, final String username, final String password) {
-199                    this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
-200            }
-201    
-202            /**
-203             * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
-204             * 
-205             * @param debug Flag to indicate debug mode yes/no.
-206             */
-207            public void setDebug(boolean debug) {
-208                    session.setDebug(debug);
-209            }
-210    
-211            /**
-212             * Processes an {@link Email} instance into a completely configured {@link Message}.
-213             * <p>
-214             * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
-215             * all connection details have been configured in the provided {@link Session} instance.
-216             * <p>
-217             * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
-218             * providing a message id.
-219             * 
-220             * @param email The information for the email to be sent.
-221             * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
-222             *             etc.
-223             * @see #validate(Email)
-224             * @see #prepareMessage(Email, MimeEmailMessageWrapper)
-225             * @see #setRecipients(Email, Message)
-226             * @see #setTexts(Email, MimeMultipart)
-227             * @see #setEmbeddedImages(Email, MimeMultipart)
-228             * @see #setAttachments(Email, MimeMultipart)
-229             */
-230            public final void sendMail(final Email email)
-231                            throws MailException {
-232                    if (validate(email)) {
-233                            try {
-234                                    // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
-235                                    final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
-236                                    // fill and send wrapped mime message parts
-237                                    final Message message = prepareMessage(email, messageRoot);
-238                                    logSession(session, transportStrategy);
-239                                    message.saveChanges(); // some headers and id's will be set for this specific message
-240                                    Transport transport = session.getTransport();
-241                                    transport.connect();
-242                                    transport.sendMessage(message, message.getAllRecipients());
-243                                    transport.close();
-244                            } catch (final UnsupportedEncodingException e) {
-245                                    logger.error(e.getMessage(), e);
-246                                    throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
-247                            } catch (final MessagingException e) {
-248                                    logger.error(e.getMessage(), e);
-249                                    throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
-250                            }
-251                    }
-252            }
-253    
-254            /**
-255             * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
-256             */
-257            private void logSession(Session session, TransportStrategy transportStrategy) {
-258                    final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
-259                    Properties properties = session.getProperties();
-260                    logger.debug(String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
-261                                    properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
-262                                    properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy));
-263            }
-264    
-265            /**
-266             * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
-267             * 
-268             * @param email The email that needs to be configured correctly.
-269             * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
-270             * @throws MailException Is being thrown in any of the above causes.
-271             * @see EmailValidationUtil
-272             */
-273            public boolean validate(final Email email)
-274                            throws MailException {
-275                    if (email.getText() == null && email.getTextHTML() == null) {
-276                            throw new MailException(MailException.MISSING_CONTENT);
-277                    } else if (email.getSubject() == null || email.getSubject().equals("")) {
-278                            throw new MailException(MailException.MISSING_SUBJECT);
-279                    } else if (email.getRecipients().size() == 0) {
-280                            throw new MailException(MailException.MISSING_RECIPIENT);
-281                    } else if (email.getFromRecipient() == null) {
-282                            throw new MailException(MailException.MISSING_SENDER);
-283                    } else {
-284                            if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
-285                                    throw new MailException(String.format(MailException.INVALID_SENDER, email));
-286                            }
-287                            for (final Recipient recipient : email.getRecipients()) {
-288                                    if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
-289                                            throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
-290                                    }
-291                            }
-292                            if (email.getReplyToRecipient() != null) {
-293                                    if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
-294                                            throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
-295                                    }
-296                            }
-297                    }
-298                    return true;
-299            }
-300    
-301            /**
-302             * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
-303             * <p>
-304             * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
-305             * 
-306             * @param email The email message from which the subject and From-address are extracted.
-307             * @param messageRoot The root of the email which holds everything (filled with some email data).
-308             * @return A fully preparated {@link Message} instance, ready to be sent.
-309             * @throws MessagingException Kan gegooid worden als het message niet goed behandelt wordt.
-310             * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
-311             */
-312            private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
-313                            throws MessagingException, UnsupportedEncodingException {
-314                    final MimeMessage message = new MimeMessage(session);
-315                    // set basic email properties
-316                    message.setSubject(email.getSubject(), CHARACTER_ENCODING);
-317                    message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
-318                    setReplyTo(email, message);
-319                    setRecipients(email, message);
-320                    // fill multipart structure
-321                    setTexts(email, messageRoot.multipartAlternativeMessages);
-322                    setEmbeddedImages(email, messageRoot.multipartRelated);
-323                    setAttachments(email, messageRoot.multipartRoot);
-324                    message.setContent(messageRoot.multipartRoot);
-325                    setHeaders(email, message);
-326                    message.setSentDate(new Date());
-327                    return message;
-328            }
-329    
-330            /**
-331             * Fills the {@link Message} instance with recipients from the {@link Email}.
-332             * 
-333             * @param email The message in which the recipients are defined.
-334             * @param message The javax message that needs to be filled with recipients.
-335             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-336             * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
-337             */
-338            private void setRecipients(final Email email, final Message message)
-339                            throws UnsupportedEncodingException, MessagingException {
-340                    for (final Recipient recipient : email.getRecipients()) {
-341                            final Address address = new InternetAddress(recipient.getAddress(), recipient.getName());
-342                            message.addRecipient(recipient.getType(), address);
-343                    }
-344            }
-345    
-346            /**
-347             * Fills the {@link Message} instance with reply-to address.
-348             * 
-349             * @param email The message in which the recipients are defined.
-350             * @param message The javax message that needs to be filled with reply-to address.
-351             * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
-352             * @throws MessagingException See {@link Message#setReplyTo(Address[])}
-353             */
-354            private void setReplyTo(final Email email, final Message message)
-355                            throws UnsupportedEncodingException, MessagingException {
-356                    final Recipient replyToRecipient = email.getReplyToRecipient();
-357                    if (replyToRecipient != null) {
-358                            InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(), CHARACTER_ENCODING);
-359                            message.setReplyTo(new Address[] { replyToAddress });
-360                    }
-361            }
-362    
-363            /**
-364             * Fills the {@link Message} instance with the content bodies (text and html).
-365             * 
-366             * @param email The message in which the content is defined.
-367             * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
-368             * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
-369             *             {@link MimeMultipart#addBodyPart(BodyPart)}.
-370             */
-371            private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
-372                            throws MessagingException {
-373                    if (email.getText() != null) {
-374                            final MimeBodyPart messagePart = new MimeBodyPart();
-375                            messagePart.setText(email.getText(), CHARACTER_ENCODING);
-376                            multipartAlternativeMessages.addBodyPart(messagePart);
-377                    }
-378                    if (email.getTextHTML() != null) {
-379                            final MimeBodyPart messagePartHTML = new MimeBodyPart();
-380                            messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
-381                            multipartAlternativeMessages.addBodyPart(messagePartHTML);
-382                    }
-383            }
-384    
-385            /**
-386             * Fills the {@link Message} instance with the embedded images from the {@link Email}.
-387             * 
-388             * @param email The message in which the embedded images are defined.
-389             * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
-390             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-391             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-392             */
-393            private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
-394                            throws MessagingException {
-395                    for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
-396                            multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
-397                    }
-398            }
-399    
-400            /**
-401             * Fills the {@link Message} instance with the attachments from the {@link Email}.
-402             * 
-403             * @param email The message in which the attachments are defined.
-404             * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
-405             * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
-406             *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
-407             */
-408            private void setAttachments(final Email email, final MimeMultipart multipartRoot)
-409                            throws MessagingException {
-410                    for (final AttachmentResource resource : email.getAttachments()) {
-411                            multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
-412                    }
-413            }
-414    
-415            /**
-416             * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
-417             * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
-418             * 
-419             * @param email The message in which the headers are defined.
-420             * @param message The {@link Message} on which to set the raw, encoded and folded headers.
-421             * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
-422             * @throws MessagingException See {@link Message#addHeader(String, String)}
-423             * @see {@link MimeUtility#encodeText(String, String, String)}
-424             * @see MimeUtility#fold(int, String)
-425             */
-426            private void setHeaders(final Email email, final Message message)
-427                            throws UnsupportedEncodingException, MessagingException {
-428                    // add headers (for raw message headers we need to 'fold' them using MimeUtility
-429                    for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
-430                            String headerName = header.getKey();
-431                            String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
-432                            String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
-433                            message.addHeader(header.getKey(), foldedHeaderValue);
-434                    }
-435            }
-436    
-437            /**
-438             * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
-439             * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
-440             * email structure. <br />
-441             * <br />
-442             * For every attachment and embedded image a header needs to be set.
-443             * 
-444             * @param resource An object that describes the attachment and contains the actual content data.
-445             * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
-446             * @return An object with the attachment data read for placement in the email structure.
-447             * @throws MessagingException All BodyPart setters.
-448             */
-449            private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
-450                            throws MessagingException {
-451                    final BodyPart attachmentPart = new MimeBodyPart();
-452                    final DataSource ds = resource.getDataSource();
-453                    // setting headers isn't working nicely using the javax mail API, so let's do that manually
-454                    attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
-455                    attachmentPart.setFileName(resource.getName());
-456                    attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
-457                    attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
-458                    attachmentPart.setDisposition(dispositionType + "; size=0");
-459                    return attachmentPart;
-460            }
-461    
-462            /**
-463             * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
-464             * ultimately sent using JavaMail.<br />
-465             * <br />
-466             * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
-467             * 
-468             * <pre>
-469             * - root
-470             *      - related
-471             *              - alternative
-472             *                      - mail tekst
-473             *                      - mail html tekst
-474             *              - embedded images
-475             *      - attachments
-476             * </pre>
-477             * 
-478             * @author Benny Bottema
-479             */
-480            private class MimeEmailMessageWrapper {
-481    
-482                    private final MimeMultipart multipartRoot;
-483    
-484                    private final MimeMultipart multipartRelated;
-485    
-486                    private final MimeMultipart multipartAlternativeMessages;
-487    
-488                    /**
-489                     * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
-490                     */
-491                    MimeEmailMessageWrapper() {
-492                            multipartRoot = new MimeMultipart("mixed");
-493                            final MimeBodyPart contentRelated = new MimeBodyPart();
-494                            multipartRelated = new MimeMultipart("related");
-495                            final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
-496                            multipartAlternativeMessages = new MimeMultipart("alternative");
-497                            try {
-498                                    // construct mail structure
-499                                    multipartRoot.addBodyPart(contentRelated);
-500                                    contentRelated.setContent(multipartRelated);
-501                                    multipartRelated.addBodyPart(contentAlternativeMessages);
-502                                    contentAlternativeMessages.setContent(multipartAlternativeMessages);
-503                            } catch (final MessagingException e) {
-504                                    logger.error(e.getMessage(), e);
-505                                    throw new RuntimeException(e.getMessage(), e);
-506                            }
-507                    }
-508            }
-509    
-510            /**
-511             * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
-512             * instance.
-513             * 
-514             * @param emailAddressValidationCriteria Refer to
-515             *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
-516             */
-517            public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
-518                    this.emailAddressValidationCriteria = emailAddressValidationCriteria;
-519            }
-520    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.io.UnsupportedEncodingException;
+004import java.util.Date;
+005import java.util.Map;
+006import java.util.Properties;
+007
+008import javax.activation.DataHandler;
+009import javax.activation.DataSource;
+010import javax.mail.Address;
+011import javax.mail.Authenticator;
+012import javax.mail.BodyPart;
+013import javax.mail.Message;
+014import javax.mail.MessagingException;
+015import javax.mail.Part;
+016import javax.mail.PasswordAuthentication;
+017import javax.mail.Session;
+018import javax.mail.Transport;
+019import javax.mail.internet.InternetAddress;
+020import javax.mail.internet.MimeBodyPart;
+021import javax.mail.internet.MimeMessage;
+022import javax.mail.internet.MimeMultipart;
+023import javax.mail.internet.MimeUtility;
+024
+025import org.slf4j.Logger;
+026import org.slf4j.LoggerFactory;
+027
+028/**
+029 * Mailing tool aimed for simplicity, for sending e-mails of any complexity. This includes e-mails with plain text and/or html content,
+030 * embedded images and separate attachments, SMTP, SMTPS / SSL and SMTP + SSL<br>
+031 * <br>
+032 * This mailing tool abstracts the javax.mail API to a higher level easy to use API. For public use, this tool only works with {@link Email}
+033 * instances. <br>
+034 * <br>
+035 * The e-mail message structure is built to work with all e-mail clients and has been tested with many different webclients as well as some
+036 * mainstream client applications such as MS Outlook or Mozilla Thunderbird.<br>
+037 * <br>
+038 * Technically, the resulting email structure is as follows:<br>
+039 * 
+040 * <pre>
+041 * - root
+042 *      - related
+043 *              - alternative
+044 *                      - mail text
+045 *                      - mail html text
+046 *              - embedded images
+047 *      - attachments
+048 * </pre>
+049 * 
+050 * <br>
+051 * Usage example:<br>
+052 * 
+053 * <pre>
+054 * Email email = new Email();
+055 * email.setFromAddress(&quot;lollypop&quot;, &quot;lolly.pop@somemail.com&quot;);
+056 * email.addRecipient(&quot;Sugar Cane&quot;, &quot;sugar.cane@candystore.org&quot;, RecipientType.TO);
+057 * email.setText(&quot;We should meet up!!&quot;);
+058 * email.setTextHTML(&quot;&lt;b&gt;We should meet up!&lt;/b&gt;&quot;);
+059 * email.setSubject(&quot;Hey&quot;);
+060 * new Mailer(preconfiguredMailSession).sendMail(email);
+061 * // or:
+062 * new Mailer(&quot;smtp.someserver.com&quot;, 25, &quot;username&quot;, &quot;password&quot;).sendMail(email);
+063 * </pre>
+064 * 
+065 * @author Benny Bottema
+066 * @see MimeEmailMessageWrapper
+067 * @see Email
+068 */
+069public class Mailer {
+070
+071        private static final Logger logger = LoggerFactory.getLogger(Mailer.class);
+072
+073        /**
+074         * Encoding used for setting body text, email address, headers, reply-to fields etc. ({@value #CHARACTER_ENCODING}).
+075         */
+076        private static final String CHARACTER_ENCODING = "UTF-8";
+077
+078        /**
+079         * Used to actually send the email. This session can come from being passed in the default constructor, or made by <code>Mailer</code>
+080         * directly, when no <code>Session</code> instance was provided.
+081         * 
+082         * @see #Mailer(Session)
+083         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+084         */
+085        private final Session session;
+086
+087        /**
+088         * The transport protocol strategy enum that actually handles the session configuration. Session configuration meaning setting the right
+089         * properties for the appropriate transport type (ie. <em>"mail.smtp.host"</em> for SMTP, <em>"mail.smtps.host"</em> for SMTPS).
+090         */
+091        private TransportStrategy transportStrategy;
+092
+093        /**
+094         * Email address restriction flags set either by constructor or overridden by getter by user.
+095         * 
+096         * @see EmailAddressValidationCriteria
+097         */
+098        private EmailAddressValidationCriteria emailAddressValidationCriteria;
+099
+100        /**
+101         * Default constructor, stores the given mail session for later use. Assumes that *all* properties used to make a connection are
+102         * configured (host, port, authentication and transport protocol settings).
+103         * <p>
+104         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+105         * smtp server instead.
+106         * 
+107         * @param session A preconfigured mail {@link Session} object with which a {@link Message} can be produced.
+108         */
+109        public Mailer(final Session session) {
+110                this.session = session;
+111                this.emailAddressValidationCriteria = null;
+112        }
+113
+114        /**
+115         * Overloaded constructor which produces a new {@link Session} on the fly. Use this if you don't have a mail session configured in your
+116         * web container, or Spring context etc.
+117         * <p>
+118         * Also leaves email address validation criteria empty so that no validation is being performed. Validation errors will come from the
+119         * smtp server instead.
+120         * 
+121         * @param host The address URL of the SMTP server to be used.
+122         * @param port The port of the SMTP server.
+123         * @param username An optional username, may be <code>null</code>.
+124         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+125         * @param transportStrategy The transport protocol configuration type for handling SSL or TLS (or vanilla SMTP)
+126         */
+127        public Mailer(final String host, final Integer port, final String username, final String password,
+128                        final TransportStrategy transportStrategy) {
+129                // we're doing these validations manually instead of using Apache Commons to avoid another dependency
+130                if (host == null || host.trim().equals("")) {
+131                        throw new MailException(MailException.MISSING_HOST);
+132                } else if ((password != null && !password.trim().equals("")) && (username == null || username.trim().equals(""))) {
+133                        throw new MailException(MailException.MISSING_USERNAME);
+134                }
+135                this.transportStrategy = transportStrategy;
+136                this.session = createMailSession(host, port, username, password);
+137                this.emailAddressValidationCriteria = null;
+138        }
+139
+140        /**
+141         * Actually instantiates and configures the {@link Session} instance. Delegates resolving transport protocol specific properties to the
+142         * {@link #transportStrategy} in two ways:
+143         * <ol>
+144         * <li>request an initial property list which the strategy may pre-populate</li>
+145         * <li>by requesting the property names according to the respective transport protocol it handles (for the host property for example it
+146         * would be <em>"mail.smtp.host"</em> for SMTP and <em>"mail.smtps.host"</em> for SMTPS)</li>
+147         * </ol>
+148         * 
+149         * @param host The address URL of the SMTP server to be used.
+150         * @param port The port of the SMTP server.
+151         * @param username An optional username, may be <code>null</code>.
+152         * @param password An optional password, may be <code>null</code>.
+153         * @return A fully configured <code>Session</code> instance complete with transport protocol settings.
+154         * @see TransportStrategy#generateProperties()
+155         * @see TransportStrategy#propertyNameHost()
+156         * @see TransportStrategy#propertyNamePort()
+157         * @see TransportStrategy#propertyNameUsername()
+158         * @see TransportStrategy#propertyNameAuthenticate()
+159         */
+160        protected Session createMailSession(final String host, final Integer port, final String username, final String password) {
+161                if (transportStrategy == null) {
+162                        logger.warn("Transport Strategy not set, using plain SMTP strategy instead!");
+163                        transportStrategy = TransportStrategy.SMTP_PLAIN;
+164                }
+165                Properties props = transportStrategy.generateProperties();
+166                props.put(transportStrategy.propertyNameHost(), host);
+167                if (port != null) {
+168                        props.put(transportStrategy.propertyNamePort(), String.valueOf(port));
+169                } else {
+170                        // let JavaMail's Transport objects determine deault port base don the used protocol
+171                }
+172
+173                if (username != null) {
+174                        props.put(transportStrategy.propertyNameUsername(), username);
+175                }
+176
+177                if (password != null) {
+178                        props.put(transportStrategy.propertyNameAuthenticate(), "true");
+179                        return Session.getInstance(props, new Authenticator() {
+180                                @Override
+181                                protected PasswordAuthentication getPasswordAuthentication() {
+182                                        return new PasswordAuthentication(username, password);
+183                                }
+184                        });
+185                } else {
+186                        return Session.getInstance(props);
+187                }
+188        }
+189
+190        /**
+191         * Overloaded constructor which produces a new {@link Session} on the fly, using default vanilla SMTP transport protocol.
+192         * 
+193         * @param host The address URL of the SMTP server to be used.
+194         * @param port The port of the SMTP server.
+195         * @param username An optional username, may be <code>null</code>.
+196         * @param password An optional password, may be <code>null</code>, but only if username is <code>null</code> as well.
+197         * @see #Mailer(String, Integer, String, String, TransportStrategy)
+198         */
+199        public Mailer(final String host, final Integer port, final String username, final String password) {
+200                this(host, port, username, password, TransportStrategy.SMTP_PLAIN);
+201        }
+202
+203        /**
+204         * In case Simple Java Mail falls short somehow, you can get a hold of the internal {@link Session} instance to debug or tweak. Please
+205         * let us know why you are needing this on https://github.com/bbottema/simple-java-mail/issues.
+206         */
+207        public Session getSession() {
+208                logger.warn("Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it.");
+209                logger.warn("\t>https://github.com/bbottema/simple-java-mail/issues");
+210                return session;
+211        }
+212
+213        /**
+214         * Actually sets {@link Session#setDebug(boolean)} so that it generates debug information.
+215         * 
+216         * @param debug Flag to indicate debug mode yes/no.
+217         */
+218        public void setDebug(final boolean debug) {
+219                session.setDebug(debug);
+220        }
+221
+222        /**
+223         * Copies all property entries into the {@link Session} using {@link Session#getProperties()}.
+224         * 
+225         * @param properties The source properties to add or override in the internal {@link Session} instance.
+226         */
+227        public void applyProperties(final Properties properties) {
+228                session.getProperties().putAll(properties);
+229        }
+230
+231        /**
+232         * Processes an {@link Email} instance into a completely configured {@link Message}.
+233         * <p>
+234         * Sends the Sun JavaMail {@link Message} object using {@link Session#getTransport()}. It will call {@link Transport#connect()} assuming
+235         * all connection details have been configured in the provided {@link Session} instance.
+236         * <p>
+237         * Performs a call to {@link Message#saveChanges()} as the Sun JavaMail API indicates it is needed to configure the message headers and
+238         * providing a message id.
+239         * 
+240         * @param email The information for the email to be sent.
+241         * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending
+242         *             etc.
+243         * @see #validate(Email)
+244         * @see #prepareMessage(Email, MimeEmailMessageWrapper)
+245         * @see #setRecipients(Email, Message)
+246         * @see #setTexts(Email, MimeMultipart)
+247         * @see #setEmbeddedImages(Email, MimeMultipart)
+248         * @see #setAttachments(Email, MimeMultipart)
+249         */
+250        public final void sendMail(final Email email)
+251                        throws MailException {
+252                if (validate(email)) {
+253                        try {
+254                                // create new wrapper for each mail being sent (enable sending multiple emails with one mailer)
+255                                final MimeEmailMessageWrapper messageRoot = new MimeEmailMessageWrapper();
+256                                // fill and send wrapped mime message parts
+257                                final Message message = prepareMessage(email, messageRoot);
+258                                logSession(session, transportStrategy);
+259                                message.saveChanges(); // some headers and id's will be set for this specific message
+260                                Transport transport = session.getTransport();
+261                                transport.connect();
+262                                transport.sendMessage(message, message.getAllRecipients());
+263                                transport.close();
+264                        } catch (final UnsupportedEncodingException e) {
+265                                logger.error(e.getMessage(), e);
+266                                throw new MailException(String.format(MailException.INVALID_ENCODING, e.getMessage()));
+267                        } catch (final MessagingException e) {
+268                                logger.error(e.getMessage(), e);
+269                                throw new MailException(String.format(MailException.GENERIC_ERROR, e.getMessage()), e);
+270                        }
+271                }
+272        }
+273
+274        /**
+275         * Simply logs host details, credentials used and whether authentication will take place and finally the transport protocol used.
+276         */
+277        private void logSession(Session session, TransportStrategy transportStrategy) {
+278                Properties properties = session.getProperties();
+279                final String specifics;
+280                if (transportStrategy != null) {
+281                        final String logmsg = "starting mail session (host: %s, port: %s, username: %s, authenticate: %s, transport: %s)";
+282                        specifics = String.format(logmsg, properties.get(transportStrategy.propertyNameHost()),
+283                                        properties.get(transportStrategy.propertyNamePort()), properties.get(transportStrategy.propertyNameUsername()),
+284                                        properties.get(transportStrategy.propertyNameAuthenticate()), transportStrategy);
+285                } else {
+286                        specifics = properties.toString();
+287                }
+288                logger.debug(String.format("starting mail session (%s)", specifics));
+289        }
+290
+291        /**
+292         * Validates an {@link Email} instance. Validation fails if the subject is missing, content is missing, or no recipients are defined.
+293         * 
+294         * @param email The email that needs to be configured correctly.
+295         * @return Always <code>true</code> (throws a {@link MailException} exception if validation fails).
+296         * @throws MailException Is being thrown in any of the above causes.
+297         * @see EmailValidationUtil
+298         */
+299        public boolean validate(final Email email)
+300                        throws MailException {
+301                if (email.getText() == null && email.getTextHTML() == null) {
+302                        throw new MailException(MailException.MISSING_CONTENT);
+303                } else if (email.getSubject() == null || email.getSubject().equals("")) {
+304                        throw new MailException(MailException.MISSING_SUBJECT);
+305                } else if (email.getRecipients().size() == 0) {
+306                        throw new MailException(MailException.MISSING_RECIPIENT);
+307                } else if (email.getFromRecipient() == null) {
+308                        throw new MailException(MailException.MISSING_SENDER);
+309                } else if (emailAddressValidationCriteria != null) {
+310                        if (!EmailValidationUtil.isValid(email.getFromRecipient().getAddress(), emailAddressValidationCriteria)) {
+311                                throw new MailException(String.format(MailException.INVALID_SENDER, email));
+312                        }
+313                        for (final Recipient recipient : email.getRecipients()) {
+314                                if (!EmailValidationUtil.isValid(recipient.getAddress(), emailAddressValidationCriteria)) {
+315                                        throw new MailException(String.format(MailException.INVALID_RECIPIENT, email));
+316                                }
+317                        }
+318                        if (email.getReplyToRecipient() != null) {
+319                                if (!EmailValidationUtil.isValid(email.getReplyToRecipient().getAddress(), emailAddressValidationCriteria)) {
+320                                        throw new MailException(String.format(MailException.INVALID_REPLYTO, email));
+321                                }
+322                        }
+323                }
+324                return true;
+325        }
+326
+327        /**
+328         * Creates a new {@link MimeMessage} instance and prepares it in the email structure, so that it can be filled and send.
+329         * <p>
+330         * Fills subject, from,reply-to, content, sent-date, recipients, texts, embedded images, attachments, content and adds all headers.
+331         * 
+332         * @param email The email message from which the subject and From-address are extracted.
+333         * @param messageRoot The root of the email which holds everything (filled with some email data).
+334         * @return A fully preparated {@link Message} instance, ready to be sent.
+335         * @throws MessagingException May be thrown when the message couldn't be processed by JavaMail.
+336         * @throws UnsupportedEncodingException Zie {@link InternetAddress#InternetAddress(String, String)}.
+337         */
+338        private Message prepareMessage(final Email email, final MimeEmailMessageWrapper messageRoot)
+339                        throws MessagingException, UnsupportedEncodingException {
+340                final MimeMessage message = new MimeMessage(session);
+341                // set basic email properties
+342                message.setSubject(email.getSubject(), CHARACTER_ENCODING);
+343                message.setFrom(new InternetAddress(email.getFromRecipient().getAddress(), email.getFromRecipient().getName(), CHARACTER_ENCODING));
+344                setReplyTo(email, message);
+345                setRecipients(email, message);
+346                // fill multipart structure
+347                setTexts(email, messageRoot.multipartAlternativeMessages);
+348                setEmbeddedImages(email, messageRoot.multipartRelated);
+349                setAttachments(email, messageRoot.multipartRoot);
+350                message.setContent(messageRoot.multipartRoot);
+351                setHeaders(email, message);
+352                message.setSentDate(new Date());
+353                return message;
+354        }
+355
+356        /**
+357         * Fills the {@link Message} instance with recipients from the {@link Email}.
+358         * 
+359         * @param email The message in which the recipients are defined.
+360         * @param message The javax message that needs to be filled with recipients.
+361         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+362         * @throws MessagingException See {@link Message#addRecipient(javax.mail.Message.RecipientType, Address)}
+363         */
+364        private void setRecipients(final Email email, final Message message)
+365                        throws UnsupportedEncodingException, MessagingException {
+366                for (final Recipient recipient : email.getRecipients()) {
+367                        final Address address = new InternetAddress(recipient.getAddress(), recipient.getName(), CHARACTER_ENCODING);
+368                        message.addRecipient(recipient.getType(), address);
+369                }
+370        }
+371
+372        /**
+373         * Fills the {@link Message} instance with reply-to address.
+374         * 
+375         * @param email The message in which the recipients are defined.
+376         * @param message The javax message that needs to be filled with reply-to address.
+377         * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
+378         * @throws MessagingException See {@link Message#setReplyTo(Address[])}
+379         */
+380        private void setReplyTo(final Email email, final Message message)
+381                        throws UnsupportedEncodingException, MessagingException {
+382                final Recipient replyToRecipient = email.getReplyToRecipient();
+383                if (replyToRecipient != null) {
+384                        InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(),
+385                                        CHARACTER_ENCODING);
+386                        message.setReplyTo(new Address[] { replyToAddress });
+387                }
+388        }
+389
+390        /**
+391         * Fills the {@link Message} instance with the content bodies (text and html).
+392         * 
+393         * @param email The message in which the content is defined.
+394         * @param multipartAlternativeMessages See {@link MimeMultipart#addBodyPart(BodyPart)}
+395         * @throws MessagingException See {@link BodyPart#setText(String)}, {@link BodyPart#setContent(Object, String)} and
+396         *             {@link MimeMultipart#addBodyPart(BodyPart)}.
+397         */
+398        private void setTexts(final Email email, final MimeMultipart multipartAlternativeMessages)
+399                        throws MessagingException {
+400                if (email.getText() != null) {
+401                        final MimeBodyPart messagePart = new MimeBodyPart();
+402                        messagePart.setText(email.getText(), CHARACTER_ENCODING);
+403                        multipartAlternativeMessages.addBodyPart(messagePart);
+404                }
+405                if (email.getTextHTML() != null) {
+406                        final MimeBodyPart messagePartHTML = new MimeBodyPart();
+407                        messagePartHTML.setContent(email.getTextHTML(), "text/html; charset=\"" + CHARACTER_ENCODING + "\"");
+408                        multipartAlternativeMessages.addBodyPart(messagePartHTML);
+409                }
+410        }
+411
+412        /**
+413         * Fills the {@link Message} instance with the embedded images from the {@link Email}.
+414         * 
+415         * @param email The message in which the embedded images are defined.
+416         * @param multipartRelated The branch in the email structure in which we'll stuff the embedded images.
+417         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+418         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+419         */
+420        private void setEmbeddedImages(final Email email, final MimeMultipart multipartRelated)
+421                        throws MessagingException {
+422                for (final AttachmentResource embeddedImage : email.getEmbeddedImages()) {
+423                        multipartRelated.addBodyPart(getBodyPartFromDatasource(embeddedImage, Part.INLINE));
+424                }
+425        }
+426
+427        /**
+428         * Fills the {@link Message} instance with the attachments from the {@link Email}.
+429         * 
+430         * @param email The message in which the attachments are defined.
+431         * @param multipartRoot The branch in the email structure in which we'll stuff the attachments.
+432         * @throws MessagingException See {@link MimeMultipart#addBodyPart(BodyPart)} and
+433         *             {@link #getBodyPartFromDatasource(AttachmentResource, String)}
+434         */
+435        private void setAttachments(final Email email, final MimeMultipart multipartRoot)
+436                        throws MessagingException {
+437                for (final AttachmentResource resource : email.getAttachments()) {
+438                        multipartRoot.addBodyPart(getBodyPartFromDatasource(resource, Part.ATTACHMENT));
+439                }
+440        }
+441
+442        /**
+443         * Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we
+444         * need to do some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
+445         * 
+446         * @param email The message in which the headers are defined.
+447         * @param message The {@link Message} on which to set the raw, encoded and folded headers.
+448         * @throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
+449         * @throws MessagingException See {@link Message#addHeader(String, String)}
+450         * @see {@link MimeUtility#encodeText(String, String, String)}
+451         * @see MimeUtility#fold(int, String)
+452         */
+453        private void setHeaders(final Email email, final Message message)
+454                        throws UnsupportedEncodingException, MessagingException {
+455                // add headers (for raw message headers we need to 'fold' them using MimeUtility
+456                for (Map.Entry<String, String> header : email.getHeaders().entrySet()) {
+457                        String headerName = header.getKey();
+458                        String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
+459                        String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
+460                        message.addHeader(header.getKey(), foldedHeaderValue);
+461                }
+462        }
+463
+464        /**
+465         * Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition
+466         * type ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the
+467         * email structure. <br>
+468         * <br>
+469         * For every attachment and embedded image a header needs to be set.
+470         * 
+471         * @param resource An object that describes the attachment and contains the actual content data.
+472         * @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
+473         * @return An object with the attachment data read for placement in the email structure.
+474         * @throws MessagingException All BodyPart setters.
+475         */
+476        private BodyPart getBodyPartFromDatasource(final AttachmentResource resource, final String dispositionType)
+477                        throws MessagingException {
+478                final BodyPart attachmentPart = new MimeBodyPart();
+479                final DataSource ds = resource.getDataSource();
+480                // setting headers isn't working nicely using the javax mail API, so let's do that manually
+481                attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
+482                attachmentPart.setFileName(resource.getName());
+483                attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
+484                attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
+485                attachmentPart.setDisposition(dispositionType + "; size=0");
+486                return attachmentPart;
+487        }
+488
+489        /**
+490         * This class conveniently wraps all necessary mimemessage parts that need to be filled with content, attachments etc. The root is
+491         * ultimately sent using JavaMail.<br>
+492         * <br>
+493         * The constructor creates a new email message constructed from {@link MimeMultipart} as follows:
+494         * 
+495         * <pre>
+496         * - root
+497         *      - related
+498         *              - alternative
+499         *                      - mail tekst
+500         *                      - mail html tekst
+501         *              - embedded images
+502         *      - attachments
+503         * </pre>
+504         * 
+505         * @author Benny Bottema
+506         */
+507        private class MimeEmailMessageWrapper {
+508
+509                private final MimeMultipart multipartRoot;
+510
+511                private final MimeMultipart multipartRelated;
+512
+513                private final MimeMultipart multipartAlternativeMessages;
+514
+515                /**
+516                 * Creates an email skeleton structure, so that embedded images, attachments and (html) texts are being processed properly.
+517                 */
+518                MimeEmailMessageWrapper() {
+519                        multipartRoot = new MimeMultipart("mixed");
+520                        final MimeBodyPart contentRelated = new MimeBodyPart();
+521                        multipartRelated = new MimeMultipart("related");
+522                        final MimeBodyPart contentAlternativeMessages = new MimeBodyPart();
+523                        multipartAlternativeMessages = new MimeMultipart("alternative");
+524                        try {
+525                                // construct mail structure
+526                                multipartRoot.addBodyPart(contentRelated);
+527                                contentRelated.setContent(multipartRelated);
+528                                multipartRelated.addBodyPart(contentAlternativeMessages);
+529                                contentAlternativeMessages.setContent(multipartAlternativeMessages);
+530                        } catch (final MessagingException e) {
+531                                logger.error(e.getMessage(), e);
+532                                throw new RuntimeException(e.getMessage(), e);
+533                        }
+534                }
+535        }
+536
+537        /**
+538         * Overrides the default email address validation restrictions when validating and sending emails using the current <code>Mailer</code>
+539         * instance. By default no validation will be performed by simple-java-mail, until a criteria object has been set.
+540         * 
+541         * @param emailAddressValidationCriteria Refer to
+542         *            {@link EmailAddressValidationCriteria#EmailAddressValidationCriteria(boolean, boolean)}.
+543         */
+544        public void setEmailAddressValidationCriteria(EmailAddressValidationCriteria emailAddressValidationCriteria) {
+545                this.emailAddressValidationCriteria = emailAddressValidationCriteria;
+546        }
+547}
 
 
 
@@ -581,6 +613,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/Recipient.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/Recipient.html index c2e9e25fe..392bbb983 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/Recipient.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/Recipient.html @@ -1,58 +1,63 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import javax.mail.Message.RecipientType;
-004    
-005    /**
-006     * An immutable recipient object, with a name, emailadres and recipient type (eg {@link RecipientType#BCC}).
-007     * 
-008     * @author Benny Bottema
-009     */
-010    public final class Recipient {
-011    
-012            private final String name;
-013    
-014            private final String address;
-015    
-016            private final RecipientType type;
-017    
-018            /**
-019             * Constructor; initializes this recipient object.
-020             * 
-021             * @param name The name of the recipient.
-022             * @param address The email address of the recipient.
-023             * @param type The recipient type (eg. {@link RecipientType#TO}).
-024             * @see RecipientType
-025             */
-026            public Recipient(final String name, final String address, final RecipientType type) {
-027                    this.name = name;
-028                    this.address = address;
-029                    this.type = type;
-030            }
-031    
-032            /**
-033             * Bean getter for {@link #name};
-034             */
-035            public String getName() {
-036                    return name;
-037            }
-038    
-039            /**
-040             * Bean getter for {@link #address};
-041             */
-042            public String getAddress() {
-043                    return address;
-044            }
-045    
-046            /**
-047             * Bean getter for {@link #type};
-048             */
-049            public RecipientType getType() {
-050                    return type;
-051            }
-052    }
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import javax.mail.Message.RecipientType;
+004
+005/**
+006 * An immutable recipient object, with a name, emailadres and recipient type (eg {@link RecipientType#BCC}).
+007 * 
+008 * @author Benny Bottema
+009 */
+010public final class Recipient {
+011
+012        private final String name;
+013
+014        private final String address;
+015
+016        private final RecipientType type;
+017
+018        /**
+019         * Constructor; initializes this recipient object.
+020         * 
+021         * @param name The name of the recipient.
+022         * @param address The email address of the recipient.
+023         * @param type The recipient type (eg. {@link RecipientType#TO}).
+024         * @see RecipientType
+025         */
+026        public Recipient(final String name, final String address, final RecipientType type) {
+027                this.name = name;
+028                this.address = address;
+029                this.type = type;
+030        }
+031
+032        /**
+033         * Bean getter for {@link #name};
+034         */
+035        public String getName() {
+036                return name;
+037        }
+038
+039        /**
+040         * Bean getter for {@link #address};
+041         */
+042        public String getAddress() {
+043                return address;
+044        }
+045
+046        /**
+047         * Bean getter for {@link #type};
+048         */
+049        public RecipientType getType() {
+050                return type;
+051        }
+052}
 
 
 
@@ -113,6 +118,7 @@
 
 
 
-
- - +
+ + + diff --git a/javadoc/users/src-html/org/codemonkey/simplejavamail/TransportStrategy.html b/javadoc/users/src-html/org/codemonkey/simplejavamail/TransportStrategy.html index e5b7a7f46..55bd0bdbb 100644 --- a/javadoc/users/src-html/org/codemonkey/simplejavamail/TransportStrategy.html +++ b/javadoc/users/src-html/org/codemonkey/simplejavamail/TransportStrategy.html @@ -1,204 +1,209 @@ - - -
-001    package org.codemonkey.simplejavamail;
-002    
-003    import java.util.Properties;
-004    
-005    import javax.mail.Session;
-006    
-007    /**
-008     * Defines the various types of transport protocols and implements respective properties so that a {@link Session} may be configured using a
-009     * <code>TransportStrategy</code> implementation.
-010     * 
-011     * @author Benny Bottema
-012     */
-013    public enum TransportStrategy {
-014    
-015            /**
-016             * Simplest possible form: only vanilla ".smtp." property names and no extra properties. Additionally the transport protocol is
-017             * explicitly set to smtp.
-018             */
-019            SMTP_PLAIN {
-020                    /**
-021                     * Here protocol "mail.transport.protocol" is set to "smtp".
-022                     * 
-023                     * @see TransportStrategy#SMTP_PLAIN
-024                     */
-025                    @Override
-026                    public Properties generateProperties() {
-027                            final Properties props = super.generateProperties();
-028                            props.put("mail.transport.protocol", "smtp");
-029                            return props;
-030                    };
-031    
-032                    /**
-033                     * @return "mail.smtp.host"
-034                     */
-035                    @Override
-036                    String propertyNameHost() {
-037                            return "mail.smtp.host";
-038                    };
-039    
-040                    /**
-041                     * @return "mail.smtp.port"
-042                     */
-043                    @Override
-044                    String propertyNamePort() {
-045                            return "mail.smtp.port";
-046                    };
-047    
-048                    /**
-049                     * @return "mail.smtp.username"
-050                     */
-051                    @Override
-052                    String propertyNameUsername() {
-053                            return "mail.smtp.username";
-054                    };
-055    
-056                    /**
-057                     * @return "mail.smtp.auth"
-058                     */
-059                    @Override
-060                    String propertyNameAuthenticate() {
-061                            return "mail.smtp.auth";
-062                    };
-063            },
-064            /**
-065             * SMTPS / SSL transport strategy, that returns the ".smtps." variation of the SMTP_PLAIN version. Additionally the transport protocol
-066             * is explicitly set to smtps. Finally, he property "mail.smtps.quitwait" is set to false, to get rid of a strange SSL exception:<br />
-067             * 
-068             * <pre>
-069             * javax.mail.MessagingException: Exception reading response;
-070             * nested exception is:
-071             *      javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
-072             * (..)
-073             * </pre>
-074             * 
-075             * <quote>The mail is sent but the exception is unwanted. The property <em>quitwait</em> means If set to false, the QUIT command is sent
-076             * and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT
-077             * command</quote><br />
-078             * <strong>- <a href="http://www.rgagnon.com/javadetails/java-0570.html">source</a></strong>
-079             */
-080            SMTP_SSL {
-081                    /**
-082                     * Here protocol "mail.transport.protocol" is set to "smtps" and the quitwait property "mail.smtps.quitwait" is set to "false".
-083                     * 
-084                     * @see TransportStrategy#SMTP_SSL
-085                     */
-086                    @Override
-087                    public Properties generateProperties() {
-088                            final Properties props = super.generateProperties();
-089                            props.put("mail.transport.protocol", "smtps");
-090                            props.put("mail.smtps.quitwait", "false");
-091                            return props;
-092                    };
-093    
-094                    /**
-095                     * @return "mail.smtps.host"
-096                     */
-097                    @Override
-098                    String propertyNameHost() {
-099                            return "mail.smtps.host";
-100                    };
-101    
-102                    /**
-103                     * @return "mail.smtps.port"
-104                     */
-105                    @Override
-106                    String propertyNamePort() {
-107                            return "mail.smtps.port";
-108                    };
-109    
-110                    /**
-111                     * @return "mail.smtps.username"
-112                     */
-113                    @Override
-114                    String propertyNameUsername() {
-115                            return "mail.smtps.username";
-116                    };
-117    
-118                    /**
-119                     * @return "mail.smtps.auth"
-120                     */
-121                    @Override
-122                    String propertyNameAuthenticate() {
-123                            return "mail.smtps.auth";
-124                    };
-125            },
-126            /**
-127             * <strong>NOTE: this code is in untested beta state</strong>
-128             * <p>
-129             * Uses standard ".smtp." property names (like {@link TransportStrategy#SMTP_PLAIN}). Additionally the transport protocol is explicitly
-130             * set to smtp. Finally, the property "mail.smtp.starttls.enable" is being set to true.
-131             */
-132            SMTP_TLS {
-133    
-134                    /**
-135                     * Here protocol "mail.transport.protocol" is set to "smtp" and the tls property "mail.smtp.starttls.enable" is set to "true".
-136                     * 
-137                     * @see TransportStrategy#SMTP_TLS
-138                     */
-139                    @Override
-140                    public Properties generateProperties() {
-141                            final Properties props = super.generateProperties();
-142                            props.put("mail.transport.protocol", "smtp");
-143                            props.put("mail.smtp.starttls.enable", "true");
-144                            return props;
-145                    }
-146    
-147                    /**
-148                     * @return "mail.smtp.host"
-149                     */
-150                    @Override
-151                    String propertyNameHost() {
-152                            return "mail.smtp.host";
-153                    };
-154    
-155                    /**
-156                     * @return "mail.smtp.port"
-157                     */
-158                    @Override
-159                    String propertyNamePort() {
-160                            return "mail.smtp.port";
-161                    };
-162    
-163                    /**
-164                     * @return "mail.smtp.username"
-165                     */
-166                    @Override
-167                    String propertyNameUsername() {
-168                            return "mail.smtp.username";
-169                    };
-170    
-171                    /**
-172                     * @return "mail.smtp.auth"
-173                     */
-174                    @Override
-175                    String propertyNameAuthenticate() {
-176                            return "mail.smtp.auth";
-177                    };
-178    
-179            };
-180    
-181            /**
-182             * Base implementation that simply returns an empty list of properties. Should be overridden by the various strategies where
-183             * appropriate.
-184             * 
-185             * @return An empty <code>Properties</code> instance.
-186             */
-187            public Properties generateProperties() {
-188                    return new Properties();
-189            }
-190    
-191            abstract String propertyNameHost();
-192    
-193            abstract String propertyNamePort();
-194    
-195            abstract String propertyNameUsername();
-196    
-197            abstract String propertyNameAuthenticate();
-198    };
+
+
+
+Source code
+
+
+
+
+
001package org.codemonkey.simplejavamail;
+002
+003import java.util.Properties;
+004
+005import javax.mail.Session;
+006
+007/**
+008 * Defines the various types of transport protocols and implements respective properties so that a {@link Session} may be configured using a
+009 * <code>TransportStrategy</code> implementation.
+010 * 
+011 * @author Benny Bottema
+012 */
+013public enum TransportStrategy {
+014
+015        /**
+016         * Simplest possible form: only vanilla ".smtp." property names and no extra properties. Additionally the transport protocol is
+017         * explicitly set to smtp.
+018         */
+019        SMTP_PLAIN {
+020                /**
+021                 * Here protocol "mail.transport.protocol" is set to "smtp".
+022                 * 
+023                 * @see TransportStrategy#SMTP_PLAIN
+024                 */
+025                @Override
+026                public Properties generateProperties() {
+027                        final Properties props = super.generateProperties();
+028                        props.put("mail.transport.protocol", "smtp");
+029                        return props;
+030                };
+031
+032                /**
+033                 * @return "mail.smtp.host"
+034                 */
+035                @Override
+036                String propertyNameHost() {
+037                        return "mail.smtp.host";
+038                };
+039
+040                /**
+041                 * @return "mail.smtp.port"
+042                 */
+043                @Override
+044                String propertyNamePort() {
+045                        return "mail.smtp.port";
+046                };
+047
+048                /**
+049                 * @return "mail.smtp.username"
+050                 */
+051                @Override
+052                String propertyNameUsername() {
+053                        return "mail.smtp.username";
+054                };
+055
+056                /**
+057                 * @return "mail.smtp.auth"
+058                 */
+059                @Override
+060                String propertyNameAuthenticate() {
+061                        return "mail.smtp.auth";
+062                };
+063        },
+064        /**
+065         * SMTPS / SSL transport strategy, that returns the ".smtps." variation of the SMTP_PLAIN version. Additionally the transport protocol
+066         * is explicitly set to smtps. Finally, he property "mail.smtps.quitwait" is set to false, to get rid of a strange SSL exception:<br>
+067         * 
+068         * <pre>
+069         * javax.mail.MessagingException: Exception reading response;
+070         * nested exception is:
+071         *      javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
+072         * (..)
+073         * </pre>
+074         * 
+075         * <blockquote>The mail is sent but the exception is unwanted. The property <em>quitwait</em> means If set to false, the QUIT command is sent
+076         * and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT
+077         * command</blockquote><br>
+078         * <strong>- <a href="http://www.rgagnon.com/javadetails/java-0570.html">source</a></strong>
+079         */
+080        SMTP_SSL {
+081                /**
+082                 * Here protocol "mail.transport.protocol" is set to "smtps" and the quitwait property "mail.smtps.quitwait" is set to "false".
+083                 * 
+084                 * @see TransportStrategy#SMTP_SSL
+085                 */
+086                @Override
+087                public Properties generateProperties() {
+088                        final Properties props = super.generateProperties();
+089                        props.put("mail.transport.protocol", "smtps");
+090                        props.put("mail.smtps.quitwait", "false");
+091                        return props;
+092                };
+093
+094                /**
+095                 * @return "mail.smtps.host"
+096                 */
+097                @Override
+098                String propertyNameHost() {
+099                        return "mail.smtps.host";
+100                };
+101
+102                /**
+103                 * @return "mail.smtps.port"
+104                 */
+105                @Override
+106                String propertyNamePort() {
+107                        return "mail.smtps.port";
+108                };
+109
+110                /**
+111                 * @return "mail.smtps.username"
+112                 */
+113                @Override
+114                String propertyNameUsername() {
+115                        return "mail.smtps.username";
+116                };
+117
+118                /**
+119                 * @return "mail.smtps.auth"
+120                 */
+121                @Override
+122                String propertyNameAuthenticate() {
+123                        return "mail.smtps.auth";
+124                };
+125        },
+126        /**
+127         * <strong>NOTE: this code is in untested beta state</strong>
+128         * <p>
+129         * Uses standard ".smtp." property names (like {@link TransportStrategy#SMTP_PLAIN}). Additionally the transport protocol is explicitly
+130         * set to smtp. Finally, the property "mail.smtp.starttls.enable" is being set to true.
+131         */
+132        SMTP_TLS {
+133
+134                /**
+135                 * Here protocol "mail.transport.protocol" is set to "smtp" and the tls property "mail.smtp.starttls.enable" is set to "true".
+136                 * 
+137                 * @see TransportStrategy#SMTP_TLS
+138                 */
+139                @Override
+140                public Properties generateProperties() {
+141                        final Properties props = super.generateProperties();
+142                        props.put("mail.transport.protocol", "smtp");
+143                        props.put("mail.smtp.starttls.enable", "true");
+144                        return props;
+145                }
+146
+147                /**
+148                 * @return "mail.smtp.host"
+149                 */
+150                @Override
+151                String propertyNameHost() {
+152                        return "mail.smtp.host";
+153                };
+154
+155                /**
+156                 * @return "mail.smtp.port"
+157                 */
+158                @Override
+159                String propertyNamePort() {
+160                        return "mail.smtp.port";
+161                };
+162
+163                /**
+164                 * @return "mail.smtp.username"
+165                 */
+166                @Override
+167                String propertyNameUsername() {
+168                        return "mail.smtp.username";
+169                };
+170
+171                /**
+172                 * @return "mail.smtp.auth"
+173                 */
+174                @Override
+175                String propertyNameAuthenticate() {
+176                        return "mail.smtp.auth";
+177                };
+178
+179        };
+180
+181        /**
+182         * Base implementation that simply returns an empty list of properties. Should be overridden by the various strategies where
+183         * appropriate.
+184         * 
+185         * @return An empty <code>Properties</code> instance.
+186         */
+187        public Properties generateProperties() {
+188                return new Properties();
+189        }
+190
+191        abstract String propertyNameHost();
+192
+193        abstract String propertyNamePort();
+194
+195        abstract String propertyNameUsername();
+196
+197        abstract String propertyNameAuthenticate();
+198};
 
 
 
@@ -259,6 +264,7 @@
 
 
 
-
- - +
+ + +