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
public final class SendMailHelper extends AbstractLogEnabled implements Disposable
Helper for sending mail
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SendMailHelper.CssRule
private static class
SendMailHelper.CssSpecificity
private static class
SendMailHelper.MailSender
private static class
SendMailHelper.MailSenderThreadFactory
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
__CSS_SPECIFICITY_ATTR_PATTERN
Attribute selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_CLASS_PATTERN
Class selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_ELEMENT_PATTERN
Element selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_ID_PATTERN
ID selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_PSEUDO_CLASS_NOT_PATTERN
Specific :not pseudo-class selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_PSEUDO_CLASS_PATTERN
Pseudo-class selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_PSEUDO_CLASS_WITH_BRACKETS_PATTERN
Pseudo-class (with bracket) selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_PSEUDO_ELEMENT_PATTERN
Pseudo-element selectors pattern for CSS specificity processingprotected static Pattern
__CSS_SPECIFICITY_UNIVERSAL_AND_SEPARATOR_PATTERN
Universal and separator characters pattern for CSS specificity processingprivate static ExecutorService
__SINGLE_THREAD_EXECUTOR
protected static org.slf4j.Logger
_LOGGER
Loggerstatic Pattern
EMAIL_VALIDATION
Regexp to validate an emailstatic String
EMAIL_VALIDATION_REGEXP
Regexp to validate an email
-
Constructor Summary
Constructors Modifier Constructor Description private
SendMailHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static String
_removeComments(String styleRules)
private static String
concatenateProperties(String oldProp, String newProp)
void
dispose()
static String
inlineCSS(String html)
This method inline css in <style> tags directly in the appropriates tags.static void
sendMail(String subject, String htmlBody, String textBody, String recipient, String sender)
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
sendMail(String subject, String htmlBody, String textBody, List<String> recipients, String sender)
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 Detail
-
EMAIL_VALIDATION_REGEXP
public static final String EMAIL_VALIDATION_REGEXP
Regexp to validate an email- See Also:
- Constant Field Values
-
EMAIL_VALIDATION
public static final Pattern EMAIL_VALIDATION
Regexp to validate an email
-
_LOGGER
protected static final org.slf4j.Logger _LOGGER
Logger
-
__CSS_SPECIFICITY_ATTR_PATTERN
protected static final Pattern __CSS_SPECIFICITY_ATTR_PATTERN
Attribute selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_ID_PATTERN
protected static final Pattern __CSS_SPECIFICITY_ID_PATTERN
ID selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_CLASS_PATTERN
protected static final Pattern __CSS_SPECIFICITY_CLASS_PATTERN
Class selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_PSEUDO_ELEMENT_PATTERN
protected static final Pattern __CSS_SPECIFICITY_PSEUDO_ELEMENT_PATTERN
Pseudo-element selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_PSEUDO_CLASS_WITH_BRACKETS_PATTERN
protected static final Pattern __CSS_SPECIFICITY_PSEUDO_CLASS_WITH_BRACKETS_PATTERN
Pseudo-class (with bracket) selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_PSEUDO_CLASS_PATTERN
protected static final Pattern __CSS_SPECIFICITY_PSEUDO_CLASS_PATTERN
Pseudo-class selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_ELEMENT_PATTERN
protected static final Pattern __CSS_SPECIFICITY_ELEMENT_PATTERN
Element selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_PSEUDO_CLASS_NOT_PATTERN
protected static final Pattern __CSS_SPECIFICITY_PSEUDO_CLASS_NOT_PATTERN
Specific :not pseudo-class selectors pattern for CSS specificity processing
-
__CSS_SPECIFICITY_UNIVERSAL_AND_SEPARATOR_PATTERN
protected static final Pattern __CSS_SPECIFICITY_UNIVERSAL_AND_SEPARATOR_PATTERN
Universal and separator characters pattern for CSS specificity processing
-
__SINGLE_THREAD_EXECUTOR
private static final ExecutorService __SINGLE_THREAD_EXECUTOR
-
-
Constructor Detail
-
SendMailHelper
private SendMailHelper()
-
-
Method Detail
-
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
public static String inlineCSS(String html)
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
-
_removeComments
private static String _removeComments(String styleRules)
-
concatenateProperties
private static String concatenateProperties(String oldProp, String newProp)
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
-