???????????????jar????mail-1.4.2.jar????????????java mail????????????SimpleSendMailDemo.java
????SimpleSendMailDemo.java

 

package com.steven.mail;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* ????????????????
*
* @author Steven
*
*/
public class SimpleSendMailDemo {
public static void main(String[] args) throws Exception {
// ???????????????????????????????????????
Properties pro = new Properties();
// ??????????????????????????163???????smtp.163.com
// ?????????????????????http://wenku.baidu.com/link?url=Cf-1ggeW3e7Rm9KWfz47UL7vvkRpPxAKBlYoTSGpnK4hxpJDiQ0A4lRoPDncMlcMIvUpEn6PD0aObgm5zJaM7AOGkRdccSx6HDH2fSWkxIq??????
pro.put("mail.smtp.host"?? "smtp.qq.com");
// ???÷??????????
pro.put("mail.smtp.port"?? "25");
// ?????????????????
pro.put("mail.smtp.auth"?? "true");
// ?????????????????????????????????????
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
// ??д???????????д???????????
return new PasswordAuthentication("songdeitao@qq.com"?? "123");
}
};
// ????????? ????????????session
Session sendMailSession = Session
.getDefaultInstance(pro?? authenticator);
// ?????????????
Message message = new MimeMessage(sendMailSession);
// ???????????????
Address sourceAddress = new InternetAddress("songdeitao@qq.com");
// ?????????????????????
message.setFrom(sourceAddress);
// ????????????????
Address destAddress = new InternetAddress("songdeitao@163.com");
// ??????????????????????????
message.setRecipient(Message.RecipientType.TO?? destAddress);
// ?????????????
message.setSubject("Merry Christmas!");
// ????????????????
message.setText("?????????????");
// ???????????????????(?????????????????)
// String sendDate = "2013-12-23 17:55:00";
// Date date = new
// SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(sendDate);
// message.setSentDate(date);
// ???????
Transport.send(message);
}
}