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

How to send mail when submiting form

Arun Vethadas .T
Ranch Hand

Joined: Dec 13, 2001
Posts: 36
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

Joined: Apr 08, 2002
Posts: 4
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

Joined: Dec 13, 2001
Posts: 36
Hi
Thank u very much.
Thanks,
Arun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send mail when submiting form