Class MailManager
- All Implemented Interfaces:
JPropertiesListener
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of both JCMS property and context map attribute defining a MailMessage behavior.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringName of both JCMS property and context map attribute defining a MailMessage behavior.static final StringName of both JCMS property and context map attribute defining a MailMessage behavior. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAuthKeyToImagesSrc(MailMessage msg, HashMap<String, Object> ctxt) Rewrite the HTML content of the specified MailMessage to add an authentication key to all images URL.static StringaddAuthKeyToImagesSrc(String contentHtml, Member mbr) Add an authentication key to all images URL in the specified HTML content.static voidaddDefaultHeaders(MailMessage msg, HashMap<String, Object> ctxt) An internal method used to add default mail headers configured in properties in the message.static StringbuildContentFromJsp(String jspPath, Member loggedMember, String language, HashMap<Object, Object> requestAttributeMap, HashMap<Object, Object> sessionAttributeMap) Builds a mail content from a given jspcreateDBMailMessage(javax.mail.Message msg) Build a DBMessage from a Message and save in into the DBgetDBMailMessage(String msgid) Returns the DBMailMessage for the given Message IdgetDBMailMessage(javax.mail.Message msg) Returns the DBMailMessage for the given MessageintReturns the count of DBMailMessageintgetDBMailMessageCount(String account) Returns the count of DBMailMessage for given accountCollection<? extends MailMessage> getDBMailMessageReplies(String msgid) Returns the DBMailMessage for the given Message IdgetDBMailMessageSet(String[] ids) Returns a Collection of MailMessage or Message-ID (if not found)Collection<? extends MailMessage> getDBMailMessageThread(String thread) static Set<javax.mail.internet.InternetAddress> getIAFromMemberSet(Set<Member> mbrSet) Returns a Set of InternetAddress build from a Set of Membersstatic StringgetIncomingAddress(String localpart, Member mbr, String label) Returns JCMS incoming email for the given Memberstatic MailManagergetInvalidEmailSet(Set<String> mailSet, Set<Member> mbrSet) Retrieve all INVALID email from the specified mail and member Set.static StringReturns a localpart suffix authkey for given Member.Returns the MailFetchergetMessageIdQuietly(javax.mail.Message msg) Convenient method that delegate to MailFetcher methodprotected Patternprotected Patternprotected Patternstatic voidimproveMailMessageConformity(MailMessage msg, HashMap<String, Object> ctxt) Improve the specified MailMessage conformity with mail sending best practices (if enabled).booleanbooleanprotected booleanvoidpropertiesChange(JProperties properties) Invoked after properties have been modified in JCMS and save on disk.static StringreplaceRelativeUrlsWithAbsoluteUrls(String contentHtml) Convert all relative URLs inside the specified HTML content into absolute URL.static MemberresolveAddress(String addr) Retrieves the Member from the given E-mail.resolveAddress(Set<String> addressSet) Retrieves the set of Members given the set of E-mail addresses.static voidresolveAddresses(MailMessage mail) Updates the given mailMessage's addresses field.voidsaveDBMailMessage(MailMessage mail, Map<String, Object> context) Build a DBMessage from a Message and save in into the DBbooleansendMessage(MailMessage msg, boolean catchMailErrors) Send 1 Mail.sendMessages(MailMessage[] msgs, boolean catchMailErrors) Send n Mails.sendMessages(List<MailMessage> msgList, boolean catchMailErrors) Send n Mails.protected booleanwriteEml(javax.mail.Message msg) Deprecated.The method is deprecated, See MessageUtil.writeEml to the new implementation
-
Field Details
-
MAIL_ACCOUNT_PROP_PREFIX
- See Also:
-
LEGACY
- See Also:
-
MAIL_ABSOLUTE_URL_CONVERSION_REGEX
- See Also:
-
MAIL_ADD_IMAGES_AUTHKEY_REGEX
- See Also:
-
MAIL_SRCSET_REGEX
- See Also:
-
MAIL_INCOMING_ENABLED
- See Also:
-
MAIL_PROVIDER_PREFIX
- See Also:
-
MAIL_SEND_PROVIDER_NAME
- See Also:
-
SET_AUTO_GENERATED
Name of both JCMS property and context map attribute defining a MailMessage behavior.The value is a boolean which defines if MailMessage should be sent using the header
Auto-Submitted: auto-generated(RFC 3834 ยง5.2) to indicate mail was automatically generated.Value can be specified :
- in JCMS properties (its default value is true)
- in context map attribute of
MailMessage.send(HashMap)method (this value overrides the behavior of JCMS property)
- Since:
- JCMS-9853
- See Also:
-
SEND_WITH_SITE_EMAIL
Name of both JCMS property and context map attribute defining a MailMessage behavior.The value is a boolean which defines if MailMessage should be sent using the Member name and e-mail, or using the user name but with the site e-mail address.
If set totrue, mail are sent using the site default email address, and the original Member is used in the ReplyTo header.
If set tofalse, mail are sent using original member email address.Value can be specified :
- in JCMS properties (its default value is true)
- in context map attribute of
MailMessage.send(HashMap)method (this value overrides the behavior of JCMS property)
- Since:
- JCMS-3740
- See Also:
-
mailHeaderMap
-
ADD_IMAGES_AUTHKEY
Name of both JCMS property and context map attribute defining a MailMessage behavior.The value is a boolean which defines if MailMessage should be modified to add authentication key to all images source URL to allow images to mailer without any authentication.
If set totrue, authkey are added to URL.
If set tofalse, default behavior is applied.Value can be specified :
- in JCMS properties (its default value is true)
- in context map attribute of
MailMessage.send(HashMap)method (this value overrides the behavior of JCMS property)
- Since:
- JCMS-2677
- See Also:
-
-
Method Details
-
addDefaultHeaders
An internal method used to add default mail headers configured in properties in the message.Mail headers are read from properties
mail.header.{Header-Name}: {Header-Value}- Parameters:
msg- the MailMessage to modifyctxt- the context map attribute ofMailMessage.send(HashMap), MUST NOT be null- Since:
- jcms-10.0.7 / JCMS-9854
-
getInstance
-
propertiesChange
Description copied from interface:JPropertiesListenerInvoked after properties have been modified in JCMS and save on disk.You cannot alter the value received in parameters.
Note that properties parameter may be null, a limited set of site properties, or all site properties.
To check that a property has been modified, reload the "current" property instead using
channel.getPropertiesorchannel.getProperty.- Specified by:
propertiesChangein interfaceJPropertiesListener- Parameters:
properties- the properties which have been submitted to change
-
isIncomingMailEnabled
public boolean isIncomingMailEnabled() -
isEnabled
public boolean isEnabled() -
getSrcLinkPattern
-
getUrlPattern
-
getSrcsetPattern
-
isSendWithSiteEmail
protected boolean isSendWithSiteEmail() -
setAutoGeneratedHeader
protected boolean setAutoGeneratedHeader() -
getSendMailProvider
-
getProviderMap
-
getProviderClassMap
-
sendMessage
Send 1 Mail. Do not throw exceptions. Warning: This method only fail and return a list of error when a Message could not be build or sent, but it DOES not failed and return anything when the connection to the remote service cannot be established.- Parameters:
msg- theMailMessageto sendcatchMailErrors- set to true to prevent this method to throw exception when sending messages- Returns:
- true is the mail has been delivered (false if exceptions thrown during sending of mails)
-
sendMessages
Send n Mails. Do not throw exceptions. Warning: This method only fail and return a list of error when a Message could not be build or sent, but it DOES not failed and return anything when the connection to the remote service cannot be established.- Parameters:
msgList- the list ofMailMessageto sendcatchMailErrors- set to true to prevent this method to throw exception when sending messages- Returns:
- a list of recipient String that throws exceptions during sending of mails
-
sendMessages
Send n Mails. Do not throw exceptions. Warning: This method only fail and return a list of error when a Message could not be build or sent, but it DOES not failed and return anything when the connection to the remote service cannot be established.- Parameters:
msgs- the array ofMailMessageto sendcatchMailErrors- set to true to prevent this method to throw exception when sending messages- Returns:
- a list of recipient String that throws exceptions during sending of mails
-
getDBMailMessageSet
Returns a Collection of MailMessage or Message-ID (if not found)- Parameters:
ids- a list of Message-ID- Returns:
- Collection of MailMessage or Message-ID
-
getDBMailMessageCount
public int getDBMailMessageCount()Returns the count of DBMailMessage- Returns:
- int the DBMailMessageCount
-
getDBMailMessageCount
Returns the count of DBMailMessage for given account- Parameters:
account- the account name- Returns:
- int the DBMailMessageCount
-
getDBMailMessage
Returns the DBMailMessage for the given Message- Parameters:
msg- a javax.mail.Message- Returns:
- a DBMailMessage stored in db
-
getDBMailMessage
Returns the DBMailMessage for the given Message Id- Parameters:
msgid- the message id- Returns:
- a DBMailMessage stored in db
-
getDBMailMessageReplies
Returns the DBMailMessage for the given Message Id- Parameters:
msgid- the message id- Returns:
- a DBMailMessage stored in db
-
getDBMailMessageThread
-
createDBMailMessage
Build a DBMessage from a Message and save in into the DB- Parameters:
msg- a javax.mail.Message- Returns:
- MailMessage instanciate or null if exception appends
-
saveDBMailMessage
Build a DBMessage from a Message and save in into the DB- Parameters:
mail- the MailMessagecontext- the contextual map
-
writeEml
Deprecated.The method is deprecated, See MessageUtil.writeEml to the new implementationWrite aMessageto a file- Parameters:
msg- theMessage- Returns:
- the File with the message saved in
-
getMailFetcher
Returns the MailFetcher- Returns:
- MailFetcher
-
getMessageIdQuietly
Convenient method that delegate to MailFetcher method- Parameters:
msg- the javax.mail.Message- Returns:
- String the message Id or null
- See Also:
-
improveMailMessageConformity
Improve the specified MailMessage conformity with mail sending best practices (if enabled).Implementation details
If following criterias are met :
- property
mail.send-with-site-emailis set totrue - attribute
mail.send-with-site-emailis either undefined or set totruein the context map (this attribute overrides behavior of JCMS property) MailMessage.getFromMember()is notnullMailMessage.getReplyToMember()isnullor is the same member specified inMailMessage.getFromMember()
- the FromMember is used as the ReplyToMember
- the From header as
"{Member Full Name} ({Site Name}) <{default-email or admin-email}>" - the FromMember is removed
- Parameters:
msg- the MailMessage to modify if criterias are metctxt- the context map attribute ofMailMessage.send(HashMap), MUST NOT be null- Since:
- JCMS-3740, updated with JCMS-9853
- property
-
addAuthKeyToImagesSrc
Rewrite the HTML content of the specified MailMessage to add an authentication key to all images URL.It allows mailer to access images without any authentication.
Default behavior is to perform this operation only when the site is private.
Since improvement JCMS-2677, the operation can be forced if :- property
mail.add-images-authkeyis set totrue - attribute
mail.add-images-authkeyis set totruein the context map (this attribute overrides behavior of JCMS property)
Authkeys are added only if the message is sent on one and only one Member.
- Parameters:
msg- the MailMessage to modify if criterias are metctxt- the context map attribute ofMailMessage.send(HashMap), MUST NOT be null- Since:
- JCMS-2677
- property
-
addAuthKeyToImagesSrc
Add an authentication key to all images URL in the specified HTML content.All image URL in tag src='...' are modified to add an authkey.
- Parameters:
contentHtml- html content to updatembr- the recipient member- Returns:
- String the modified content
-
replaceRelativeUrlsWithAbsoluteUrls
Convert all relative URLs inside the specified HTML content into absolute URL.Uses the current channel URL as prefix of relative URL.
- Parameters:
contentHtml- the HTML content in which to look for relative URL (in src and href attributes)- Returns:
- the modified content
-
getIncomingAddress
Returns JCMS incoming email for the given Member- Parameters:
localpart- the mail prefixmbr- Member author of the maillabel- the email label- Returns:
- String valid incoming email
-
getLocalPartSuffixAuthKey
Returns a localpart suffix authkey for given Member.- Parameters:
mbr- the member- Returns:
- String localpart sufix authkey (starting with +)
-
getIAFromMemberSet
public static Set<javax.mail.internet.InternetAddress> getIAFromMemberSet(Set<Member> mbrSet) throws javax.mail.MessagingException Returns a Set of InternetAddress build from a Set of Members- Parameters:
mbrSet- a Set of Members- Returns:
- Set of InternetAddress
- Throws:
javax.mail.MessagingException- a base class for all exceptions thrown by the Messaging classes
-
getInvalidEmailSet
Retrieve all INVALID email from the specified mail and member Set.- Parameters:
mailSet- a set of email addressesmbrSet- a set of Member- Returns:
- a set of invalid email
- Since:
- jcms-6.1
-
buildContentFromJsp
public static String buildContentFromJsp(String jspPath, Member loggedMember, String language, HashMap<Object, Object> requestAttributeMap, HashMap<Object, Object> sessionAttributeMap) Builds a mail content from a given jsp- Parameters:
jspPath- the jsp to processloggedMember- the loggedMemberlanguage- the user languagerequestAttributeMap- Map of request attributessessionAttributeMap- Map of session attributes- Returns:
- String builded content
-
resolveAddresses
Updates the given mailMessage's addresses field.String addresses will be resolved to Members if possible.
optional already set Members will be kept.
- Parameters:
mail- the mail to resolved String email to Members.- Since:
- jcms-9.0
-
resolveAddress
Retrieves the Member from the given E-mail.- Parameters:
addr- an email address that will be parsed usingMailUtil.getInternetAddress(String)- Returns:
- the Member from E-mail if any
- Since:
- jcms-9.0
-
resolveAddress
Retrieves the set of Members given the set of E-mail addresses.Retrieved Member's E-mail will be removed from
addressSetwhen resolved.- Parameters:
addressSet- the set of E-mails to retrieve their related Member if any- Returns:
- the Set of Member
- Since:
- jcms-9.0
-