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();
} //发件人
}
}