关于阿里云服务器上使用javamail失败的解决方案
2017-06-09 10:33
453 查看
今天出现一个奇怪的问题, 本地的邮件能正常发送. 代码上传到阿里云服务器上就是不能成功.
在阿里云社区上看到这么一篇帖子, https://yq.aliyun.com/ask/47591
后台发现写的代码没有使用ssl的连接方式.
Properties props = new Properties();
// 开启debug调试
// props.setProperty("mail.debug", "true");
// 发送服务器需要身份验证
props.setProperty("mail.smtp.auth", "true");
// 设置邮件服务器主机名
props.setProperty("mail.host", "smtp.9meth.com");
// 发送邮件协议名称
//props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
// 设置环境信息
// Session session = Session.getInstance(props);
Session session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("mail", "password");
}
});
// 创建邮件对象
Message msg = new MimeMessage(session);
try {
msg.setSubject(title);
// 设置邮件内容
msg.setText(content);
// 设置发件人
msg.setFrom(new InternetAddress("发的邮件"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(收的邮件, false));
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
在阿里云社区上看到这么一篇帖子, https://yq.aliyun.com/ask/47591
后台发现写的代码没有使用ssl的连接方式.
Properties props = new Properties();
// 开启debug调试
// props.setProperty("mail.debug", "true");
// 发送服务器需要身份验证
props.setProperty("mail.smtp.auth", "true");
// 设置邮件服务器主机名
props.setProperty("mail.host", "smtp.9meth.com");
// 发送邮件协议名称
//props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
// 设置环境信息
// Session session = Session.getInstance(props);
Session session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("mail", "password");
}
});
// 创建邮件对象
Message msg = new MimeMessage(session);
try {
msg.setSubject(title);
// 设置邮件内容
msg.setText(content);
// 设置发件人
msg.setFrom(new InternetAddress("发的邮件"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(收的邮件, false));
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
相关文章推荐
- 刚买的阿里云服务器,使用ftp连接失败?解决方案
- 关于阿里云服务器中使用Docker启动Tomcat过程很慢的解决方案
- 在红帽子下配置javamail服务器,使用外面的邮箱地址发送邮件失败
- 结合阿里云服务器,使用FTP上传和下载文件,出现的问题和解决方案
- 关于centos 7 中service iptables save 指令使用失败的解决方案
- tp3.2使用phpmailer发送邮件线下测试ok,上传阿里云服务器发送邮件失败
- 关于阿里云服务器Linux安装Tomcat后,外网不能访问解决方案
- 关于远程桌面连接阿里云服务器ECS出现的卡顿、自动退出问题的解决方案
- 关于winserver2008和winserver2012 64位服务器使用cvs版本控制的解决方案
- 关于SecureCRT连接阿里云服务器提示需要public key的解决方案
- 阿里云服务器 25端口无法使用解决方案
- 关于使用genymotion"创建 VirtualBoxClient COM 对象失败. 应用程序将被中断“的解决方案
- 关于npm和yarn安装node-sass失败并且依旧想使用NPM或者yarn的完美解决方案
- 关于ThinkPHP框架开发微信公众号在微信后台配置服务器URL提示Token验证失败的解决方案
- 关于微信服务器ngrok 配置失败解决方案
- 关于服务器上发送邮件程序发送失败的解决方案
- 关于Oracle安装完毕使用自带图形化界面打开失败的问题 --->解决方案
- iOS开发中 关于阿里云服务器的使用与安全策略 韩俊强的博客
- 阿里云服务器 通过JavaMail发送邮箱STMP问题 25端口被禁用 使用SSL协议465端口
- 关于阿里云服务器Linux安装Tomcat后,外网不能访问解决方案