先附上代码
public class JavaMail {
@Test
public void func() throws MessagingException {
Properties prop = new Properties();
prop.setProperty("mail.host","smtp.163.com");
prop.setProperty("mail.smtp.auth","true");
Authenticator aut = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("yonghuming","mima");//由于涉及隐私就用拼音代替了
}
};
Session session = Session.getInstance(prop,aut);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));//sender
msg.setRecipients(Message.RecipientType.TO,"[email protected]");//recipients
msg.setSubject("这是一封测试邮件");
msg.setContent("你猜猜看是啥","text/html;charset=utf-8");
Transport.send(msg);
}
public class JavaMail {
@Test