You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Bathje <mp...@ntsource.com> on 2004/02/11 17:02:42 UTC

[OT] Sending email from struts

Hi all.

This is kind of off topic as it is not really struts related, but somebody
here would probably have the answer.

We have our application sending emails to users at some points and it is
working fine. The problem is that we have the email message hardcoded into
the Java, which we would like to avoid either by storing the message in
application.properties or our database. This would be easy, except all of
the messages contain user-specific information like their name or phone
number or order id or something like that.

Anybody have any ideas (or links to programs!) that can read in an email,
replace the information it needs to from the db, and send that to the user.

I could obviously write something myself to do it, but wouldn't want to
reinvent the wheel.

Turns out this is hard to search for too - email is not a search term that
makes things easy.

Thanks,
Matt Bathje


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Sending email from struts

Posted by Sachin Pandey <sa...@bigpond.com>.
Hi,

     Have a look at Velocity (Jakarta), templating engine. You can use that
to substitute the user details and form the mail message. The template could
just be a resourse file with velocity tags.

Cheers
Sachin



----- Original Message ----- 
From: "Matt Bathje" <mp...@ntsource.com>
To: "strutslist" <st...@jakarta.apache.org>
Sent: Thursday, February 12, 2004 3:02 AM
Subject: [OT] Sending email from struts


> Hi all.
>
> This is kind of off topic as it is not really struts related, but somebody
> here would probably have the answer.
>
> We have our application sending emails to users at some points and it is
> working fine. The problem is that we have the email message hardcoded into
> the Java, which we would like to avoid either by storing the message in
> application.properties or our database. This would be easy, except all of
> the messages contain user-specific information like their name or phone
> number or order id or something like that.
>
> Anybody have any ideas (or links to programs!) that can read in an email,
> replace the information it needs to from the db, and send that to the
user.
>
> I could obviously write something myself to do it, but wouldn't want to
> reinvent the wheel.
>
> Turns out this is hard to search for too - email is not a search term that
> makes things easy.
>
> Thanks,
> Matt Bathje
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Sending email from struts

Posted by Robert Nocera <rn...@neosllc.com>.
You might want to try something like velocity so you can store the text of
the e-mail as a template and use velocity to insert the dynamic content.

If there are really only a few simple fields, I would store the text in the
database or an xml file and then use a simple string replace routine to
replace tags like {ORDER_ID} and {USER_NAME} with the order id and user name
before passing that message to the mailer.

-Rob


-----Original Message-----
From: Matt Bathje [mailto:mpb@ntsource.com] 
Sent: Wednesday, February 11, 2004 11:03 AM
To: strutslist
Subject: [OT] Sending email from struts

Hi all.

This is kind of off topic as it is not really struts related, but somebody
here would probably have the answer.

We have our application sending emails to users at some points and it is
working fine. The problem is that we have the email message hardcoded into
the Java, which we would like to avoid either by storing the message in
application.properties or our database. This would be easy, except all of
the messages contain user-specific information like their name or phone
number or order id or something like that.

Anybody have any ideas (or links to programs!) that can read in an email,
replace the information it needs to from the db, and send that to the user.

I could obviously write something myself to do it, but wouldn't want to
reinvent the wheel.

Turns out this is hard to search for too - email is not a search term that
makes things easy.

Thanks,
Matt Bathje


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Sending email from struts

Posted by Navjot Singh <na...@net4india.net>.
Hi Matt,

Shouldn't be a difficult job to do. I have implemented this in two different
ways

1. Using velocity - guess that's the way most people do now a days.
2. Using my own Email Template System
   I keep the text or html in some files. Right now, paths for those
   files are being picked from constants. (picked relative to the
   context_root). Once the request comes thru *TemplateFacade* to load
   a particular template, it is loaded and *cached*. Map can be passed
   to replace the placeholders in template. *TemplateRunner* runs the
   transformation on underlying template. Then it's on to java mail
   api.

   Instead of saving the template paths in constants file, you could
   save them in some text file (.properties / .xml) but that seems
   overhead to me as this is one time job and doesn't change at all
   once fixed.

HTH
Navjot Singh

>-----Original Message-----
>From: Matt Bathje [mailto:mpb@ntsource.com]
>Sent: Wednesday, February 11, 2004 9:33 PM
>To: strutslist
>Subject: [OT] Sending email from struts
>
>
>Hi all.
>
>This is kind of off topic as it is not really struts related, but somebody
>here would probably have the answer.
>
>We have our application sending emails to users at some points and it is
>working fine. The problem is that we have the email message hardcoded into
>the Java, which we would like to avoid either by storing the message in
>application.properties or our database. This would be easy, except all of
>the messages contain user-specific information like their name or phone
>number or order id or something like that.
>
>Anybody have any ideas (or links to programs!) that can read in an email,
>replace the information it needs to from the db, and send that to the user.
>
>I could obviously write something myself to do it, but wouldn't want to
>reinvent the wheel.
>
>Turns out this is hard to search for too - email is not a search term that
>makes things easy.
>
>Thanks,
>Matt Bathje
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] Sending email from struts

Posted by Robert Taylor <rt...@mulework.com>.
Matt, we ended up storing our email templates in a configuration file and
loading them into
memory (using Digester) at application run time. The configuration templates
can contain
both plain text and HTML message versions. We leverage the
java.text.MessageFormat
API to replace place holders in the templates with actual data.

In the application, we use a design pattern called EmailHelper. EmailHelper
provides a business
API to which the application passes information. For example, after a
customer downloads a product,
the application might do something like:

EmailHelper.getInstance().sendThankYouMessage(user, product);

where user and product are application data structures respectively
representing the current user
and the product which was just downloaded.

Subsequently, EmailHelper mines the necessary data from the arguments and
then performs
lower level operations such as retrieving the appropriate email template
from the
in memory configurations, populating the template and then persisting the
email to the
appropriate queue where it will be delivered later.

A different application (daemon) periodically retrieves unsent email from
the queue and
sends them using the JavaMail API.


It has worked quite well so far. If we need to tweak the templates, we can
do so and reload
the configurations. You could take this idea a step further and store the
templates in the database.

This does seem like a common task in applications and it would be nice if
there were some standard
framework to use, but I don't know of any in development currently.


robert

> -----Original Message-----
> From: Matt Bathje [mailto:mpb@ntsource.com]
> Sent: Wednesday, February 11, 2004 11:03 AM
> To: strutslist
> Subject: [OT] Sending email from struts
>
>
> Hi all.
>
> This is kind of off topic as it is not really struts related, but somebody
> here would probably have the answer.
>
> We have our application sending emails to users at some points and it is
> working fine. The problem is that we have the email message hardcoded into
> the Java, which we would like to avoid either by storing the message in
> application.properties or our database. This would be easy, except all of
> the messages contain user-specific information like their name or phone
> number or order id or something like that.
>
> Anybody have any ideas (or links to programs!) that can read in an email,
> replace the information it needs to from the db, and send that to
> the user.
>
> I could obviously write something myself to do it, but wouldn't want to
> reinvent the wheel.
>
> Turns out this is hard to search for too - email is not a search term that
> makes things easy.
>
> Thanks,
> Matt Bathje
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org