Class DefaultEmailService
- java.lang.Object
-
- de.hybris.platform.acceleratorservices.email.impl.DefaultEmailService
-
- All Implemented Interfaces:
EmailService
public class DefaultEmailService extends java.lang.Object implements EmailService
Service to create and send emails.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEMAIL_BODY_ENCODINGDeprecated.As of release 6.7, replaced byStandardCharsets.UTF_8static intEMAIL_BODY_MAX_LENGTHstatic java.lang.StringEMAIL_BODY_MAX_LENGTH_KEYstatic java.lang.StringEMAIL_BODY_MIME_TYPEstatic java.lang.StringEMAILSERVICE_SEND_ENABLED_CONFIG_KEY
-
Constructor Summary
Constructors Constructor Description DefaultEmailService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddReplyTo(EmailMessageModel message, org.apache.commons.mail.HtmlEmail email)protected java.util.List<java.lang.String>convertToStrings(java.util.List<EmailAddressModel> addresses)protected MediaModelcreateBodyMedia(java.lang.String bodyMediaName, java.lang.String body)Method creates MediaModel object for storing email bodyEmailAttachmentModelcreateEmailAttachment(java.io.DataInputStream masterDataStream, java.lang.String filename, java.lang.String mimeType)Creates an email attachment from an input stream.EmailMessageModelcreateEmailMessage(java.util.List<EmailAddressModel> toAddresses, java.util.List<EmailAddressModel> ccAddresses, java.util.List<EmailAddressModel> bccAddresses, EmailAddressModel fromAddress, java.lang.String replyToAddress, java.lang.String subject, java.lang.String body, java.util.List<EmailAttachmentModel> attachments)Creates and EmailMessage object.protected javax.mail.internet.InternetAddresscreateInternetAddress(java.lang.String emailAddress, java.lang.String displayName)protected java.util.Collection<javax.mail.internet.InternetAddress>getAddresses(java.util.List<EmailAddressModel> emailAddresses)protected java.lang.StringgetBody(EmailMessageModel message)Method checks which attribute is storing email body (bodyMedia or body) and return its content as stringprotected CatalogServicegetCatalogService()protected CatalogVersionModelgetCatalogVersion()protected CatalogVersionServicegetCatalogVersionService()protected ConfigurationServicegetConfigurationService()protected EmailAddressFetchStrategygetEmailAddressFetchStrategy()protected MediaFolderModelgetEmailAttachmentsMediaFolder()protected java.lang.StringgetEmailAttachmentsMediaFolderName()protected MediaFolderModelgetEmailBodyMediaFolder()protected java.lang.StringgetEmailBodyMediaFolderName()protected MediaServicegetMediaService()protected ModelServicegetModelService()EmailAddressModelgetOrCreateEmailAddressForEmail(java.lang.String emailAddress, java.lang.String displayName)Returns aEmailAddressModel.protected org.apache.commons.mail.HtmlEmailgetPerConfiguredEmail()protected voidlogDebugException(java.lang.Exception e)protected voidlogInfo(EmailMessageModel message, org.apache.commons.mail.EmailException e)protected java.lang.StringnullifyEmpty(java.lang.String str)protected booleanprocessAttachmentsSuccessful(org.apache.commons.mail.HtmlEmail email, java.util.List<EmailAttachmentModel> attachments)booleansend(EmailMessageModel message)Sends an emailprotected voidsetAddresses(EmailMessageModel message, org.apache.commons.mail.HtmlEmail email, java.util.List<EmailAddressModel> toAddresses)voidsetCatalogService(CatalogService catalogService)voidsetCatalogVersionService(CatalogVersionService catalogVersionService)voidsetConfigurationService(ConfigurationService configurationService)voidsetEmailAddressFetchStrategy(EmailAddressFetchStrategy emailAddressFetchStrategy)voidsetEmailAttachmentsMediaFolderName(java.lang.String emailAttachmentsMediaFolderName)voidsetEmailBodyMediaFolderName(java.lang.String emailBodyMediaFolderName)voidsetMediaService(MediaService mediaService)voidsetModelService(ModelService modelService)protected voidvalidateAddresses(java.util.List<EmailAddressModel> toAddresses, EmailAddressModel fromAddress)protected voidvalidateContent(java.lang.String subject, java.lang.String body)protected voidvalidateEmailAddress(java.lang.String address, java.lang.String type)
-
-
-
Field Detail
-
EMAIL_BODY_ENCODING
@Deprecated(since="6.7") public static final java.lang.String EMAIL_BODY_ENCODING
Deprecated.As of release 6.7, replaced byStandardCharsets.UTF_8- See Also:
- Constant Field Values
-
EMAILSERVICE_SEND_ENABLED_CONFIG_KEY
public static final java.lang.String EMAILSERVICE_SEND_ENABLED_CONFIG_KEY
- See Also:
- Constant Field Values
-
EMAIL_BODY_MAX_LENGTH
public static final int EMAIL_BODY_MAX_LENGTH
- See Also:
- Constant Field Values
-
EMAIL_BODY_MAX_LENGTH_KEY
public static final java.lang.String EMAIL_BODY_MAX_LENGTH_KEY
- See Also:
- Constant Field Values
-
EMAIL_BODY_MIME_TYPE
public static final java.lang.String EMAIL_BODY_MIME_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getOrCreateEmailAddressForEmail
public EmailAddressModel getOrCreateEmailAddressForEmail(java.lang.String emailAddress, java.lang.String displayName)
Description copied from interface:EmailServiceReturns aEmailAddressModel. Instance is found for the given email address and display name criteria. If there is no instance for this condition the newEmailAddressModelinstance is returned based on the given criteria.- Specified by:
getOrCreateEmailAddressForEmailin interfaceEmailService- Parameters:
emailAddress- Email iddisplayName- Display name- Returns:
- EmailAddress object
-
createEmailAttachment
public EmailAttachmentModel createEmailAttachment(java.io.DataInputStream masterDataStream, java.lang.String filename, java.lang.String mimeType)
Description copied from interface:EmailServiceCreates an email attachment from an input stream.- Specified by:
createEmailAttachmentin interfaceEmailService- Parameters:
masterDataStream- Input data streamfilename- File namemimeType- Mime type- Returns:
- EmailAttachment object
-
getEmailAttachmentsMediaFolder
protected MediaFolderModel getEmailAttachmentsMediaFolder()
-
getEmailBodyMediaFolder
protected MediaFolderModel getEmailBodyMediaFolder()
-
createEmailMessage
public EmailMessageModel createEmailMessage(java.util.List<EmailAddressModel> toAddresses, java.util.List<EmailAddressModel> ccAddresses, java.util.List<EmailAddressModel> bccAddresses, EmailAddressModel fromAddress, java.lang.String replyToAddress, java.lang.String subject, java.lang.String body, java.util.List<EmailAttachmentModel> attachments)
Description copied from interface:EmailServiceCreates and EmailMessage object.- Specified by:
createEmailMessagein interfaceEmailService- Parameters:
toAddresses- List of To email addressesccAddresses- List of CC email addressesbccAddresses- List of BCC email addressesfromAddress- From email addressreplyToAddress- Reply To email addresssubject- Subject of the emailbody- Contents of the emailattachments- List of email attachments- Returns:
- EmailMessage object
-
validateAddresses
protected void validateAddresses(java.util.List<EmailAddressModel> toAddresses, EmailAddressModel fromAddress)
-
validateContent
protected void validateContent(java.lang.String subject, java.lang.String body)
-
createBodyMedia
protected MediaModel createBodyMedia(java.lang.String bodyMediaName, java.lang.String body)
Method creates MediaModel object for storing email body- Parameters:
bodyMediaName- - name for created objectbody- - content of email body- Returns:
- created MediaModel object
-
getCatalogVersion
protected CatalogVersionModel getCatalogVersion()
-
validateEmailAddress
protected void validateEmailAddress(java.lang.String address, java.lang.String type)
-
send
public boolean send(EmailMessageModel message)
Description copied from interface:EmailServiceSends an email- Specified by:
sendin interfaceEmailService- Parameters:
message- EmailMessage- Returns:
- true if successful
-
addReplyTo
protected void addReplyTo(EmailMessageModel message, org.apache.commons.mail.HtmlEmail email) throws org.apache.commons.mail.EmailException
- Throws:
org.apache.commons.mail.EmailException
-
logInfo
protected void logInfo(EmailMessageModel message, org.apache.commons.mail.EmailException e)
-
processAttachmentsSuccessful
protected boolean processAttachmentsSuccessful(org.apache.commons.mail.HtmlEmail email, java.util.List<EmailAttachmentModel> attachments)
-
setAddresses
protected void setAddresses(EmailMessageModel message, org.apache.commons.mail.HtmlEmail email, java.util.List<EmailAddressModel> toAddresses) throws org.apache.commons.mail.EmailException
- Throws:
org.apache.commons.mail.EmailException
-
getPerConfiguredEmail
protected org.apache.commons.mail.HtmlEmail getPerConfiguredEmail() throws org.apache.commons.mail.EmailException- Throws:
org.apache.commons.mail.EmailException
-
getBody
protected java.lang.String getBody(EmailMessageModel message)
Method checks which attribute is storing email body (bodyMedia or body) and return its content as string- Parameters:
message- - email message object- Returns:
- email body
-
nullifyEmpty
protected java.lang.String nullifyEmpty(java.lang.String str)
-
getAddresses
protected java.util.Collection<javax.mail.internet.InternetAddress> getAddresses(java.util.List<EmailAddressModel> emailAddresses)
-
createInternetAddress
protected javax.mail.internet.InternetAddress createInternetAddress(java.lang.String emailAddress, java.lang.String displayName) throws org.apache.commons.mail.EmailException- Throws:
org.apache.commons.mail.EmailException
-
convertToStrings
protected java.util.List<java.lang.String> convertToStrings(java.util.List<EmailAddressModel> addresses)
-
logDebugException
protected void logDebugException(java.lang.Exception e)
-
getEmailAddressFetchStrategy
protected EmailAddressFetchStrategy getEmailAddressFetchStrategy()
-
setEmailAddressFetchStrategy
public void setEmailAddressFetchStrategy(EmailAddressFetchStrategy emailAddressFetchStrategy)
-
getEmailAttachmentsMediaFolderName
protected java.lang.String getEmailAttachmentsMediaFolderName()
-
setEmailAttachmentsMediaFolderName
public void setEmailAttachmentsMediaFolderName(java.lang.String emailAttachmentsMediaFolderName)
-
getEmailBodyMediaFolderName
protected java.lang.String getEmailBodyMediaFolderName()
-
setEmailBodyMediaFolderName
public void setEmailBodyMediaFolderName(java.lang.String emailBodyMediaFolderName)
-
getModelService
protected ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getMediaService
protected MediaService getMediaService()
-
setMediaService
public void setMediaService(MediaService mediaService)
-
getConfigurationService
protected ConfigurationService getConfigurationService()
-
setConfigurationService
public void setConfigurationService(ConfigurationService configurationService)
-
getCatalogVersionService
protected CatalogVersionService getCatalogVersionService()
-
setCatalogVersionService
public void setCatalogVersionService(CatalogVersionService catalogVersionService)
-
getCatalogService
protected CatalogService getCatalogService()
-
setCatalogService
public void setCatalogService(CatalogService catalogService)
-
-