srikotesh
asked on
how do i get proper emaiTemplate format
hi i am sending one email notification while sending mail i am not getting proper format
< html > < body > < br > To: some_name@gmail.com < br > From: noreply@gmail.com < br > Subject:Batchfile not Sent < br > Dear Sir/Madam, < br > No Records are sent to Email welcome letter via silver pop < br > < p > Sincerely, < br > Underwriting and Individual Enrollment < /p > < br > CODE_02 < /body > < /html >
but actual format is:
To: some_name@gmail.com
From: noreply@gmail.com
Subject:User Defined
Dear Sir/Madam,
Threshhold amount is: 5
Sincerely,
Underwriting and Individual Enrollment
CODE_01
see the below code suggest how to resolve this**Thanks in advance***
< html > < body > < br > To: some_name@gmail.com < br > From: noreply@gmail.com < br > Subject:Batchfile not Sent < br > Dear Sir/Madam, < br > No Records are sent to Email welcome letter via silver pop < br > < p > Sincerely, < br > Underwriting and Individual Enrollment < /p > < br > CODE_02 < /body > < /html >
but actual format is:
To: some_name@gmail.com
From: noreply@gmail.com
Subject:User Defined
Dear Sir/Madam,
Threshhold amount is: 5
Sincerely,
Underwriting and Individual Enrollment
CODE_01
see the below code suggest how to resolve this**Thanks in advance***
public void sendEmail(final EmailDetail email) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setFrom(email.getSenderEmailAddress());
message.setSubject(email.getSubjectLine());
message.setContent(message, "text/html");
Map<String, Object> model = new HashMap<String, Object>();
model.put("email", email);
String text = null;
if(email.getReciepientEmailAddress().contains(","))
{
email.getReciepientEmailAddress().replaceAll("\\s","");
String[] emailAddreses = email.getReciepientEmailAddress().split(",");
message.setTo(emailAddreses);
}
else
message.setTo(email.getReciepientEmailAddress());
// if (logger.isDebugEnabled()) {
logger.debug("<<<temp email template file location>>");
// }
List<MessageTemplate> messageTemplate = messageTemplateDao
.findByProperty("code", email.getTemplateCode());
// if (logger.isDebugEnabled()) {
logger.debug("<<<temp email template file location>>"
+ tempTemplateFileLocation);
// }
File tempDir = new File(tempTemplateFileLocation);
if (!tempDir.exists()) {
// if (logger.isDebugEnabled()) {
logger.debug("Temp email template location dosen't exist!");
// }
tempDir.mkdir();
}
File file = new File(tempTemplateFileLocation + "/template.vm");
if (file.exists()) {
file.delete();
}
FileWriter fileWriter = new FileWriter(tempTemplateFileLocation
+ "template.vm");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(messageTemplate.get(0).getTemplate());
if (bufferedWriter != null) {
bufferedWriter.flush();
bufferedWriter.close();
}
try {
text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "/template.vm", model);
message.setText(text, true);
} catch (MailPreparationException e) {
logger.error("Resource not Found",e);
} finally {
File file2 = new File(tempTemplateFileLocation
+ "/template.vm");
// file2.delete();
}
}
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for ur valuable suggestion
ASKER
****Thanks******