Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i get proper emaiTemplate format

Posted on 2014-04-03
5
Medium Priority
?
268 Views
Last Modified: 2014-04-04
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***

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();
				}
			}
		};

Open in new window

0
Comment
Question by:srikotesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 39977062
I can't help with the java part, but the problem you have is the html tags have white space.

Where you have "< br >"  That should be "<br>"

The corrected code is below.  If you can figure out how to get rid of all white space, you will be good.  I would even get rid of the white space between tags.

Convert this, "To: some_name@gmail.com <br> From: noreply@gmail.com <br> "

To this, To: some_name@gmail.com<br>From: noreply@gmail.com<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

Open in new window

0
 
LVL 2

Author Comment

by:srikotesh
ID: 39977541
k,this template format we inserted in db there i observed between the tags some spaces are there,k i vl remove the whitespaces and try,
****Thanks******
0
 
LVL 2

Author Closing Comment

by:srikotesh
ID: 39977852
Thanks for ur valuable suggestion
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question