11 Ağustos 2007 Cumartesi

Sending Mail

/*
This code requires JavaMail. Specifically it requires mailapi.jar
and smtp.jar from the JavaMail distribution (available
at http://java.sun.com/) as well as activation.jar from the
JavaBeans Activation Framework (available
at http://java.sun.com/beans/glasgow/jaf.html).
*/

Properties props = new Properties();
props.put("mail.smtp.host", "your-smtp-host.com");
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(message, "text/plain");
Transport.send(msg);


0 Comments: