Project Wonder 5.0

er.javamail
Class ERMailDelivery

java.lang.Object
  extended by er.javamail.ERMailDelivery
Direct Known Subclasses:
ERMailDeliveryComponentBased, ERMailDeliveryPlainText

public abstract class ERMailDelivery
extends java.lang.Object

This is the main class for sending mail with the JavaMail API. You should create instances of its subclasses that match with specific use cases.

Here is an example of its usage:

    ERMailDeliveryHTML mail = new ERMailDeliveryHTML ();
    mail.setWOComponentContent (mailPage);

    try {
        mail.newMail ();
        mail.setFromAddress(emailFrom);
        mail.setReplyToAddress(emailReplyTo);
        mail.setSubject(emailSubject);
        mail.setToAddresses(new NSArray (toEmailAddresses));

        // Send the mail
        mail.sendMail ();
    } catch (Exception e) {
        // do something ...
    }

Author:
Camille Troillard , ak fixes
Properties
er.javamail.defaultEncodinger.javamail.defaultEncoding
           

Field Summary
protected  com.webobjects.foundation.NSMutableArray<ERMailAttachment> _attachments
          NSArray of ERMailAttachment that must be binded to the message as ATTACHEMENT.
 java.lang.String _charset
           
protected  com.webobjects.foundation.NSMutableArray<ERMailAttachment> _inlineAttachments
          NSArray of ERMailAttachment that must be binded to the message as INLINE.
protected  javax.mail.internet.MimeMessage _mimeMessage
          Content of sent mail.
static java.lang.String DefaultCharset
           
 
Constructor Summary
ERMailDelivery()
          Default constructor
ERMailDelivery(javax.mail.Session session)
          Designated constructor
 
Method Summary
protected  com.webobjects.foundation.NSMutableArray<ERMailAttachment> _attachments()
           
protected  com.webobjects.foundation.NSMutableArray<ERMailAttachment> _inlineAttachments()
           
 void addAttachment(ERMailAttachment attachment)
           
 void addInlineAttachment(ERMailAttachment attachment)
           
 com.webobjects.foundation.NSArray<ERMailAttachment> attachments()
           
protected  ERMessage buildMessage()
          Builds an ERMessage for the current MimeMessage.
 java.lang.String charset()
           
 java.lang.String contextString()
           
protected  void finishMessagePreparation()
           
 com.webobjects.foundation.NSArray<ERMailAttachment> inlineAttachments()
           
protected  javax.mail.internet.InternetAddress internetAddressWithEmailAndPersonal(java.lang.String email, java.lang.String personal)
           
protected  javax.mail.internet.MimeMessage mimeMessage()
           
 void newMail()
          Creates a new mail instance within ERMailDelivery
protected abstract  javax.activation.DataHandler prepareMail()
          Abstract method called by subclasses for doing pre-processing before sending the mail.
 void removeAttachment(ERMailAttachment attachment)
           
 void sendMail()
          Sends the mail immediately.
 void sendMail(boolean shouldBlock)
          Method used to construct a MimeMessage and then send it.
protected  javax.mail.Session session()
           
 void setAdditionalHeader(java.lang.String headerKey, java.lang.String value)
          Sets an additional custom header element for the message.
 void setBCCAddresses(com.webobjects.foundation.NSArray<java.lang.String> bccAddresses)
          Sets the bcc-addresses array for the current message instance
 void setBCCAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> bccAddresses)
          Sets the bcc-addresses array for the current message instance
 void setCCAddresses(com.webobjects.foundation.NSArray<java.lang.String> ccAddresses)
          Sets the cc-addresses array for the current message instance
 void setCCAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> ccAddresses)
          Sets the cc-addresses array for the current message instance
 void setCharset(java.lang.String charset)
           
 void setContextString(java.lang.String contextString)
           
 void setDelegate(ERMessage.Delegate delegate)
          Sets the given delegate to listen to any messages that are created from this ERMailDelivery.
 void setFromAddress(java.lang.String fromAddress)
          Sets the from address for the current message instance
 void setFromAddress(java.lang.String fromAddress, java.lang.String personalName)
          Sets the from address for the current message instance using an email and the personal name.
 void setInternetAddresses(com.webobjects.foundation.NSArray<javax.mail.internet.InternetAddress> addresses, javax.mail.Message.RecipientType type)
          Sets addresses using an NSArray of InternetAddress objects.
