Package com.xpn.xwiki.plugin.mailsender
Class MailSenderPlugin
- java.lang.Object
-
- com.xpn.xwiki.plugin.XWikiDefaultPlugin
-
- com.xpn.xwiki.plugin.mailsender.MailSenderPlugin
-
- All Implemented Interfaces:
XWikiPluginInterface
public class MailSenderPlugin extends XWikiDefaultPlugin
Plugin that brings powerful mailing capabilities.- Version:
- $Id: 04326c47444e23629b91d729956bb9022a480a3d $
- See Also:
MailSender
-
-
Field Summary
Fields Modifier and Type Field Description 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 forsendMailFromTemplate(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
Constructors Constructor Description MailSenderPlugin(String name, String className, XWikiContext context)
Default plugin constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.mail.internet.MimeBodyPart
createAttachmentBodyPart(Attachment attachment, XWikiContext context)
Add attachments to a multipart messagejavax.mail.Multipart
createMimeMultipart(Mail mail, XWikiContext context)
Creates a Multipart MIME Message (multiple content-types within the same message) from an existing mailprotected String
evaluate(String property, org.apache.velocity.context.Context context)
Evaluates a String property containing Velocityprotected String
getFileName(String path)
Get a file name from its pathString
getName()
Api
getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
static String[]
parseAddresses(String email)
Split comma separated list of emailsprotected void
parseRawMessage(String rawMessage, Mail toMail)
Splits a raw mail into headers and the actual content, filling in aMail
object.org.apache.velocity.VelocityContext
prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, Map<String,Object> parameters, XWikiContext context)
Prepares a Mail Velocity context based on a map of parametersorg.apache.velocity.VelocityContext
prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, org.apache.velocity.VelocityContext vcontext, XWikiContext context)
Prepares a Mail Velocity contextboolean
sendMail(Mail mailItem, MailConfiguration mailConfiguration, XWikiContext context)
Send a single Mailboolean
sendMail(Mail mailItem, XWikiContext context)
Send a single Mailint
sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, Map<String,Object> parameters, XWikiContext context)
Uses an XWiki document to build the message subject and context, based on variables stored in a map.int
sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, org.apache.velocity.VelocityContext vcontext, 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, XWikiContext context)
Send a Collection of Mails (multiple emails)boolean
sendMails(Collection<Mail> emails, XWikiContext context)
Send a Collection of Mails (multiple emails)-
Methods inherited from class com.xpn.xwiki.plugin.XWikiDefaultPlugin
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endParsing, endRendering, endRenderingHandler, flushCache, flushCache, getClassName, getLocalization, init, insidePREHandler, localizePlainOrKey, outsidePREHandler, setClassName, setName, startRenderingHandler, virtualInit
-
-
-
-
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 forsendMailFromTemplate(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, XWikiContext context)
Default plugin constructor.
-
-
Method Detail
-
getName
public String getName()
- Specified by:
getName
in interfaceXWikiPluginInterface
- Overrides:
getName
in classXWikiDefaultPlugin
-
getPluginApi
public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
- Specified by:
getPluginApi
in interfaceXWikiPluginInterface
- Overrides:
getPluginApi
in classXWikiDefaultPlugin
-
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
-
createAttachmentBodyPart
public javax.mail.internet.MimeBodyPart createAttachmentBodyPart(Attachment attachment, XWikiContext context) throws XWikiException, IOException, javax.mail.MessagingException
Add attachments to a multipart message- Parameters:
attachment
- the attachment to create the body part for.context
- the XWiki context.- Returns:
- the body part for the given attachment.
- Throws:
XWikiException
IOException
javax.mail.MessagingException
-
createMimeMultipart
public javax.mail.Multipart createMimeMultipart(Mail mail, XWikiContext context) throws javax.mail.MessagingException, 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
XWikiException
IOException
-
parseRawMessage
protected void parseRawMessage(String rawMessage, Mail toMail)
Splits a raw mail into headers and the actual content, filling in aMail
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 parsedtoMail
- theMail
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 propertycontext
- 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, XWikiContext context)
Prepares a Mail Velocity context- Parameters:
fromAddr
- Mail fromtoAddr
- Mail toccAddr
- Mail ccbccAddr
- Mail bccvcontext
- The Velocity context to prepare- Returns:
- The prepared context
-
prepareVelocityContext
public org.apache.velocity.VelocityContext prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, Map<String,Object> parameters, XWikiContext context)
Prepares a Mail Velocity context based on a map of parameters- Parameters:
fromAddr
- Mail fromtoAddr
- Mail toccAddr
- Mail ccbccAddr
- Mail bccparameters
- variables to be passed to the velocity context- Returns:
- The prepared context
-
sendMail
public boolean sendMail(Mail mailItem, 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, 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, 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, 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, XWikiContext context) throws 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 attachedfrom
- Email senderto
- Email recipientcc
- Email Carbon Copybcc
- Email Hidden Carbon Copylanguage
- Language of the emailvcontext
- Velocity context passed to the velocity renderer- Returns:
- True if the email has been sent
- Throws:
XWikiException
-
sendMailFromTemplate
public int sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, Map<String,Object> parameters, XWikiContext context) throws XWikiException
Uses an XWiki document to build the message subject and context, based on variables stored in a map. 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 attachedfrom
- Email senderto
- Email recipientcc
- Email Carbon Copybcc
- Email Hidden Carbon Copylanguage
- Language of the emailparameters
- variables to be passed to the velocity context- Returns:
- True if the email has been sent
- Throws:
XWikiException
-
-