導入mail.jarhtml
1.utils:session
public class utils {
public static void sendMail(String email, String emailMsg) throws MessagingException {
Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "SMTP");
properties.setProperty("mail.smtp.host", "smtp.qq.com");
properties.setProperty("mail.smtp.auth", "true");
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("", "");
}
};
Session session = Session.getInstance(properties, authenticator);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(""));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
message.setSubject("用戶激活");
message.setContent(emailMsg, "text/html;charset=utf-8");
Transport.send(message);
}
}
2.問題:ide
有時候會被視爲垃圾郵件,收進垃圾箱htm