当前位置:   article > 正文

解决阿里云服务器无法使用STMP服务器25端口_smtp服务【服务地址: smtp.spiderman.cfd 、端口: 25 】

smtp服务【服务地址: smtp.spiderman.cfd 、端口: 25 】

之前在本地windows上用javax-mail写发送邮件时运行的好好的,
但是程序部署到Linux服务器上后发送邮件就会报如下错误:

Could not connect to SMTP host: smtp.qq.com, port: 25

我还以为是防火墙的问题,折腾了半天,把防火墙关了也没弄好。

之后看了别人的文章才知道阿里禁用了服务器的25端口:用户对阿里的投诉,以及阿里的回复

那么问题来了SMTP协议的端口就是25,那该怎么办呢?

阿里的回复中给出了两种解决办法:
1、使用加密465端口

2、使用阿里的邮箱

 

我这里是用的465端口:

  1. Properties properties = System.getProperties();
  2. //使用465端口和25端口就只有配置文件不一样
  3. properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  4. properties.put("mail.smtp.port", "465");
  5. properties.put("mail.smtp.socketFactory.port", "465");
  6. properties.put("mail.smtp.host", "smtp.qq.com");
  7. properties.put("mail.smtp.auth", "true");
  8. properties.put("mail.user", "1223814404@qq.com");
  9. properties.put("mail.password", "填你邮箱的密钥");
  10. //smtp邮箱需要验证
  11. Authenticator authenticator = new Authenticator() {
  12. @Override
  13. protected PasswordAuthentication getPasswordAuthentication() {
  14. String userName = properties.getProperty("mail.user");
  15. String password = properties.getProperty("mail.password");
  16. return new PasswordAuthentication(userName, password);
  17. }
  18. };
  19. Session session = Session.getDefaultInstance(properties, authenticator);
  20. MimeMessage mimeMessage = new MimeMessage(session);
  21. try {
  22. mimeMessage.setFrom(new InternetAddress(emailConfig.user));
  23. mimeMessage.setRecipients(MimeMessage.RecipientType.TO, new Address[]{new InternetAddress(email)});
  24. mimeMessage.setSubject(emailConfig.subject);
  25. mimeMessage.setText(String.format("验证码:%s", code), "utf-8");
  26. Transport.send(mimeMessage);
  27. return ResultVoUtil.success();
  28. } catch (MessagingException e) {
  29. e.printStackTrace();
  30. }



 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/776896
推荐阅读
相关标签
  

闽ICP备14008679号