用的是163郵箱,授權(quán)已開,在使用JavaMail發(fā)郵件,每天開始的幾封能正常發(fā)送出去,后面會(huì)出現(xiàn)以下異常:源碼是: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("用戶名", "授權(quán)碼");
}
};
Session session = Session.getInstance(pro, auth);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("我的郵箱"));
msg.setRecipients(RecipientType.TO, "發(fā)送給的郵箱");
msg.setSubject("我自己的郵件");
msg.setContent("我的郵件正文", "text/html;charset=utf-8");
Transport.send(msg);
}
}上網(wǎng)查了方法把上述注釋打開則會(huì)出現(xiàn)以下異常:各種方法都試過了還是解決不了,求大神解答,謝謝!
3 回答

楊__羊羊
TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
看完log,顯示是Caused by: Connection closed by remote host
就是說是連接被遠(yuǎn)程host關(guān)閉了,所以就發(fā)送失敗了,至于關(guān)閉的原因就需要你去排查了。
添加回答
舉報(bào)
0/150
提交
取消