用的是163郵箱,授權已開,在使用JavaMail發郵件,每天開始的幾封能正常發送出去,后面會出現以下異常:源碼是:package test.ceshi;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class MailTest {
public static void main(String[] args) throws AddressException, MessagingException, IOException {
Properties pro = new Properties();
pro.put("mail.smtp.host", "smtp.163.com");
pro.put("mail.smtp.auth", "true");
//pro.setProperty("mail.smtp.starttls.enable", "true");
Authenticator auth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("用戶名", "授權碼");
}
};
Session session = Session.getInstance(pro, auth);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("我的郵箱"));
msg.setRecipients(RecipientType.TO, "發送給的郵箱");
msg.setSubject("我自己的郵件");
msg.setContent("我的郵件正文", "text/html;charset=utf-8");
Transport.send(msg);
}
}上網查了方法把上述注釋打開則會出現以下異常:各種方法都試過了還是解決不了,求大神解答,謝謝!
3 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
看完log,顯示是Caused by: Connection closed by remote host
就是說是連接被遠程host關閉了,所以就發送失敗了,至于關閉的原因就需要你去排查了。
添加回答
舉報
0/150
提交
取消