| java.lang.Object org.jivesoftware.util.EmailService
EmailService | public class EmailService (Code) | | A service to send email.
This class has a few factory methods you can use to return message objects
or to add messages into a queue to be sent. Using these methods, you can
send emails in the following couple of ways:
EmailService.sendMessage(
"Joe Bloe", "jbloe@place.org",
"Jane Doe", "jane@doe.com",
"Hello...",
"This is the body of the email...",
null
);
or
Message message = EmailService.createMimeMessage();
// call setters on the message object
// .
// .
// .
emailService.sendMessage(message);
This class is configured with a set of Jive properties:
- mail.smtp.host -- the host name of your mail server, i.e.
mail.yourhost.com. The default value is "localhost".
- mail.smtp.port -- an optional property to change the smtp
port used from the default of 25.
- mail.smtp.username -- an optional property to change the
username used to connect to the smtp server. Default is no username.
- mail.smtp.password -- an optional property to change the
password used to connect to the smtp server. Default is no password.
- mail.smtp.ssl -- an optional property to set whether to use
SSL to connect to the smtp server or not. Default is false.
- mail.debugEnabled -- true if debug information should written out.
Default is false.
|
Method Summary | |
public MimeMessage | createMimeMessage() Factory method to return a blank JavaMail message. | public String | getHost() Returns the SMTP host (e.g. | public static EmailService | getInstance() | public String | getPassword() Returns the password used to connect to the SMTP server. | public int | getPort() Returns the port number used when connecting to the SMTP server. | public String | getUsername() Returns the username used to connect to the SMTP server. | public boolean | isDebugEnabled() Returns true if SMTP debugging is enabled. | public boolean | isSSLEnabled() Returns true if SSL is enabled for SMTP connections. | public void | sendMessage(MimeMessage message) Sends a JavaMail message. | public void | sendMessage(String toName, String toEmail, String fromName, String fromEmail, String subject, String textBody, String htmlBody) Sends a message, specifying all of its fields.
To have more advanced control over the message sent, use the
EmailService.sendMessage(MimeMessage) method.
Both a plain text and html body can be specified. | public void | sendMessages(Collection<MimeMessage> messages) Send a collection of messages. | public void | sendMessagesImmediately(Collection<MimeMessage> messages) Sends a collection of email messages. | public void | setDebugEnabled(boolean debugEnabled) Enables or disables SMTP transport layer debugging. | public void | setHost(String host) Sets the SMTP host (e.g. | public void | setPassword(String password) Sets the password that will be used when connecting to the SMTP
server. | public void | setPort(int port) Sets the port number that will be used when connecting to the SMTP
server. | public void | setSSLEnabled(boolean sslEnabled) Sets whether the SMTP connection is configured to use SSL or not. | public void | setUsername(String username) Sets the username that will be used when connecting to the SMTP
server. |
createMimeMessage | public MimeMessage createMimeMessage()(Code) | | Factory method to return a blank JavaMail message. You should use the
object returned and set desired message properties. When done, pass the
object to the addMessage(Message) method.
a new JavaMail message. |
getHost | public String getHost()(Code) | | Returns the SMTP host (e.g. mail.example.com). The default value is "localhost".
the SMTP host. |
getPassword | public String getPassword()(Code) | | Returns the password used to connect to the SMTP server. If the password
is null, no password will be used when connecting to the server.
the password used to connect to the SMTP server, or null ifthere is no password. |
getPort | public int getPort()(Code) | | Returns the port number used when connecting to the SMTP server. The default
port is 25.
the SMTP port. |
getUsername | public String getUsername()(Code) | | Returns the username used to connect to the SMTP server. If the username
is null, no username will be used when connecting to the server.
the username used to connect to the SMTP server, or null ifthere is no username. |
isDebugEnabled | public boolean isDebugEnabled()(Code) | | Returns true if SMTP debugging is enabled. Debug information is
written to System.out by the underlying JavaMail provider.
true if SMTP debugging is enabled. |
isSSLEnabled | public boolean isSSLEnabled()(Code) | | Returns true if SSL is enabled for SMTP connections.
true if SSL is enabled. |
sendMessage | public void sendMessage(MimeMessage message)(Code) | | Sends a JavaMail message. To create a message, use the
EmailService.createMimeMessage() method.
Parameters: message - the message to send. |
sendMessage | public void sendMessage(String toName, String toEmail, String fromName, String fromEmail, String subject, String textBody, String htmlBody)(Code) | | Sends a message, specifying all of its fields.
To have more advanced control over the message sent, use the
EmailService.sendMessage(MimeMessage) method.
Both a plain text and html body can be specified. If one of the values is null,
only the other body type is sent. If both body values are set, a multi-part
message will be sent. If parts of the message are invalid (ie, the toEmail is null)
the message won't be sent.
Parameters: toName - the name of the recipient of this email. Parameters: toEmail - the email address of the recipient of this email. Parameters: fromName - the name of the sender of this email. Parameters: fromEmail - the email address of the sender of this email. Parameters: subject - the subject of the email. Parameters: textBody - plain text body of the email, which can be null if thehtml body is not null. Parameters: htmlBody - html body of the email, which can be null if the text bodyis not null. |
sendMessagesImmediately | public void sendMessagesImmediately(Collection<MimeMessage> messages) throws MessagingException(Code) | | Sends a collection of email messages. This method differs from
EmailService.sendMessages(Collection) in that messages are sent
before this method returns rather than queueing the messages to be sent later.
Parameters: messages - the messages to send. throws: MessagingException - if an error occurs. |
setDebugEnabled | public void setDebugEnabled(boolean debugEnabled)(Code) | | Enables or disables SMTP transport layer debugging. Debug information is
written to System.out by the underlying JavaMail provider.
Parameters: debugEnabled - true if SMTP debugging should be enabled. |
setHost | public void setHost(String host)(Code) | | Sets the SMTP host (e.g. mail.example.com). The default value is "localhost".
Parameters: host - the SMTP host. |
setPassword | public void setPassword(String password)(Code) | | Sets the password that will be used when connecting to the SMTP
server. The default is null, or no password.
Parameters: password - the SMTP password. |
setPort | public void setPort(int port)(Code) | | Sets the port number that will be used when connecting to the SMTP
server. The default is 25, the standard SMTP port number.
Parameters: port - the SMTP port number. |
setSSLEnabled | public void setSSLEnabled(boolean sslEnabled)(Code) | | Sets whether the SMTP connection is configured to use SSL or not.
Typically, the port should be 465 when using SSL with SMTP.
Parameters: sslEnabled - true if ssl should be enabled, false otherwise. |
setUsername | public void setUsername(String username)(Code) | | Sets the username that will be used when connecting to the SMTP
server. The default is null, or no username.
Parameters: username - the SMTP username. |
|
|