標籤:
1.QQ郵箱設定
1.1 進去QQ郵箱-->設定-->帳號-->進行設定如
2.foxmail設定(由於我要利用它收郵件)
2.1 參照官方的設定即可 http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=371
ps:填寫的郵箱密碼是獨立密碼:需要注意的就是SSL連結要勾選;smtp連接埠是465
3.Java中代碼配置
3.1 發送郵件配置代碼
public class MailUtils {
public static void sendMail(String email, String emailMsg) throws AddressException, MessagingException { // 1.建立一個程式與郵件伺服器會話對象 Session
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "SMTP");
props.setProperty("mail.host", "smtp.sohu.com");
props.setProperty("mail.smtp.auth", "true");// 指定驗證為true
// 建立驗證器
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("hoobey", "1234567890");
}
};
Session session = Session.getInstance(props, auth);
// 2.建立一個Message,它相當於是郵件內容
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]")); // 設定寄件者
message.setRecipient(RecipientType.TO, new InternetAddress(email)); // 設定發送方式與接收者
message.setSubject("使用者啟用"); // message.setText("這是一封啟用郵件,請<a href=‘#‘>點擊</a>");
message.setContent(emailMsg, "text/html;charset=utf-8");
// 3.建立 Transport用於將郵件發送
Transport.send(message); } }
java mail使用qq郵箱發郵件的配置方法