protected  void setMimeMessage(javax.mail.internet.MimeMessage message)
           
 void setReplyToAddress(java.lang.String toAddress)
          Sets the reply-to address for the current message instance
 void setReplyToAddress(java.lang.String toAddress, java.lang.String personalName)
          Sets the reply-to address for the current message instance
protected  void setSession(javax.mail.Session aSession)
           
 void setSubject(java.lang.String subject)
          Sets the subject for the current message instance
 void setToAddress(java.lang.String toAddress)
           
 void setToAddress(java.lang.String toAddress, java.lang.String personalName)
          Sets the to address for the current message instance using an email and the personal name.
 void setToAddresses(com.webobjects.foundation.NSArray<java.lang.String> toAddresses)
          Sets the to-addresses array for the current message instance
 void setToAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> toAddresses)
          Sets the to-addresses array for the current message instance
 void setUserInfo(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo)
          Sets the userInfo dictionary for this ERMailDelivery.
 void setXMailerHeader(java.lang.String xMailer)
          Sets the X-Mailer header for the message.
 com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo()
          Returns the userInfo dictionary for this ERMailDelivery.
 java.lang.String xMailerHeader()
          Gets the X-Mailer header set on the MimeMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_mimeMessage

protected javax.mail.internet.MimeMessage _mimeMessage
Content of sent mail. In one instance of ERMailDelivery, when creating multiple mails, you must be sure to call newMail () method before send a new mail in order to have a cleared fresh mail


_attachments

protected com.webobjects.foundation.NSMutableArray<ERMailAttachment> _attachments
NSArray of ERMailAttachment that must be binded to the message as ATTACHEMENT.


_inlineAttachments

protected com.webobjects.foundation.NSMutableArray<ERMailAttachment> _inlineAttachments
NSArray of ERMailAttachment that must be binded to the message as INLINE.


DefaultCharset

public static final java.lang.String DefaultCharset

_charset

public java.lang.String _charset
Constructor Detail

ERMailDelivery

public ERMailDelivery(javax.mail.Session session)
Designated constructor


ERMailDelivery

public ERMailDelivery()
Default constructor

Method Detail

setDelegate

public void setDelegate(ERMessage.Delegate delegate)
Sets the given delegate to listen to any messages that are created from this ERMailDelivery. This will automatically call ERMessage.setDelegate(delegate) for any ERMessage that is generated.

Parameters:
delegate - the delegate to use for notifications

setUserInfo

public void setUserInfo(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo)
Sets the userInfo dictionary for this ERMailDelivery. This userInfo is passed through to any ERMessage that is created by this ERMailDelivery, which can be used by delegates to get additional information about the message.

Parameters:
userInfo - the userInfo dictionary

userInfo

public com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo()
Returns the userInfo dictionary for this ERMailDelivery.

Returns:
the userInfo dictionary

setContextString

public void setContextString(java.lang.String contextString)

contextString

public java.lang.String contextString()

charset

public java.lang.String charset()

setCharset

public void setCharset(java.lang.String charset)

session

protected javax.mail.Session session()

setSession

protected void setSession(javax.mail.Session aSession)

newMail

public void newMail()
Creates a new mail instance within ERMailDelivery


mimeMessage

protected javax.mail.internet.MimeMessage mimeMessage()

setMimeMessage

protected void setMimeMessage(javax.mail.internet.MimeMessage message)

addAttachment

public void addAttachment(ERMailAttachment attachment)

addInlineAttachment

public void addInlineAttachment(ERMailAttachment attachment)

_inlineAttachments

protected com.webobjects.foundation.NSMutableArray<ERMailAttachment> _inlineAttachments()

inlineAttachments

public com.webobjects.foundation.NSArray<ERMailAttachment> inlineAttachments()

_attachments

protected com.webobjects.foundation.NSMutableArray<ERMailAttachment> _attachments()

attachments

public com.webobjects.foundation.NSArray<ERMailAttachment> attachments()

removeAttachment

public void removeAttachment(ERMailAttachment attachment)

internetAddressWithEmailAndPersonal

protected javax.mail.internet.InternetAddress internetAddressWithEmailAndPersonal(java.lang.String email,
                                                                                  java.lang.String personal)
                                                                           throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

setFromAddress

