Introduction:
Email sending part in atg is achieved by two main component as TemplateEmailSender and TemplateEmailInfoImpl.Below you can find the entire code base.
List of Files:
1.Email.java
2.Email.properties
3.TemplateEmailSender.properties
4.SampleEmailTemplate.properties
5.SMTPEmail.properties
6.sampleMail.jsp
7.handleInvoke.jsp
Brief Explanation with code:
1. Email.java
public class Email extends GenericFormHandler {
TemplateEmailSender templateEmailSenderObject;
TemplateEmailInfoImpl templateEmailInfoImplObject;
public boolean handleSendEmailMethod(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws TemplateEmailException{
Properties pp = System.getProperties();
pp.put("mail.smtp.auth", "true");
pp.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
pp.put("mail.smtp.socketFactory.fallback", "false");
pp.put("mail.smtp.starttls.enable", "true");
pp.put("mail.smtp.ssl.trust", "false");
pp.put("mail.smtp.ssl", "true");
String recipient[]={"kavimani.g@gmail.com"};
Map MapObject=new HashMap();
MapObject.put("mapKey_1", "value are 1 , 2, 3");
MapObject.put("mapKey_2", "values are 4, 5, 6");
templateEmailInfoImplObject.setTemplateParameters(MapObject);
templateEmailInfoImplObject.setMessageSubject("Sample Email");
File[] fileAttachmentObject = new File[1];
fileAttachmentObject[0] = new File("E:\\Email-Attachment.png");
templateEmailInfoImplObject.setMessageAttachments(fileAttachmentObject);
templateEmailSenderObject.sendEmailMessage(templateEmailInfoImplObject, recipient);
return true;
}
}
2.Email.properties
$class=com.ownprogram.Email
templateEmailSenderObject=/atg/userprofiling/email/TemplateEmailSender
templateEmailInfoImplObject=/atg/userprofiling/email/SampleEmailTemplate
3.TemplateEmailSender.properties
contextPathPrefix=/yourcontextpath(in application.xml)
requestSetupServlet=/atg/dynamo/servlet/dafpipeline/DynamoHandler
templateRendererServlet=/atg/dynamo/servlet/dafpipeline/DynamoHandler
applicationPrefix^=/atg/dynamo/Configuration.dynamoEarContextRoot
loggingDebug=true
4.SampleEmailTemplate.properties
$class=atg.userprofiling.email.TemplateEmailInfoImpl
$scope=global
contentProcessor=/atg/userprofiling/email/HtmlContentProcessor
fillFromTemplate=true
messageFrom=kavimani.g@gmail.com
templateURL=/learning/sampleMail.jsp
5.SMTPEmail.properties
emailHandlerHostName=smtp.gmail.com
emailHandlerPort=465
username=kavimani.g@gmail.com
password=#########
loggingDebug=true
6.sampleMail.jsp
<%@taglib prefix="dsp" uri="/dspTaglib"%>
<dsp:page>
<h1> Template URL Page</h1>
1.<dsp:valueof param="mapKey_1"/>
2.<dsp:valueof param="mapKey_2"/>
</dsp:page>
7.handleInvoke.jsp
<%@taglib prefix="dsp" uri="/dspTaglib"%>
<dsp:importbean bean="/own/Email"/>
<dsp:page>
<dsp:form action="handleInvoke.jsp" method="post">
<dsp:input type="submit" bean="Email.sendEmailMethod" value="sub" />
</dsp:form>
</dsp:page>
Email sending part in atg is achieved by two main component as TemplateEmailSender and TemplateEmailInfoImpl.Below you can find the entire code base.
List of Files:
1.Email.java
2.Email.properties
3.TemplateEmailSender.properties
4.SampleEmailTemplate.properties
5.SMTPEmail.properties
6.sampleMail.jsp
7.handleInvoke.jsp
Brief Explanation with code:
1. Email.java
public class Email extends GenericFormHandler {
TemplateEmailSender templateEmailSenderObject;
TemplateEmailInfoImpl templateEmailInfoImplObject;
public boolean handleSendEmailMethod(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws TemplateEmailException{
Properties pp = System.getProperties();
pp.put("mail.smtp.auth", "true");
pp.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
pp.put("mail.smtp.socketFactory.fallback", "false");
pp.put("mail.smtp.starttls.enable", "true");
pp.put("mail.smtp.ssl.trust", "false");
pp.put("mail.smtp.ssl", "true");
String recipient[]={"kavimani.g@gmail.com"};
Map MapObject=new HashMap();
MapObject.put("mapKey_1", "value are 1 , 2, 3");
MapObject.put("mapKey_2", "values are 4, 5, 6");
templateEmailInfoImplObject.setTemplateParameters(MapObject);
templateEmailInfoImplObject.setMessageSubject("Sample Email");
File[] fileAttachmentObject = new File[1];
fileAttachmentObject[0] = new File("E:\\Email-Attachment.png");
templateEmailInfoImplObject.setMessageAttachments(fileAttachmentObject);
templateEmailSenderObject.sendEmailMessage(templateEmailInfoImplObject, recipient);
return true;
}
}
2.Email.properties
$class=com.ownprogram.Email
templateEmailSenderObject=/atg/userprofiling/email/TemplateEmailSender
templateEmailInfoImplObject=/atg/userprofiling/email/SampleEmailTemplate
3.TemplateEmailSender.properties
contextPathPrefix=/yourcontextpath(in application.xml)
requestSetupServlet=/atg/dynamo/servlet/dafpipeline/DynamoHandler
templateRendererServlet=/atg/dynamo/servlet/dafpipeline/DynamoHandler
applicationPrefix^=/atg/dynamo/Configuration.dynamoEarContextRoot
loggingDebug=true
4.SampleEmailTemplate.properties
$class=atg.userprofiling.email.TemplateEmailInfoImpl
$scope=global
contentProcessor=/atg/userprofiling/email/HtmlContentProcessor
fillFromTemplate=true
messageFrom=kavimani.g@gmail.com
templateURL=/learning/sampleMail.jsp
5.SMTPEmail.properties
emailHandlerHostName=smtp.gmail.com
emailHandlerPort=465
username=kavimani.g@gmail.com
password=#########
loggingDebug=true
6.sampleMail.jsp
<%@taglib prefix="dsp" uri="/dspTaglib"%>
<dsp:page>
<h1> Template URL Page</h1>
1.<dsp:valueof param="mapKey_1"/>
2.<dsp:valueof param="mapKey_2"/>
</dsp:page>
7.handleInvoke.jsp
<%@taglib prefix="dsp" uri="/dspTaglib"%>
<dsp:importbean bean="/own/Email"/>
<dsp:page>
<dsp:form action="handleInvoke.jsp" method="post">
<dsp:input type="submit" bean="Email.sendEmailMethod" value="sub" />
</dsp:form>
</dsp:page>
Hey Kavi, thanks for the post! That is actually the same way I went about doing it too.
ReplyDeleteHey Kavi, thanks for the post.
ReplyDeleteThis is working but parameters values comes empty.
Do you have any reasons of trhat ?
Hi, Paste your code snipt let me check
Deleteam getting null pointer exception in this line
ReplyDeletetemplateEmailInfoImplObject.setTemplateParameters(MapObject);
Hi, Paste your code snipt let me check
DeleteI am getting the following error, Can you help?
ReplyDeleteatg.userprofiling.email.TemplateEmailException: Request for URL http://:7001/dyn/init-session?ignoreMetric=true did not return a valid session. Please check your settings for siteHttpServerName, siteHttpServerPort, applicationPrefix and initSessionURL for component /
at atg.userprofiling.email.TemplateInvoker.createTemplateEmailSession(TemplateInvoker.java:625)
at atg.userprofiling.email.TemplateInvoker$TemplateSession.(TemplateInvoker.java:865)
at atg.userprofiling.email.TemplateInvoker.createSession(TemplateInvoker.java:755)
at atg.userprofiling.email.TemplateEmailSender.doSendEmailMessage(TemplateEmailSender.java:1899)
at atg.userprofiling.email.TemplateEmailSender.sendEmailMessage(TemplateEmailSender.java:1763)
at atg.userprofiling.email.TemplateEmailSender.sendEmailMessage(TemplateEmailSender.java:1812)
at atg.userprofiling.email.TemplateEmailSender.sendEmailMessage(TemplateEmailSender.java:1781)
The dynSessionId is not getting set because of which it is failling.
Hi, add addition properties to your /atg/userprofiling/email/TemplateEmailSender.properties
ReplyDeletecontentProcessor=/atg/userprofiling/email/HtmlContentProcessor
bypassRecipientVerification=true
siteHttpServerName^=/atg/dynamo/Configuration.siteHttpServerName
siteHttpServerPort^=/atg/dynamo/Configuration.siteHttpServerPort
contextPathPrefix^=/com/liverpool/dynamo/LiverpoolConfiguration.siteUrl
loggingDebug=true
AND YOUR /atg/dynamo/Configuration.properties
ReplyDeletehttpsPort=XXXX
siteHttpServerPort=XXXX
rmiPort=XXXX
adminPort^=/atg/dynamo/Configuration.siteHttpServerPort
httpPort^=/atg/dynamo/Configuration.siteHttpServerPort
siteHttpServerName=localhost
how this flow is working
ReplyDeleteHow can I set the properties is my server isn´t using SSL?
ReplyDeleteHi Kavi,
ReplyDeletewhere to set SMTPEmail.properties ? in which properties file we have to include SMTPEmail.properties ?
OOTB Path name is atg/dynamo/service/SMTPEmail.properties
ReplyDeleteHi Kavi,
ReplyDeleteIam facing an issue with TemplateEmailSender.sendEmailMessage(TemplateEmailInfo pEmailInfo, Collection pRecipients, boolean pRunInSeparateThread, boolean pPersist) method . Sometimes it send mail only in the third attempt . Eg : i tried to send a mail from CSC server , on first attempt it waits for 5 mins and throws 504 error , second attempt also gives same error . But from third attempt im able to receive mails .What could be the reason .
Thanks in advance