用的是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
提交
取消