java使用网易云邮箱服务器发送邮件,本地环境可以。上到正式阿里云服务器发送邮件显示超时。
port端口25走非加密,465是使用加密方式。
发送超时,可以试试在参数设置里面加上以下配置试试。
prop.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.put("mail.smtp.ssl.protocols", "TLSv1.2");
prop.put("mail.smtp.ssl.enable", true);
发送邮件时指定使用 465 端口:
// 1、创建session
Session session = openSession();
// 开启Session的debug模式查看到程序发送Email的运行状态
session.setDebug(true);
// 2、通过session得到transport对象
Transport ts = null;
try {
ts = session.getTransport();
// 3、使用邮箱的用户名和密码连上邮件服务器,发送邮件时,发件人需要提交邮箱的用户名和密码给smtp服务器,用户名和密码都通过验证之后才能够正常发送邮件给收件人。
ts.connect(host,port, user, password);
// 4、发送邮件
ts.sendMessage(message, message.getAllRecipients());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error(e.getMessage());
} finally {
closeTransport(ts);
}
2万+

被折叠的 条评论
为什么被折叠?



