org.mentawai.mail
Class HtmlEmail

java.lang.Object
  extended by org.mentawai.mail.Email
      extended by org.mentawai.mail.MultiPartEmail
          extended by org.mentawai.mail.HtmlEmail

public class HtmlEmail
extends MultiPartEmail

An HTML multipart email.

This class is used to send HTML formatted email. A text message can also be set for HTML unaware email clients, such as text-based email clients.

This class also inherits from MultiPartEmail, so it is easy to add attachents to the email.

To send an email in HTML, one should create a HtmlEmail, then use the setFrom, addTo, etc. methods. The HTML content can be set with the setHtmlMsg method. The alternate text content can be set with setTextMsg.

Either the text or HTML can be omitted, in which case the "main" part of the multipart becomes whichever is supplied rather than a multipart/alternative.

Version:
$Id: HtmlEmail.java,v 1.1 2006/03/02 17:11:41 soliveira Exp $
Author:
Regis Koenig, Sean Legassick

Field Summary
static int CID_LENGTH
          Defintion of the length of generated CID's
protected  String html
          Html part of the message
protected  List<javax.mail.internet.MimeBodyPart> inlineImages
          Embeded images
protected  String text
          Text part of the message.
 
Fields inherited from class org.mentawai.mail.Email
ATTACHMENTS, authenticator, bccList, bounceAddress, ccList, charset, content, CONTENT_TYPE, contentType, debug, EMAIL_BODY, EMAIL_SUBJECT, emailBody, FILE_SERVER, fromAddress, headers, hostName, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_FACTORY_CLASS, MAIL_FACTORY_FALLBACK, MAIL_FACTORY_PORT, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_FROM, MAIL_TRANSPORT_PROTOCOL, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, ssl_connection, subject, TEXT_HTML, TEXT_PLAIN, toList, US_ASCII
 
Constructor Summary
HtmlEmail()
           
 
Method Summary
 String embed(URL url, String name)
          Embeds an URL in the HTML.
 List<javax.mail.internet.InternetAddress> getBccList()
           
 List<javax.mail.internet.InternetAddress> getCcList()
           
 List<javax.mail.internet.InternetAddress> getReplyList()
           
 List<javax.mail.internet.InternetAddress> getToList()
           
 void send()
          Does the work of actually sending the email.
static void sendLater(String toName, String toEmail, String subject, String msg)
           
static void sendLater(String fromName, String fromEmail, String toName, String toEmail, String subject, String msg)
           
static void sendNow(String toName, String toEmail, String subject, String msg)
           
static void sendNow(String fromName, String fromEmail, String toName, String toEmail, String subject, String msg)
           
 HtmlEmail setHtmlMsg(String aHtml)
          Set the HTML content.
 Email setMsg(String msg)
          Set the message.
 HtmlEmail setTextMsg(String aText)
          Set the text content.
 
Methods inherited from class org.mentawai.mail.MultiPartEmail
addPart, addPart, addPart, attach, attach, attach, attach, attach, getContainer, getPrimaryBodyPart, getSubType, init, isBoolHasAttachments, setBoolHasAttachments, setSubType
 
Methods inherited from class org.mentawai.mail.Email
addBcc, addBcc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addTo, addTo, getMailSession, getSentDate, removeBcc, removeCc, removeTo, send, sendLater, sendLater, sendLater, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setDefaultAuthentication, setDefaultBounceAddress, setDefaultCharset, setDefaultFrom, setDefaultHostName, setDefaultPort, setDefaultPort, setDefaultSslConnection, setFactoryFallBack, setFrom, setFrom, setHeaders, setHostName, setMailSession, setPopBeforeSmtp, setSendEmail, setSentDate, setSmtpPort, setSslConnection, setSSLConnection, setSubject, setTo, toInternetAddressArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CID_LENGTH

public static final int CID_LENGTH
Defintion of the length of generated CID's

See Also:
Constant Field Values

text

protected String text
Text part of the message. This will be used as alternative text if the email client does not support HTML messages.


html

protected String html
Html part of the message


inlineImages

protected List<javax.mail.internet.MimeBodyPart> inlineImages
Embeded images

Constructor Detail

HtmlEmail

public HtmlEmail()
Method Detail

getToList

public List<javax.mail.internet.InternetAddress> getToList()
Returns:
List the list of destinataries or null if not exist

getCcList

public List<javax.mail.internet.InternetAddress> getCcList()
Returns:
List the list of cc or null if not exist

getBccList

public List<javax.mail.internet.InternetAddress> getBccList()
Returns:
List the list of bcc or null if not exist

getReplyList

public List<javax.mail.internet.InternetAddress> getReplyList()
Returns:
List the list of reply or null if not exist

setTextMsg

public HtmlEmail setTextMsg(String aText)
                     throws EmailException
Set the text content.

Parameters:
aText - A String.
Returns:
An HtmlEmail.
Throws:
EmailException - see javax.mail.internet.MimeBodyPart for defintions

setHtmlMsg

public HtmlEmail setHtmlMsg(String aHtml)
                     throws EmailException
Set the HTML content.

Parameters:
aHtml - A String.
Returns:
An HtmlEmail.
Throws:
EmailException - see javax.mail.internet.MimeBodyPart for defintions

setMsg

public Email setMsg(String msg)
             throws EmailException
Set the message.

This method overrides the MultiPartEmail setMsg() method in order to send an HTML message instead of a full text message in the mail body. The message is formatted in HTML for the HTML part of the message, it is let as is in the alternate text part.

Overrides:
setMsg in class MultiPartEmail
Parameters:
msg - A String.
Returns:
An Email.
Throws:
EmailException - see javax.mail.internet.MimeBodyPart for defintions

embed

public String embed(URL url,
                    String name)
             throws EmailException
Embeds an URL in the HTML.

This method allows to embed a file located by an URL into the mail body. It allows, for instance, to add inline images to the email. Inline files may be referenced with a cid:xxxxxx URL, where xxxxxx is the Content-ID returned by the embed function.

Example of use:

 HtmlEmail he = new HtmlEmail();
 he.setHtmlMsg("<html><img src=cid:" +
  embed("file:/my/image.gif","image.gif") +
  "></html>");
 // code to set the others email fields (not shown)
 

Parameters:
url - The URL of the file.
name - The name that will be set in the filename header field.
Returns:
A String with the Content-ID of the file.
Throws:
EmailException - when URL suplpied is invalid also see javax.mail.internet.MimeBodyPart for defintions

send

public void send()
          throws EmailException
Does the work of actually sending the email.

Overrides:
send in class MultiPartEmail
Throws:
EmailException - if there was an error.

sendNow

public static void sendNow(String toName,
                           String toEmail,
                           String subject,
                           String msg)
                    throws Exception
Throws:
Exception

sendLater

public static void sendLater(String toName,
                             String toEmail,
                             String subject,
                             String msg)
                      throws Exception
Throws:
Exception

sendNow

public static void sendNow(String fromName,
                           String fromEmail,
                           String toName,
                           String toEmail,
                           String subject,
                           String msg)
                    throws Exception
Throws:
Exception

sendLater

public static void sendLater(String fromName,
                             String fromEmail,
                             String toName,
                             String toEmail,
                             String subject,
                             String msg)
                      throws Exception
Throws:
Exception


Copyright © 2013. All Rights Reserved.