| Author |
Sending dynamic content by email in jsp
|
hasan khan
Ranch Hand
Joined: Aug 04, 2003
Posts: 222
|
|
Sending dynamic content by email in jsp i have created a form for users to register at my site. when user submits the form i validate the form with my bean and then i add users information in my database. and i display the message that you have been register at my site with user name : xyz and email id : abc@xyz.com. after showing the above message i want to send him/her email that you have been successfully registered at our site with user name : xyz and email .... the message i will be sending by email will be big html content with some dynamic data i.e. his/her all registration information so my question is how do i send dynamic data by email. i am using the following code for sending email import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class SendMail { public static void SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText) throws MessagingException, Exception { boolean debug = false; // change to get more information String msgText2 = "multipart message"; boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue(); // set the host Properties props = new Properties(); props.put("mail.smtp.host", smtphost); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from InternetAddress from = new InternetAddress(emailfrom); msg.setFrom(from); InternetAddress[] address = { new InternetAddress(emailto) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(msgSubject); if(!sendmultipart) { // send a plain text message msg.setContent(msgText, "text/html"); } else { // send a multipart message// create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(msgText, "text/plain"); // create and fill the second message part MimeBodyPart mbp2 = new MimeBodyPart(); mbp2.setContent(msgText2, "text/plain"); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); } Transport.send(msg); } }
|
SCJP, SCWCD
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
hasan, It would be helpful if: 1) You would enclose your code in UBB code tags. That will preserve the formatting of your code. Most people here, myself included, will not read long blocks of unformatted code. 2) State specifically what your problem is. You say what you are trying to do. Then include some code. But nowhere do you state what your issues are. I'm assuming that your issue is how to build up the mail message body from the submitted parameters? If so, remember that the params are available on the request that handles the form submission. You seem to indicate that you want to send the e-mail after you show the 'you have registered page'. Why? The workflow I'd adopt would be: 1) User submits form to a servlet 2) The servlet registers the user in the DB 3) The servlet builds and issues the e-mail using the submission data 4) The servlet forwards to the 'success' JSP 5) The JSP displays the success message bear [ November 04, 2003: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
hasan khan
Ranch Hand
Joined: Aug 04, 2003
Posts: 222
|
|
Yes you got it right i want the following 1) User submits form to a servlet/jsp 2) The servlet/jsp registers the user in the DB 3) The servlet/jsp builds and issues the e-mail using the submission data 4) The servlet/jsp forwards to the 'success' JSP 5) The JSP displays the success message i will prefer to use jsp instead of servlets how to do the above
|
 |
 |
|
|
subject: Sending dynamic content by email in jsp
|
|
|