com.xpn.xwiki.plugin.mailsender
Class MailSenderPluginApi

java.lang.Object
  extended by com.xpn.xwiki.api.Api
      extended by com.xpn.xwiki.plugin.PluginApi<MailSenderPlugin>
          extended by com.xpn.xwiki.plugin.mailsender.MailSenderPluginApi
All Implemented Interfaces:
MailSender

public class MailSenderPluginApi
extends PluginApi<MailSenderPlugin>
implements MailSender

Plugin that brings powerful mailing capabilities. This is the wrapper accessible from in-document scripts.

Version:
$Id: 5f6b291d7142cba6b8e814baec1a9ce14639e3dc $
See Also:
MailSender

Field Summary
 
Fields inherited from class com.xpn.xwiki.api.Api
context
 
Constructor Summary
MailSenderPluginApi(MailSenderPlugin plugin, XWikiContext context)
          API constructor.
 
Method Summary
 Mail createMail()
          A helper method for Velocity scripts since we cannot create Java objects from Velocity.
 MailConfiguration createMailConfiguration(XWiki xwiki)
          A helper method for Velocity scripts since we cannot create Java objects from Velocity.
 int sendHtmlMessage(String from, String to, String cc, String bcc, String subject, String body, String alternative, List<Attachment> attachments)
          Sends an HTML mail, with a list of attachments
 int sendMail(Mail mail)
          Generic method for sending emails.
 int sendMail(Mail mail, MailConfiguration mailConfiguration)
          Generic method for sending emails.
 int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, String documentFullName, Map<String,Object> parameters)
          Uses an XWiki document to build the message subject and context, based on variables stored in a map.
 int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language, String documentFullName, org.apache.velocity.VelocityContext vcontext)
          Uses an XWiki document to build the message subject and context, based on variables stored in the VelocityContext.
 int sendRawMessage(String from, String to, String rawMessage)
          Sends a raw message.
 int sendTextMessage(String from, String to, String subject, String message)
          Sends a simple text plain mail
 int sendTextMessage(String from, String to, String cc, String bcc, String subject, String message, List<Attachment> attachments)
          Sends a simple text plain mail with a list of files attachments
 
Methods inherited from class com.xpn.xwiki.plugin.PluginApi
getInternalPlugin, getProtectedPlugin, setPlugin
 
Methods inherited from class com.xpn.xwiki.api.Api
convert, convert, convert, convertAttachments, getXWikiContext, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailSenderPluginApi

public MailSenderPluginApi(MailSenderPlugin plugin,
                           XWikiContext context)
API constructor.

Parameters:
plugin - The wrapped plugin object.
context - Context of the request.
See Also:
PluginApi.PluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface,XWikiContext)
Method Detail

sendHtmlMessage

public int sendHtmlMessage(String from,
                           String to,
                           String cc,
                           String bcc,
                           String subject,
                           String body,
                           String alternative,
                           List<Attachment> attachments)
Description copied from interface: MailSender
Sends an HTML mail, with a list of attachments

Specified by:
sendHtmlMessage in interface MailSender
Parameters:
from - the sender
to - the recipient of the message
cc - carbon copy
bcc - hidden carbon copy
subject - the subject of the message
body - the body content of the mail
alternative - the alternative text offered to the mail client
attachments - List of com.xpn.xwiki.api.Attachment that will be attached to the mail.
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

sendTextMessage

public int sendTextMessage(String from,
                           String to,
                           String subject,
                           String message)
Description copied from interface: MailSender
Sends a simple text plain mail

Specified by:
sendTextMessage in interface MailSender
Parameters:
from - the sender
to - the recipient of the message
subject - the subject of the message
message - the body of the message
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

sendTextMessage

public int sendTextMessage(String from,
                           String to,
                           String cc,
                           String bcc,
                           String subject,
                           String message,
                           List<Attachment> attachments)
Description copied from interface: MailSender
Sends a simple text plain mail with a list of files attachments

