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");
//建立會話
Session session = Session.getInstance(p);
Message msg = new MimeMessage(session); //建立信息
msg.setFrom(new InternetAddress("skiyra@163.com")); //發件人
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("myb4562@163.com")); //收件人
msg.setSentDate(new Date()); // 發送日期
msg.setSubject("答話稀有"); // 主題
msg.setText("快點下在"); //內容
// 郵件服務器進行驗證
Transport tran = session.getTransport("smtp");
tran.connect("smtp.163.com", "skiyra", "aaaaaaaaaaaa");
// bluebit_cn是用戶名,xiaohao是密碼
tran.sendMessage(msg, msg.getAllRecipients()); // 發送
System.out.println("郵件發送成功");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} //發件人
}
}