public class MailSenderPlugin extends XWikiDefaultPlugin
MailSender
Modifier and Type | Field and 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 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 and Description |
---|
MailSenderPlugin(String name,
String className,
XWikiContext context)
Default plugin constructor.
|
Modifier and Type | Method and Description |
---|---|
javax.mail.internet.MimeBodyPart |
createAttachmentBodyPart(Attachment attachment,
XWikiContext context)
Add attachments to a multipart message
|
javax.mail.Multipart |
createMimeMultipart(Mail mail,
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(XWikiPluginInterface plugin,
XWikiContext context) |
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,
Map<String,Object> parameters,
XWikiContext context)
Prepares a Mail Velocity context based on a map of parameters
|
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
|
boolean |
sendMail(Mail mailItem,
MailConfiguration mailConfiguration,
XWikiContext context)
Send a single Mail
|
boolean |
sendMail(Mail mailItem,
XWikiContext context)
Send a single Mail
|
int |
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)
|
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endParsing, endRendering, endRenderingHandler, flushCache, flushCache, getClassName, getLocalization, init, insidePREHandler, localizePlainOrKey, outsidePREHandler, setClassName, setName, startRenderingHandler, virtualInit
public static int ERROR_TEMPLATE_EMAIL_OBJECT_NOT_FOUND
sendMailFromTemplate(String, String, String, String, String, String, VelocityContext, XWikiContext)
was
not found.public static int ERROR
public static final String EMAIL_XWIKI_CLASS_NAME
public static final String ID
protected static final String URL_SEPARATOR
public MailSenderPlugin(String name, String className, XWikiContext context)
public String getName()
getName
in interface XWikiPluginInterface
getName
in class XWikiDefaultPlugin
public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
getPluginApi
in interface XWikiPluginInterface
getPluginApi
in class XWikiDefaultPlugin
public static String[] parseAddresses(String email)
email
- comma separated list of emailspublic javax.mail.internet.MimeBodyPart createAttachmentBodyPart(Attachment attachment, XWikiContext context) throws XWikiException, IOException, javax.mail.MessagingException
attachment
- the attachment to create the body part for.context
- the XWiki context.XWikiException
IOException
javax.mail.MessagingException
public javax.mail.Multipart createMimeMultipart(Mail mail, XWikiContext context) throws javax.mail.MessagingException, XWikiException, IOException
mail
- The original Mailjavax.mail.MessagingException
XWikiException
IOException
protected void parseRawMessage(String rawMessage, Mail toMail)
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.rawMessage
- the raw content of the message that should be parsedtoMail
- the Mail
to createIllegalArgumentException
- if the target Mail or the content to parse are null or the empty stringprotected String evaluate(String property, org.apache.velocity.context.Context context) throws Exception
property
- The String propertycontext
- Context of the requestException
protected String getFileName(String path)
path
- The file pathpublic org.apache.velocity.VelocityContext prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, org.apache.velocity.VelocityContext vcontext, XWikiContext context)
fromAddr
- Mail fromtoAddr
- Mail toccAddr
- Mail ccbccAddr
- Mail bccvcontext
- The Velocity context to preparepublic org.apache.velocity.VelocityContext prepareVelocityContext(String fromAddr, String toAddr, String ccAddr, String bccAddr, Map<String,Object> parameters, XWikiContext context)
fromAddr
- Mail fromtoAddr
- Mail toccAddr
- Mail ccbccAddr
- Mail bccparameters
- variables to be passed to the velocity contextpublic boolean sendMail(Mail mailItem, XWikiContext context) throws javax.mail.MessagingException, UnsupportedEncodingException
mailItem
- The Mail to sendjavax.mail.MessagingException
UnsupportedEncodingException
public boolean sendMail(Mail mailItem, MailConfiguration mailConfiguration, XWikiContext context) throws javax.mail.MessagingException, UnsupportedEncodingException
mailItem
- The Mail to sendjavax.mail.MessagingException
UnsupportedEncodingException
public boolean sendMails(Collection<Mail> emails, XWikiContext context) throws javax.mail.MessagingException, UnsupportedEncodingException
emails
- Mail Collectionjavax.mail.MessagingException
UnsupportedEncodingException
public boolean sendMails(Collection<Mail> emails, MailConfiguration mailConfiguration, XWikiContext context) throws javax.mail.MessagingException, UnsupportedEncodingException
emails
- Mail Collectionjavax.mail.MessagingException
UnsupportedEncodingException
public int sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, org.apache.velocity.VelocityContext vcontext, XWikiContext context) throws XWikiException
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 rendererXWikiException
public int sendMailFromTemplate(String templateDocFullName, String from, String to, String cc, String bcc, String language, Map<String,Object> parameters, XWikiContext context) throws XWikiException
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 contextXWikiException
Copyright © 2004–2022 XWiki. All rights reserved.