1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.mailsender

File MailSender.java

 

Code metrics

0
0
0
1
151
20
0
-
-
0
-

Classes

Class Line # Actions
MailSender 34 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.plugin.mailsender;
21   
22    import java.util.List;
23    import org.apache.velocity.VelocityContext;
24   
25    import com.xpn.xwiki.api.Attachment;
26    import com.xpn.xwiki.api.XWiki;
27   
28    /**
29    * Send mails to recipients (to, cc, bcc). Both text and HTML emails can be sent along with attachments. Also support
30    * XWiki page templates and allows sending a collection of emails in one call.
31    *
32    * @version $Id: 8907ef7edfeabdfa9463b73166ded8bee8aee1ce $
33    */
 
34    public interface MailSender
35    {
36    /**
37    * A helper method for Velocity scripts since we cannot create Java objects from Velocity.
38    *
39    * @return An empty mail message to be populated with recipient addresses, subject, message, etc.
40    */
41    Mail createMail();
42   
43    /**
44    * A helper method for Velocity scripts since we cannot create Java objects from Velocity.
45    *
46    * @param xwiki the XWiki object used to get the default values from the XWiki Preferences ("smtp_server" and
47    * "smtp_from").
48    * @return A mail server configuration, initialized with values from XWiki Preferences, but which can be overriden
49    * by users.
50    */
51    MailConfiguration createMailConfiguration(XWiki xwiki);
52   
53    /**
54    * Generic method for sending emails. The passed Mail object has to be populated by the caller to set the correct
55    * fields. All the other <code>sendHtmlXXX()</code> and <code>sendTextXXX()</code> methods are specialized helper
56    * versions of this generic method.
57    *
58    * @param mail the already populated mail Object to be sent
59    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
60    * "error" key.
61    */
62    int sendMail(Mail mail);
63   
64    /**
65    * Generic method for sending emails. The passed Mail object has to be populated by the caller to set the correct
66    * fields. The passed Mail Configuration allows the user to override the default connection properties (SMTP host,
67    * SMTP port, SMTP from, etc). All the other <code>sendHtmlXXX()</code> and <code>sendTextXXX()</code> methods are
68    * specialized helper versions of this generic method.
69    *
70    * @param mail the already populated mail Object to be sent
71    * @param mailConfiguration the configuration to use
72    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
73    * "error" key.
74    */
75    int sendMail(Mail mail, MailConfiguration mailConfiguration);
76   
77    /**
78    * Sends an HTML mail, with a list of attachments
79    *
80    * @param to the recipient of the message
81    * @param from the sender
82    * @param cc carbon copy
83    * @param bcc hidden carbon copy
84    * @param subject the subject of the message
85    * @param body the body content of the mail
86    * @param alternative the alternative text offered to the mail client
87    * @param attachments List of com.xpn.xwiki.api.Attachment that will be attached to the mail.
88    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
89    * "error" key.
90    */
91    int sendHtmlMessage(String from, String to, String cc, String bcc, String subject, String body, String alternative,
92    List<Attachment> attachments);
93   
94    /**
95    * Sends a simple text plain mail
96    *
97    * @param to the recipient of the message
98    * @param from the sender
99    * @param subject the subject of the message
100    * @param message the body of the message
101    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
102    * "error" key.
103    */
104    int sendTextMessage(String from, String to, String subject, String message);
105   
106    /**
107    * Sends a simple text plain mail with a list of files attachments
108    *
109    * @param to the recipient of the message
110    * @param from the sender
111    * @param cc carbon copy
112    * @param bcc hidden carbon copy
113    * @param subject the subject of the message
114    * @param message the body of the message
115    * @param attachments List of com.xpn.xwiki.api.Attachment that will be attached to the mail.
116    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
117    * "error" key.
118    */
119    int sendTextMessage(String from, String to, String cc, String bcc, String subject, String message,
120    List<Attachment> attachments);
121   
122    /**
123    * Sends a raw message. The message can contain additional headers at the start, which are parsed and correctly sent
124    * as additional headers (Bcc, Subject, Reply-To, etc.). The actual message is treated as plain text.
125    *
126    * @param from the sender
127    * @param to the receiver
128    * @param rawMessage the raw message, containing additional headers and the actual message
129    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
130    * "error" key.
131    */
132    int sendRawMessage(String from, String to, String rawMessage);
133   
134    /**
135    * Uses an XWiki document to build the message subject and context, based on variables stored in the
136    * VelocityContext. Sends the email.
137    *
138    * @param from Email sender
139    * @param to Email recipient
140    * @param cc Email Carbon Copy
141    * @param bcc Email Hidden Carbon Copy
142    * @param language Language of the email
143    * @param documentFullName Full name of the template to be used (example: XWiki.MyEmailTemplate). The template needs
144    * to have an XWiki.Email object attached
145    * @param vcontext Velocity context passed to the velocity renderer
146    * @return 0 on success, -1 on failure. On failure the error message is stored in the XWiki context under the
147    * "error" key.
148    */
149    int sendMessageFromTemplate(String from, String to, String cc, String bcc, String language,
150    String documentFullName, VelocityContext vcontext);
151    }