dcsimg
how to send a javamail message to an email id like abc.yahoo.com
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mangesh_Kulkarni
Posted On:   Thursday, April 27, 2006 10:20 AM

hi all,

i m naive to javamail.

REQUIREMENT :

i wanna get some informatio from a html form and build a mail first. later i wanna send it on an email id
it may pop acc or may genral email id

can i send a javamail message directly to a email id

how i can do so?

Re: how to send a javamail message to an email id like abc.yahoo.com

Posted By:   Rad_Sat  
Posted On:   Thursday, April 27, 2006 11:26 AM

Yes you can, you first need activation.jar and mail.jar set in your classpath.

Then your class should have something like,

smtpHost = configData.getEmailSmtpHost();
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.size()];
for (int i = 0; i < recipients.size(); i++)
{
addressTo[i] = new InternetAddress((String)recipients.get(i));
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
About | Sitemap | Contact