Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to send mail when submiting form

 
Arun Vethadas .T
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai
in my jsp file i want to send mail using
outlook(MSExchange Server) mailid while submiting the page or form. Automatic email send to the particular person. And i want to send a alert mail when person final date of the project.the date is in the database while submiting the form we send the date also. Pls Help me urgent.sample code ps.
Thanks,
Arun.
 
Tejeshwara Murthy K.G
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
U can use JavaMail to send an automatic mail. By getting the form Details and the required date u can call a component method which takes the i/p parameter as EmailProfile. The EmailProfile class contains of Server IP Address(Host),To Address,From Address,Subject,Message Body(u can specify cc & Bcc also).U set all thes EmailProfile details and call the SendMailRef method which is show below.That will automatically sends a mail.
To use Javamail u have to download and use three jars, namingly
1.activation.jar
2.pop3.jar
3.mail.jar
Then u have to set this classpath in the WebServer.
The sendMailRef method is as follows

public int sendMailRef(EmailProfile emprof)
{
int ret=0;
try
{
String host=emprof.host;
// System.out.println("host "+host);
String to =emprof.to ;
// System.out.println("to "+to);
String from=emprof.from;
String cc=null;
String bcc=null;
String subject=emprof.subject;
//System.out.println("subject "+subject);
String msgText=emprof.message;
// System.out.println("message "+msgText);
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session sendsession = Session.getInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(sendsession);
if (from != null)
message.setFrom(new InternetAddress(from));
else
message.setFrom();
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
if (cc != null)
message.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
if (bcc != null)
message.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false));
message.setSubject(subject);
//Add the message body to
message.setContent(msgText,"text/html");
//Date d = new Date();
// message.setSentDate(d);
Transport.send(message);
ret=1;
return ret;
}
catch(Exception e)
{
System.out.println(e);
}

return ret;



}

Regds
Tejesh
 
Arun Vethadas .T
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank u very much.
Thanks,
Arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic