File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Using XML file send to out email  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Using XML file send to out email  " Watch "Using XML file send to out email  " New topic
Author

Using XML file send to out email

Ankittt Shah
Greenhorn

Joined: Aug 19, 2008
Posts: 6
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.
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
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

Joined: Aug 19, 2008
Posts: 6
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

Joined: Nov 07, 2000
Posts: 242
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using XML file send to out email
 
Similar Threads
Beginner Java Question
Help wit h code
Spring MVC : {beanName.property} not working
Creating Custom wsdl definition
Removing multiple if conditions