package cn.com.cloud.utils;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* 邮件
* @author 李海云
* @date 2012-02-23
* @email CloudComputing.cc@gmail.com
*/
public class TestMail {
public static void main(String[] args) throws MessagingException {
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setSubject("你好subject");
msg.setText("天气晴朗text");
msg.setFrom(new InternetAddress("your username@qq.com"));//发件人address
Transport transport = session.getTransport();
//发送者 1连接服务器 2端口号 3用户名 4密码
transport.connect("smtp.qq.com", 25, "your username", "your password");
//发送目标
transport.sendMessage(msg,
new Address[]{new InternetAddress("target username@qq.com")});
transport.close();
}
}