package lianxi;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendMail {
public static void main(String[] args) throws AddressException, MessagingException {
// TODO Auto-generated method stub
String to = "abcd@gmail.com";
String from = "web@gmail.com";
String host = "localhost";//发送邮件的主机
//获取系统属性
Properties properties = System.getProperties();
//设置邮件服务器
properties.setProperty("mail.smtp.host", host);
//获取默认session对象
Session session = Session.getDefaultInstance(properties);
//创建默认的MimeMessage对象
MimeMessage message = new MimeMessage(session);
//set From: 头部头字段
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the Subject Line!");
//设置消息体
message.setText("This is actual message");
Transport.send(message);
Transport.send(message);
System.out.println("sent message successfully....");
}
}
09-21