com.xpn.xwiki.plugin.mailsender
Class MailSenderPlugin

java.lang.Object
  extended by com.xpn.xwiki.plugin.XWikiDefaultPlugin
      extended by com.xpn.xwiki.plugin.mailsender.MailSenderPlugin
All Implemented Interfaces:
com.xpn.xwiki.plugin.XWikiPluginInterface

public class MailSenderPlugin
extends com.xpn.xwiki.plugin.XWikiDefaultPlugin

Plugin that brings powerful mailing capabilities.

Version:
$Id$
See Also:
MailSender

Field Summary
static String EMAIL_XWIKI_CLASS_NAME
          The name of the Object Type holding mail templates.
static int ERROR
          Generic error code for plugin failures.
static int ERROR_TEMPLATE_EMAIL_OBJECT_NOT_FOUND
          Error code signaling that the mail template requested for sendMailFromTemplate(String, String, String, String, String, String, VelocityContext, XWikiContext) was not found.
static String ID
          The name of the plugin, used for accessing it from scripting environments.
protected static String URL_SEPARATOR
           
 
Constructor Summary
MailSenderPlugin(String name, String className, com.xpn.xwiki.XWikiContext context)
          Default plugin constructor.
 
Method Summary
 javax.mail.internet.MimeBodyPart createAttachmentBodyPart(Attachment attachment, com.xpn.xwiki.XWikiContext context)
          Add attachments to a multipart message
 javax.mail.Multipart createMimeMultipart(Mail mail, com.xpn.xwiki.XWikiContext context)
          Creates a Multipart MIME Message (multiple content-types within the same message) from an existing mail
protected  String evaluate(String property, org.apache.velocity.context.Context context)
          Evaluates a String property containing Velocity
protected  String getFileName(String path)
          Get a file name from its path
 String getName()
          
 Api getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface plugin, com.xpn.xwiki.XWikiContext context)
          
 void init(com.xpn.xwiki.XWikiContext context)
          
protected  com.xpn.xwiki.objects.classes.BaseClass initMailClass(com.xpn.xwiki.XWikiContext context)
          Creates the Mail XWiki Class
static String[] parseAddresses(String email)
          Split comma separated list of emails
protected  void parseRawMessage(String rawMessage, Mail toMail)
          Splits a raw mail into headers and the actual content, filling in a Mail object.
 org.apache.velocity.VelocityContext prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, org.apache.velocity.VelocityContext vcontext, com.xpn.xwiki.XWikiContext context)
          Prepares a Mail Velocity context
 boolean sendMail(Mail mailItem, MailConfiguration mailConfiguration, com.xpn.xwiki.XWikiContext context)
          Send a single Mail
 boolean sendMail(Mail mailItem, com.xpn.xwiki.XWikiContext context)
          Send a single Mail
 int sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, org.apache.velocity.VelocityContext vcontext, com.xpn.xwiki.XWikiContext context)
          Uses an XWiki document to build the message subject and context, based on variables stored in the VelocityContext.
 boolean sendMails(Collection<Mail> emails, MailConfiguration mailConfiguration, com.xpn.xwiki.XWikiContext context)
          Send a Collection of Mails (multiple emails)
 boolean sendMails(Collection<Mail> emails, com.xpn.xwiki.XWikiContext context)
          Send a Collection of Mails (multiple emails)
 void virtualInit(com.xpn.xwiki.XWikiContext context)
          
 
Methods inherited from class com.xpn.xwiki.plugin.XWikiDefaultPlugin
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endParsing, endRendering, endRenderingHandler, flushCache, flushCache, getClassName, insidePREHandler, outsidePREHandler, setClassName, setName, startRenderingHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_TEMPLATE_EMAIL_OBJECT_NOT_FOUND

public static int ERROR_TEMPLATE_EMAIL_OBJECT_NOT_FOUND
Error code signaling that the mail template requested for sendMailFromTemplate(String, String, String, String, String, String, VelocityContext, XWikiContext) was not found.


ERROR

public static int ERROR
Generic error code for plugin failures.


EMAIL_XWIKI_CLASS_NAME

public static final String EMAIL_XWIKI_CLASS_NAME
The name of the Object Type holding mail templates.

See Also:
Constant Field Values

ID

public static final String ID
The name of the plugin, used for accessing it from scripting environments.

See Also:
Constant Field Values

URL_SEPARATOR

protected static final String URL_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

MailSenderPlugin

public MailSenderPlugin(String name,
                        String className,
                        com.xpn.xwiki.XWikiContext context)
Default plugin constructor.

See Also:
XWikiDefaultPlugin.XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
Method Detail

init

public void init(com.xpn.xwiki.XWikiContext context)

Specified by:
init in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
init in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiDefaultPlugin.init(XWikiContext)

virtualInit

public void virtualInit(com.xpn.xwiki.XWikiContext context)

Specified by:
virtualInit in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
virtualInit in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiDefaultPlugin.virtualInit(XWikiContext)

getName

public String getName()

Specified by:
getName in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
getName in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiPluginInterface.getName()

getPluginApi

public Api getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface plugin,
                        com.xpn.xwiki.XWikiContext context)

Specified by:
getPluginApi in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
getPluginApi in class com.xpn.xwiki.plugin.XWikiDefaultPlugin
See Also:
XWikiDefaultPlugin.getPluginApi(XWikiPluginInterface, XWikiContext)

parseAddresses

public static String[] parseAddresses(String email)
Split comma separated list of emails