public void setFromAddress(java.lang.String fromAddress)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the from address for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setFromAddress

public void setFromAddress(java.lang.String fromAddress,
                           java.lang.String personalName)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the from address for the current message instance using an email and the personal name.

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setToAddress

public void setToAddress(java.lang.String toAddress)
                  throws javax.mail.MessagingException,
                         javax.mail.internet.AddressException
Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setToAddress

public void setToAddress(java.lang.String toAddress,
                         java.lang.String personalName)
                  throws javax.mail.MessagingException,
                         javax.mail.internet.AddressException
Sets the to address for the current message instance using an email and the personal name.

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setToAddresses

public void setToAddresses(com.webobjects.foundation.NSArray<java.lang.String> toAddresses)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the to-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setToAddresses

public void setToAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> toAddresses)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the to-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setReplyToAddress

public void setReplyToAddress(java.lang.String toAddress)
                       throws javax.mail.MessagingException,
                              javax.mail.internet.AddressException
Sets the reply-to address for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setReplyToAddress

public void setReplyToAddress(java.lang.String toAddress,
                              java.lang.String personalName)
                       throws javax.mail.MessagingException,
                              javax.mail.internet.AddressException
Sets the reply-to address for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setCCAddresses

public void setCCAddresses(com.webobjects.foundation.NSArray<java.lang.String> ccAddresses)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the cc-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setCCAddresses

public void setCCAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> ccAddresses)
                    throws javax.mail.MessagingException,
                           javax.mail.internet.AddressException
Sets the cc-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setBCCAddresses

public void setBCCAddresses(com.webobjects.foundation.NSArray<java.lang.String> bccAddresses)
                     throws javax.mail.MessagingException,
                            javax.mail.internet.AddressException
Sets the bcc-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setBCCAddresses

public void setBCCAddresses(com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.String> bccAddresses)
                     throws javax.mail.MessagingException,
                            javax.mail.internet.AddressException
Sets the bcc-addresses array for the current message instance

Throws:
javax.mail.MessagingException
javax.mail.internet.AddressException

setSubject

public void setSubject(java.lang.String subject)
                throws javax.mail.MessagingException
Sets the subject for the current message instance

Throws:
javax.mail.MessagingException

setXMailerHeader

public void setXMailerHeader(java.lang.String xMailer)
                      throws javax.mail.MessagingException
Sets the X-Mailer header for the message. Useful for tracking which mailers are sending messages.

Parameters:
xMailer - value to set
Throws:
javax.mail.MessagingException

xMailerHeader

public java.lang.String xMailerHeader()
                               throws javax.mail.MessagingException
Gets the X-Mailer header set on the MimeMessage.

Returns:
X-Mailer header if it is set
Throws:
javax.mail.MessagingException

setAdditionalHeader

public void setAdditionalHeader(java.lang.String headerKey,
                                java.lang.String value)
                         throws javax.mail.MessagingException
Sets an additional custom header element for the message.

Parameters:
header - header key
value - value to set
Throws:
javax.mail.MessagingException

buildMessage

protected ERMessage buildMessage()
Builds an ERMessage for the current MimeMessage.

Returns:
ERMessage for the current MimeMessage.

sendMail

public void sendMail()
Sends the mail immediately. The message is put in a FIFO queue managed by a static threaded inner class


sendMail

public void sendMail(boolean shouldBlock)
Method used to construct a MimeMessage and then send it. This method can be specified to block until the message is sent or to add the message to a queue and have a callback object handle any exceptions that happen. If sending is blocking then any exception thrown will be wrapped in a general NSForwardException.

Parameters:
shouldBlock - boolean to indicate if the message should be added to a queue or sent directly.

finishMessagePreparation

protected void finishMessagePreparation()
                                 throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

setInternetAddresses

public void setInternetAddresses(com.webobjects.foundation.NSArray<javax.mail.internet.InternetAddress> addresses,
                                 javax.mail.Message.RecipientType type)
                          throws javax.mail.MessagingException
Sets addresses using an NSArray of InternetAddress objects.

Throws:
javax.mail.MessagingException

prepareMail

protected abstract javax.activation.DataHandler prepareMail()
                                                     throws javax.mail.MessagingException
Abstract method called by subclasses for doing pre-processing before sending the mail.

Returns:
the multipart used to put in the mail.
Throws:
javax.mail.MessagingException

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.