Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to write a code for sending automail through JSP application

  Asked By: Kelley    Date: Aug 28    Category: Java    Views: 1742
  

How to write a code for sending automail through JSP application.
selecting the mailaddreses and salutions etc from databases.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Woodrow Jones     Answered On: Aug 28

use java Mail for Sending Mail.
use Following Packages,
javax.mail,javax.mail.internet,
java.net.InetAddress
use mail.jar, activation.jar in classpath...

Create Properties like

properties.put("mail.smtp.host", strHostName);
properties.put("mail.debug", "false");

then get Session

session = Session.getDefaultInstance(properties, null);

Create Message

Message msgBody = new MimeMessage(session);

set the From Address to Message
msgBody.setFrom(new InternetAddress(strFrom));

set to Address

InternetAddress[] address = (new
InternetAddress()).parse(strToAddr);
msgBody.setRecipients(Message.RecipientType.TO, address);

set the Subject...

msgBody.setSubject("Hi How r u ");

Send the Message

Transport.send(msgBody);

 




Tagged: