org.olat.core.util.mail
Class MailHelper

java.lang.Object
  extended by org.olat.core.util.mail.MailHelper

public class MailHelper
extends java.lang.Object

Description:
Some mail helpers

Initial Date: 21.11.2006

Author:
Florian Gnaegi, frentix GmbH
http://www.frentix.com

Constructor Summary
MailHelper()
           
 
Method Summary
static void appendErrorsAndWarnings(MailerResult mailerResult, java.lang.StringBuilder errors, java.lang.StringBuilder warnings, java.util.Locale locale)
          Method to evaluate the mailer result.
static javax.mail.internet.MimeMessage createMessage()
          Create a configures mail message object that is ready to use
static javax.mail.internet.MimeMessage createMessage(javax.mail.Address from, javax.mail.Address[] recipients, javax.mail.Address[] recipientsCC, javax.mail.Address[] recipientsBCC, java.lang.String body, java.lang.String subject, java.io.File[] attachments, MailerResult result)
          create MimeMessage from given fields, this may be used for creation of the email but sending it later.
static java.lang.String getMailFooter(java.util.Locale locale, Identity sender)
          Create a mail footer for the given locale and sender.
static java.lang.Object getMailhost()
           
static java.lang.String getMessageForFailedUsersError(java.util.Locale locale, java.util.List<Identity> disabledIdentities)
           
static java.lang.String getTitleForFailedUsersError(java.util.Locale locale)
           
static boolean isValidEmailAddress(java.lang.String mailAddress)
          Checks if the given mail address is potentially a valid email address that can be used to send emails.
static void printErrorsAndWarnings(MailerResult mailerResult, WindowControl wControl, java.util.Locale locale)
          Method to evaluate the mailer result and disply general error and warning messages.
static MailerResult removeDisabledMailAddress(java.util.List<Identity> identities, MailerResult result)
          check for disabled mail address
static void sendMessage(javax.mail.Address from, javax.mail.Address[] recipients, javax.mail.Address[] recipientsCC, javax.mail.Address[] recipientsBCC, java.lang.String body, java.lang.String subject, java.io.File[] attachments, MailerResult result)
          Send an email message to the given TO, CC and BCC address.
static void sendMessage(javax.mail.internet.MimeMessage msg, MailerResult result)
          send email with MimeMessage available
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailHelper

public MailHelper()
Method Detail

createMessage

public static javax.mail.internet.MimeMessage createMessage()
Create a configures mail message object that is ready to use

Returns:
MimeMessage

createMessage

public static javax.mail.internet.MimeMessage createMessage(javax.mail.Address from,
                                                            javax.mail.Address[] recipients,
                                                            javax.mail.Address[] recipientsCC,
                                                            javax.mail.Address[] recipientsBCC,
                                                            java.lang.String body,
                                                            java.lang.String subject,
                                                            java.io.File[] attachments,
                                                            MailerResult result)
create MimeMessage from given fields, this may be used for creation of the email but sending it later. E.g. previewing the email first.

Parameters:
from -
recipients -
recipientsCC -
recipientsBCC -
body -
subject -
attachments -
result -
Returns:

sendMessage

public static void sendMessage(javax.mail.Address from,
                               javax.mail.Address[] recipients,
                               javax.mail.Address[] recipientsCC,
                               javax.mail.Address[] recipientsBCC,
                               java.lang.String body,
                               java.lang.String subject,
                               java.io.File[] attachments,
                               MailerResult result)
Send an email message to the given TO, CC and BCC address. The result will be stored in the result object. The message can contain attachments.
At this point HTML mails are not supported.

Parameters:
from - Address used as sender address. Must not be NULL
recipients - Address array used as sender addresses. Must not be NULL and contain at lease one address
recipientsCC - Address array used as CC addresses. Can be NULL
recipientsBCC - Address array used as BCC addresses. Can be NULL
body - Body text of message. Must not be NULL
subject - Subject text of message. Must not be NULL
attachments - File array used as attachments. Can be NULL
result - MailerResult object that stores the result code

sendMessage

public static void sendMessage(javax.mail.internet.MimeMessage msg,
                               MailerResult result)
send email with MimeMessage available

Parameters:
msg -
result -

getMailhost

public static java.lang.Object getMailhost()
Returns:
the configured mail host. Can be null, indicating that the system should not send any mail at all

getMailFooter

public static java.lang.String getMailFooter(java.util.Locale locale,
                                             Identity sender)
Create a mail footer for the given locale and sender.

Parameters:
locale - Defines language of footer text. If null, the systems default locale is used
sender - Details about sender embedded in mail footer. If null no such details are attached to the footer
Returns:
The mail footer as string

getTitleForFailedUsersError

public static java.lang.String getTitleForFailedUsersError(java.util.Locale locale)

getMessageForFailedUsersError

public static java.lang.String getMessageForFailedUsersError(java.util.Locale locale,
                                                             java.util.List<Identity> disabledIdentities)

printErrorsAndWarnings

public static void printErrorsAndWarnings(MailerResult mailerResult,
                                          WindowControl wControl,
                                          java.util.Locale locale)
Method to evaluate the mailer result and disply general error and warning messages. If you want to display other messages instead you have to evaluate the mailer result yourself and print messages accordingly.

Parameters:
mailerResult - The mailer result to be evaluated
wControl - The current window controller
locale - The users local

appendErrorsAndWarnings

public static void appendErrorsAndWarnings(MailerResult mailerResult,
                                           java.lang.StringBuilder errors,
                                           java.lang.StringBuilder warnings,
                                           java.util.Locale locale)
Method to evaluate the mailer result. The errors and warnings will be attached to the given string buffers. If you want to display other messages instead you have to evaluate the mailer result yourself and print messages accordingly.

Parameters:
mailerResult - The mailer result to be evaluated
errors - StringBuilder for the error messages
warnings - StringBuilder for the warnings
locale - The users local

isValidEmailAddress

public static boolean isValidEmailAddress(java.lang.String mailAddress)
Checks if the given mail address is potentially a valid email address that can be used to send emails. It does NOT check if the mail address exists, it checks only for syntactical validity.

Parameters:
mailAddress -
Returns:

removeDisabledMailAddress

public static MailerResult removeDisabledMailAddress(java.util.List<Identity> identities,
                                                     MailerResult result)
check for disabled mail address

Parameters:
recipients -
result -
Returns: