Email Customization Hybris
Email Customization Hybris
Contents
Introduction:................................................................................................................................................1
Email flow:...................................................................................................................................................2
.................................................................................................................................................................... 2
Steps to send a simple email:......................................................................................................................2
Create an email process model in <extension>core-items.xml:...................................................................2
Create process xml and associate it with process model:............................................................................3
Register process related beans in <extension>core-spring.xml...................................................................3
Create an event and listener Java classes....................................................................................................4
Create an email context Java class and register in <extension>facades-spring.xml:....................................4
Create an email body and email subject vm files:.......................................................................................5
Create email page and associate it with email body and subject vm files:..................................................5
Steps to sending email in local host:............................................................................................................6
Triggering email through HMC:....................................................................................................................7
Steps to add cc mail:....................................................................................................................................9
Tips to avoid error:......................................................................................................................................9
Introduction:
This document will help you to understand entire email functionality in Hybris. This will cover the
following topics:
Email flow
Steps to send a simple email
Steps to create email page and templates
Steps to sending email in local host
Triggering email through HMC
Steps to add cc mail
Hints to avoid error
Email flow:
For example,
For contact us form submission, we need to send email to helpdesk with customer details and
user given form fields values. Hence we created 2 new models
o 1.CSTicketModel which holds the all the required attributes
o 2.CsTicketProcessModel which holds the CSTicketModel as an attribute
After adding your model in the items.xml, do an ant all and refresh your eclipse project folders.
hsscore_items_xml.txt
contactUsEmailProcess.xml.txt
Make sure these beans present with correct name in your core-spring.xml
hss_core_spring.xml.txt
Create an event and listener Java classes
We can trigger the process by directly or using event driven pattern. Here trigger process by event driven
pattern is explained.
Event class is a DTO which should contain all the attributes which are present in the process model.
Follow below steps to create event and listener class:
In required email triggering place, trigger this event by setting required values which are need to
be set to process model.
In event listener class catch this event and create a process model using the process name which
we have mentioned in the process.xml.
Get all the values from the event and set it to the process model.
Start the process using business service in the listener method.
Make sure this listener is registered in the core-spring.xml
We have to create two vm files for email body and email subject contents. .vm file is kind of .jsp
file where html code design will be there for email contents. Vm file has their own syntax for if,
else, for loops etc. Refer velocity template syntax in online. We will see .vm creation in the later
sections.
For each vm file we need context Java class to pass the Java objects to the .vm files from Java class
so that we can display email contents based on our business logic in the .vm file.
Email context class kind of controller class where you can put your Java object as a key value pair.
Once email process is triggered, process will pass the created process model (which has required
email contents) to the email context class. We can take value from process model and can send
required values as a key value pair from email context java class to vm files.
Association between email context class and corresponding vm file will be mentioned in the email
page template creation steps.
To pass the Java object from email context Java class to .vmfile , use put (hybris OOTB method ) in the
email context Java class as below:
put(keyString, yourJavaObject)
We can also access our Java object using below syntax without using “put” method if we mentioned
getter setter methods for our Java object in the email context Java also.
${ctx.yourJavaObject.requiredAttribute}
Refer attached code to create context class. Make sure register your email context class in the <your-
extension>.facades.xml.
hssfacades-spring.xml.txt ContactUsFormEmailContext.java
email-contactUsFormBody.vm.txt email-contactUsFormSubject.vm.txt
Create email page and associate it with email body and subject vm files:
Creating email page steps are similar to normal cms page creation process. Create body vm file and
subject vm file and put it in the corresponding folder. In the email page template we have to associate
corresponding email-body vm file, email-subject file and their corresponding Java classes. Please refer
the attached email-content.impex file.
For DEV/UAT/PROD we are using Rackspace server or any other server. That should have their
own smtp server itself. Hence no need to mention ip address for it. Just mention as below that
will handle by itself
mail.smtp.server=localhost
mail.smtp.port=25
Then we need to run the email content impex. Before run the email-content.impex, just change
the from email attribute value as your/anyother valid born email id in the below impex as below
INSERT_UPDATE EmailPage;
$contentCV[unique=true];uid[unique=true];name;masterTemplate(uid,
$contentCV);defaultPage;approvalStatus(code)
[default='approved'];fromEmail[lang=en];fromName[lang=en]
o Reason to change the from email value is that we are using BORN smtp server in our
local. Hence we can’t set other domain email id as from email id.
o In DEV/UAT/PROD it should be your client helpdesk id.
Once all the above steps are done. Do ant clean all, start the server and update your system.
Run the email conten.impex with online mode.
Then trigger the mail as below in your required place. Make sure to inject basestoreservice,
basesiteservice, CommonI18NService, eventservice in your Java class.
This might be due to wrong smtp server details and port number in local.properties
Might be firewall issue. SMTP port access might be blocked for your IP address. Please check with
your admin support team.
Once email is triggered successfully, check your spam box and inbox.
Once email is triggered successfully and If you want to change .vm file content, that can be done
through HMC itself
To Change the email body content:
Go to WCMS folder in HMC
Click Page template and change it to email template from dropdown
Search your email page template id
In the result open your email page template online
In that go to email tab, their you can find the email body vm file and subject vm file and you can
edit their content from there.
After changing the content no need to trigger the mail from website again. We can trigger it
from using HMC.
To trigger email process:
Go to System in HMC
Click the Business process
Search your business process which you already triggered using process name as below
HSSSendEmailAction.java
<beanid="sendEmail"class="com.groupfmg.hss.core.actions.HSSSendEmailAction"
parent="abstractAction">
<propertyname="emailService"ref="emailService"/>
<propertyname="baseStoreService"ref="baseStoreService"/>
</bean>
Tips to avoid error:
First define and create your process model and then proceed further steps
Make sure process names are correctly used in the required place
Make sure process beans, email context beans and all related beans are registered in the
corresponding spring xml
Make sure smtp server details are correctly configured
Make sure from email id should be our born domain email id in the email page model if you are
testing email in your local environment.
Thanks…………