Package org.ametys.core.util.mail
Class SendMailHelper
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.core.util.mail.SendMailHelper
- All Implemented Interfaces:
Disposable
,LogEnabled
Helper for sending mail
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final Pattern
Attribute selectors pattern for CSS specificity processingprotected static final Pattern
Class selectors pattern for CSS specificity processingprotected static final Pattern
Element selectors pattern for CSS specificity processingprotected static final Pattern
ID selectors pattern for CSS specificity processingprotected static final Pattern
Specific :not pseudo-class selectors pattern for CSS specificity processingprotected static final Pattern
Pseudo-class selectors pattern for CSS specificity processingprotected static final Pattern
Pseudo-class (with bracket) selectors pattern for CSS specificity processingprotected static final Pattern
Pseudo-element selectors pattern for CSS specificity processingprotected static final Pattern
Universal and separator characters pattern for CSS specificity processingprotected static final Logger
Loggerstatic final Pattern
Regexp to validate an emailstatic final String
Regexp to validate an email -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
static String
This method inline css in <style> tags directly in the appropriates tags.static void
Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, String recipient, String sender, boolean async) Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, String recipient, String sender, String host, long port, String securityProtocol, boolean async) Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, String recipient, String sender, String host, long port, String securityProtocol, String user, String password, boolean async) Sends mail with authentication, without attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async) Sends mail with authentication and attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, boolean async) Sends mail without authentication, with attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async) Sends mail with authentication and attachments.static void
sendMail
(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async, boolean singleEmail) Sends mail with authentication and attachments.static void
Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, List<String> recipients, String sender, boolean async) Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, List<String> recipients, String sender, String host, long port, String securityProtocol, boolean async) Sends mail without authentication or attachments.static void
sendMail
(String subject, String htmlBody, String textBody, List<String> recipients, String sender, String host, long port, String securityProtocol, String user, String password, boolean async) Sends mail with authentication, without attachments.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
EMAIL_VALIDATION_REGEXP
Regexp to validate an email- See Also:
-
EMAIL_VALIDATION
Regexp to validate an email -
_LOGGER
Logger -
__CSS_SPECIFICITY_ATTR_PATTERN
Attribute selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_ID_PATTERN
ID selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_CLASS_PATTERN
Class selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_PSEUDO_ELEMENT_PATTERN
Pseudo-element selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_PSEUDO_CLASS_WITH_BRACKETS_PATTERN
Pseudo-class (with bracket) selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_PSEUDO_CLASS_PATTERN
Pseudo-class selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_ELEMENT_PATTERN
Element selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_PSEUDO_CLASS_NOT_PATTERN
Specific :not pseudo-class selectors pattern for CSS specificity processing -
__CSS_SPECIFICITY_UNIVERSAL_AND_SEPARATOR_PATTERN
Universal and separator characters pattern for CSS specificity processing
-
-
Method Details
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, String recipient, String sender) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipient
- The recipient addresssender
- The sender address- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, List<String> recipients, String sender) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipients
- The recipients addressessender
- The sender address- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, String recipient, String sender, boolean async) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipient
- The recipient addresssender
- The sender addressasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, List<String> recipients, String sender, boolean async) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipients
- The recipients addressessender
- The sender addressasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, String recipient, String sender, String host, long port, String securityProtocol, boolean async) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipient
- The recipient addresssender
- The sender addresshost
- The server mail hostport
- The server mail portsecurityProtocol
- The server mail security protocolasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, List<String> recipients, String sender, String host, long port, String securityProtocol, boolean async) throws javax.mail.MessagingException Sends mail without authentication or attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipients
- The recipients addressessender
- The sender addresshost
- The server mail hostport
- The server mail portsecurityProtocol
- The server mail security protocolasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, String recipient, String sender, String host, long port, String securityProtocol, String user, String password, boolean async) throws javax.mail.MessagingException Sends mail with authentication, without attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipient
- The recipient addresssender
- The sender addresshost
- The server mail hostport
- The server portsecurityProtocol
- The server mail security protocoluser
- The user namepassword
- The user passwordasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, List<String> recipients, String sender, String host, long port, String securityProtocol, String user, String password, boolean async) throws javax.mail.MessagingException Sends mail with authentication, without attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.recipients
- The recipients addressessender
- The sender addresshost
- The server mail hostport
- The server portsecurityProtocol
- The server mail security protocoluser
- The user namepassword
- The user passwordasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending email
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipient
- The recipient addresssender
- The sender address- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender address- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipient
- The recipient addresssender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.async
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.async
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipient
- The recipient addresssender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.async
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.async
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipient
- The recipient addresssender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.host
- The server mail hostport
- The server portsecurityProtocol
- The server mail security protocolasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, boolean async) throws javax.mail.MessagingException, IOException Sends mail without authentication, with attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender addresscc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.host
- The server mail hostport
- The server portsecurityProtocol
- The server mail security protocolasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, String recipient, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async) throws javax.mail.MessagingException, IOException Sends mail with authentication and attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipient
- The recipient addresssender
- The sender address. Can be null when called by MailChecker.cc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.host
- The server mail host. Can be null when called by MailChecker.securityProtocol
- the security protocol to use when transporting the emailport
- The server portuser
- The user namepassword
- The user passwordasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async) throws javax.mail.MessagingException, IOException Sends mail with authentication and attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender address. Can be null when called by MailChecker.cc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.host
- The server mail host. Can be null when called by MailChecker.securityProtocol
- the security protocol to use when transporting the emailport
- The server portuser
- The user namepassword
- The user passwordasync
- True to use asynchronous mail sending- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
sendMail
public static void sendMail(String subject, String htmlBody, String textBody, Collection<File> attachments, List<String> recipients, String sender, List<String> cc, List<String> bcc, boolean deliveryReceipt, boolean readReceipt, String host, long port, String securityProtocol, String user, String password, boolean async, boolean singleEmail) throws javax.mail.MessagingException, IOException Sends mail with authentication and attachments.- Parameters:
subject
- The mail subjecthtmlBody
- The HTML mail body. Can be null.textBody
- The text mail body. Can be null.attachments
- the file attachments. Can be null.recipients
- The recipients addressessender
- The sender address. Can be null when called by MailChecker.cc
- Carbon copy address list. Can be null.bcc
- Blind carbon copy address list. Can be null.deliveryReceipt
- true to request that the receiving mail server send a notification when the mail is received.readReceipt
- true to request that the receiving mail client send a notification when the person opens the mail.host
- The server mail host. Can be null when called by MailChecker.securityProtocol
- the security protocol to use when transporting the emailport
- The server portuser
- The user namepassword
- The user passwordasync
- True to use asynchronous mail sendingsingleEmail
- true if just one email is sent with all recipients. Otherwise, an email will be sent for each recipients.- Throws:
javax.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-
inlineCSS
This method inline css in <style> tags directly in the appropriates tags. e.g. : <style>h1 {color: red;}</style> <h1>a</h1> becomes <h1 style="color: red">a</h1>- Parameters:
html
- The initial non null html- Returns:
- The inlined html
-
dispose
- Specified by:
dispose
in interfaceDisposable
-