public class SendMail {
public static void main(String[] args) {
try {
Properties p = new Properties(); //Properties p = System.getProperties();
p.put("mail.smtp.auth", "true");
p.put("mail.transport.protocol", "smtp");
p.put("mail.smtp.host", "smtp.163.com");
p.put("mail.smtp.port", "25");
//建立會(huì)話
Session session = Session.getInstance(p);
Message msg = new MimeMessage(session); //建立信息
msg.setFrom(new InternetAddress("skiyra@163.com")); //發(fā)件人
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("myb4562@163.com")); //收件人
msg.setSentDate(new Date()); // 發(fā)送日期
msg.setSubject("答話稀有"); // 主題
msg.setText("快點(diǎn)下在"); //內(nèi)容
// 郵件服務(wù)器進(jìn)行驗(yàn)證
Transport tran = session.getTransport("smtp");
tran.connect("smtp.163.com", "skiyra", "aaaaaaaaaaaa");
// bluebit_cn是用戶名,xiaohao是密碼
tran.sendMessage(msg, msg.getAllRecipients()); // 發(fā)送
System.out.println("郵件發(fā)送成功");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} //發(fā)件人
}
}