I am attempting to program an auto-email feature into a JSP page.
The user logs into to an application where they type information from an image.
When there is a problem with the image they click the "comment" button which takes them to a popup,
where they can comment about the image problems(separate JSP file).
I want to add a feature in the popup that allows them the option to send an e-mail with the comment as the body.
I have seen examples of how to set up an e-mail form but I want the feature to auto send the e-mail and eliminate the human error.
I can look up the username and user address for the FROM: and I can look up the appropriate e-mail for the TO:.
Since I will already have the body of the message in the popup "comment" form I would like to know if it is possible to
program the app to send an e-mail automatically when the comment is submitted.
If, for instance, a check box "send email" is checked, then I would like the application to submit the comment to the db as usual and then send the e-mail before returning to the original application.
I am not looking for specific code just guidelines to help me build this. Any help would be appreciated.
Don't do this in a JSP. Post the form data (comment) to a servlet and handle it there. In the servlet can you initialize the storage of the comment in the database and the sending of the e-mail, in whichever way you like. You can use JavaMail directly or a wrapper like Simple Java Mail to send e-mail from your application.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
//add to the database before displaying...
var comment = form.elements.namedItem("itemComment").value;
if (comment == null || comment == "")
createDojoAlert("Add Comment","<li>Comment required</li>");
var commentType = form.elements.namedItem("commentType").value;
var itemID = "<s:property value="itemID" />";
var itemRowNum = "<s:property value="itemRowNum" />";
/* Do some magic to find the correct row to add this comment */
var tbody = dojo.byId("commentsTbl").tBodies.item(0);
for (var i=0; i<tbody.childNodes.length; i++)
if (tbody.childNodes.item(i).tagName == "TR")
if (trCnt == 2)
I assumed you were using a basic JSP / Servlet approach, but the application seems to be using Struts 2. So instead of a Servlet, some Action class will be handling the form data - in JSON format apperently. Same difference really
Still a server-side component, and like Bear said, that's where you'll need the e-mail sending logic to execute.
Joined: May 14, 2012
Thank you for all your help. I think I can figure out how to move forward from here.