• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using XML file send to out email

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following requirement to send out email notification to customers.

XML email template is like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE message SYSTEM "message.dtd">
<message format="html">
<from>noreply@abc.com</from>
<to>noreply@abc.com</to>
<subject>Email Notification</subject>
<content>
<salutation>Dear Customer,</salutation>
<body_text1>Account Username</body_text1>
<username>__</username>
<body_text2>Following products are expiring</product1>
<product1>product 1.</product1>
<product1value>__</product1value>
<product2>product 2</product2>
<product2value>__</product2value>
<product3>product 3</product3>
<product3value>__</product3value>
<thankyou>Thank you</thankyou>
</content>
</message>

The java code will target more than one user at a time, i.e will be sending out more than one emails at a time [batch job]
for a username there are possible 3 products which are expiring, he / she might have two products. so for that username the value should be populated thru a java program [i have the value].

What technology do i have to use to send this email. [I could use JavaMail]
but i am not sure what technologies to use for populating the data, will XmlBeans help ??

Thanks
Ankit.
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make it simple and working type, you can use String.replace or StringUtils.replace methods to replace the keywords with runtime values.

As you say, it is not necessarily a user has all three products and in that case you want to include just the number of products user is concerned with.

To solve that, either you can have different template for different number of products or replace the complete products lines with a keyword and replace it at runtime including the tag. For ex.,



In this case, replace the ${username} with actual user name and ${products} with product fields.
 
Ankittt Shah
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Santosh,

Thank you so much for your reply,

So i just load the xml document into memory and then use the string.replace or stringUtil.replace ?

do you have a sample code to read this xml document using any api which takes this $ parameters, is this part of xml beans ?

Thanks in advance
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XmlBeans is used to convert the xml to java objects and versa so that is not what you looking for here.

Just use FileInputStream to read the xml into a String object and replace the keywords using String.replace function.
reply
    Bookmark Topic Watch Topic
  • New Topic