Parameters:
email - comma separated list of emails
Returns:
An array containing the emails

initMailClass

protected com.xpn.xwiki.objects.classes.BaseClass initMailClass(com.xpn.xwiki.XWikiContext context)
                                                         throws com.xpn.xwiki.XWikiException
Creates the Mail XWiki Class

Parameters:
context - Context of the request
Returns:
the Mail XWiki Class
Throws:
com.xpn.xwiki.XWikiException

createAttachmentBodyPart

public javax.mail.internet.MimeBodyPart createAttachmentBodyPart(Attachment attachment,
                                                                 com.xpn.xwiki.XWikiContext context)
                                                          throws com.xpn.xwiki.XWikiException,
                                                                 IOException,
                                                                 javax.mail.MessagingException
Add attachments to a multipart message

Parameters:
multipart - Multipart message
attachments - List of attachments
Throws:
com.xpn.xwiki.XWikiException
IOException
javax.mail.MessagingException

createMimeMultipart

public javax.mail.Multipart createMimeMultipart(Mail mail,
                                                com.xpn.xwiki.XWikiContext context)
                                         throws javax.mail.MessagingException,
                                                com.xpn.xwiki.XWikiException,
                                                IOException
Creates a Multipart MIME Message (multiple content-types within the same message) from an existing mail

Parameters:
mail - The original Mail
Returns:
The Multipart MIME message
Throws:
javax.mail.MessagingException
com.xpn.xwiki.XWikiException
IOException

parseRawMessage

protected void parseRawMessage(String rawMessage,
                               Mail toMail)
Splits a raw mail into headers and the actual content, filling in a Mail object. This method should be compliant with RFC 2822 as much as possible. If the message accidentally starts with what looks like a mail header, then that line WILL be considered a header; no check on the semantics of the header is performed.

Parameters:
rawMessage - the raw content of the message that should be parsed
toMail - the Mail to create
Throws:
IllegalArgumentException - if the target Mail or the content to parse are null or the empty string

evaluate

protected String evaluate(String property,
                          org.apache.velocity.context.Context context)
                   throws Exception
Evaluates a String property containing Velocity

Parameters:
property - The String property
context - Context of the request
Returns:
The evaluated String
Throws:
Exception

getFileName

protected String getFileName(String path)
Get a file name from its path

Parameters:
path - The file path
Returns:
The file name

prepareVelocityContext

public org.apache.velocity.VelocityContext prepareVelocityContext(String fromAddr,
                                                                  String toAddr,
                                                                  String ccAddr,
                                                                  String bccAddr,
                                                                  org.apache.velocity.VelocityContext vcontext,
                                                                  com.xpn.xwiki.XWikiContext context)
Prepares a Mail Velocity context

Parameters:
fromAddr - Mail from
toAddr - Mail to
ccAddr - Mail cc
bccAddr - Mail bcc
vcontext - The Velocity context to prepare
Returns:
The prepared context

sendMail

public boolean sendMail(Mail mailItem,
                        com.xpn.xwiki.XWikiContext context)
                 throws javax.mail.MessagingException,
                        UnsupportedEncodingException
Send a single Mail

Parameters:
mailItem - The Mail to send
Returns:
True if the the email has been sent
Throws:
javax.mail.MessagingException
UnsupportedEncodingException

sendMail

public boolean sendMail(Mail mailItem,
                        MailConfiguration mailConfiguration,
                        com.xpn.xwiki.XWikiContext context)
                 throws javax.mail.MessagingException,
                        UnsupportedEncodingException
Send a single Mail

Parameters:
mailItem - The Mail to send
Returns:
True if the the email has been sent
Throws:
javax.mail.MessagingException
UnsupportedEncodingException

sendMails

public boolean sendMails(Collection<Mail> emails,
                         com.xpn.xwiki.XWikiContext context)
                  throws javax.mail.MessagingException,
                         UnsupportedEncodingException
Send a Collection of Mails (multiple emails)

Parameters:
emails - Mail Collection
Returns:
True in any case (TODO ?)
Throws:
javax.mail.MessagingException
UnsupportedEncodingException

sendMails

public boolean sendMails(Collection<Mail> emails,
                         MailConfiguration mailConfiguration,
                         com.xpn.xwiki.XWikiContext context)
                  throws javax.mail.MessagingException,
                         UnsupportedEncodingException
Send a Collection of Mails (multiple emails)

Parameters:
emails - Mail Collection
Returns:
True in any case (TODO ?)
Throws:
javax.mail.MessagingException
UnsupportedEncodingException

sendMailFromTemplate

public int sendMailFromTemplate(String templateDocFullName,
                                String from,
                                String to,
                                String cc,
                                String bcc,
                                String language,
                                org.apache.velocity.VelocityContext vcontext,
                                com.xpn.xwiki.XWikiContext context)
                         throws com.xpn.xwiki.XWikiException
Uses an XWiki document to build the message subject and context, based on variables stored in the VelocityContext. Sends the email.

Parameters:
templateDocFullName - Full name of the template to be used (example: XWiki.MyEmailTemplate). The template needs to have an XWiki.Email object attached
from - Email sender
to - Email recipient
cc - Email Carbon Copy
bcc - Email Hidden Carbon Copy
language - Language of the email
vcontext - Velocity context passed to the velocity renderer
Returns:
True if the email has been sent
Throws:
com.xpn.xwiki.XWikiException


Copyright © 2004-2012 XWiki. All Rights Reserved.