Specified by:
sendTextMessage in interface MailSender
Parameters:
from - the sender
to - the recipient of the message
cc - carbon copy
bcc - hidden carbon copy
subject - the subject of the message
message - the body of the message
attachments - List of com.xpn.xwiki.api.Attachment that will be attached to the mail.
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

sendRawMessage

public int sendRawMessage(String from,
                          String to,
                          String rawMessage)
Description copied from interface: MailSender
Sends a raw message. The message can contain additional headers at the start, which are parsed and correctly sent as additional headers (Bcc, Subject, Reply-To, etc.). The actual message is treated as plain text.

Specified by:
sendRawMessage in interface MailSender
Parameters:
from - the sender
to - the receiver
rawMessage - the raw message, containing additional headers and the actual message
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

sendMessageFromTemplate

public int sendMessageFromTemplate(String from,
                                   String to,
                                   String cc,
                                   String bcc,
                                   String language,
                                   String documentFullName,
                                   org.apache.velocity.VelocityContext vcontext)
Description copied from interface: MailSender
Uses an XWiki document to build the message subject and context, based on variables stored in the VelocityContext. Sends the email.

Specified by:
sendMessageFromTemplate in interface MailSender
Parameters:
from - Email sender
to - Email recipient
cc - Email Carbon Copy
bcc - Email Hidden Carbon Copy
language - Language of the email
documentFullName - Full name of the template to be used (example: XWiki.MyEmailTemplate). The template needs to have an XWiki.Email object attached
vcontext - Velocity context passed to the velocity renderer
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

sendMessageFromTemplate

public int sendMessageFromTemplate(String from,
                                   String to,
                                   String cc,
                                   String bcc,
                                   String language,
                                   String documentFullName,
                                   Map<String,Object> parameters)
Uses an XWiki document to build the message subject and context, based on variables stored in a map. Sends the email.

Parameters:
from - Email sender
to - Email recipient
cc - Email Carbon Copy
bcc - Email Hidden Carbon Copy
language - Language of the email
documentFullName - Full name of the template to be used (example: XWiki.MyEmailTemplate). The template needs to have an XWiki.Email object attached
parameters - variables to be passed to the velocity context
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

createMail

public Mail createMail()
Description copied from interface: MailSender
A helper method for Velocity scripts since we cannot create Java objects from Velocity.

Specified by:
createMail in interface MailSender
Returns:
An empty mail message to be populated with recipient addresses, subject, message, etc.

sendMail

public int sendMail(Mail mail)
Description copied from interface: MailSender
Generic method for sending emails. The passed Mail object has to be populated by the caller to set the correct fields. All the other sendHtmlXXX() and sendTextXXX() methods are specialized helper versions of this generic method.

Specified by:
sendMail in interface MailSender
Parameters:
mail - the already populated mail Object to be sent
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.

createMailConfiguration

public MailConfiguration createMailConfiguration(XWiki xwiki)
Description copied from interface: MailSender
A helper method for Velocity scripts since we cannot create Java objects from Velocity.

Specified by:
createMailConfiguration in interface MailSender
Parameters:
xwiki - the XWiki object used to get the default values from the XWiki Preferences ("smtp_server" and "smtp_from").
Returns:
A mail server configuration, initialized with values from XWiki Preferences, but which can be overriden by users.

sendMail

public int sendMail(Mail mail,
                    MailConfiguration mailConfiguration)
Description copied from interface: MailSender
Generic method for sending emails. The passed Mail object has to be populated by the caller to set the correct fields. The passed Mail Configuration allows the user to override the default connection properties (SMTP host, SMTP port, SMTP from, etc). All the other sendHtmlXXX() and sendTextXXX() methods are specialized helper versions of this generic method.

Specified by:
sendMail in interface MailSender
Parameters:
mail - the already populated mail Object to be sent
mailConfiguration - the configuration to use
Returns:
0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the "error" key.


Copyright © 2004-2013 XWiki. All Rights Reserved.