【问题标题】:Spring boot application return me : 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)Spring Boot 应用程序返回我:550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)
【发布时间】:2020-09-07 21:41:47
【问题描述】:

尝试通过我的 Spring Boot 应用程序发送电子邮件时出现此错误:

failures; nested exception is javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Software caused connection abort: socket write error. Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1);
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

我的 Spring boot 应用程序是使用 jhipster 生成的,这是我的邮件配置的 application-dev.yml 配置:

mail:   
  host: mail.example.com
  port: 587
  username: support@example.com
  password: ************

注意:example.com 只是一个不共享机密数据的示例,我的配置是正确的,我已经对其进行了测试并且效果很好,但在我的 Spring Boot 应用程序上却没有

【问题讨论】:

  • 您需要使用实际的SMTP配置,example.com不存在。
  • 我当然做到了!!! example.com 只是一个不共享机密数据的例子,谢谢你的评论,伙计
  • 为什么将其标记为 jhipster?这只是 spring-boot 配置。您的问题缺少一些细节,例如您的邮件服务器(公共或私人)是什么?您是否使用telnet 命令或邮件客户端测试过您的配置?您只显示了您的应用程序属性的摘录,所以我们不知道它是否正确缩进并且在spring 下,它可以是什么?你有没有在调试器中设置断点来检查MailProperties的内容?
  • 感谢您的回答,您是对的,没有必要在该问题上标记 jhipster,因为您说这是一个 spring-boot 配置问题。我确实按照你所说的进行了测试,我发现我忘记添加'mail.smtp.starttls.enable:true'和'mail.smtp.starttls.auth:true'向你致以最诚挚的问候@GaëlMarziou

标签: java spring-boot smtp


【解决方案1】:

我在下面提供了一个示例。 显示我如何使用 spring-boot 发送电子邮件

pom.xml 中添加启动邮件依赖项:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

在您的应用程序类中添加以下 bean:

@Bean
public JavaMailSenderImpl customJavaMailSenderImpl(){

    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(host);
    mailSender.setPort(port);
     
    mailSender.setUsername(username);
    mailSender.setPassword(password);
     
    Properties props = mailSender.getJavaMailProperties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.debug", "true");
     
    return mailSender;

}

看一个例子,使用下面的customJavaMailSenderImpl bean:

@Service
public class emailSender{
   
   @Autowired
   JavaMailSenderImpl customJavaMailSenderImpl;

   public void mailWithAttachment() throws Exception {
    
    MimeMessage message = customJavaMailSenderImpl.createMimeMessage();
      
    MimeMessageHelper helper = new MimeMessageHelper(message, true,"utf-8");
     
    helper.setTo("abc@example.com");
    helper.setSubject("test");
    helper.setText("hello test", true);
    helper.setFrom("abd@example.com", "John Doe");
      
    
 
    customJavaMailSenderImpl.send(message);
    
 }


}

【讨论】:

    【解决方案2】:

    经过审核,我发现我忘记在我的application-dev.yml 中添加一些邮件配置:

    mail.smtp.starttls.enable : truemail.smtp.starttls.auth : true

    邮件配置应如下所示:

    mail:   
      host: mail.example.com
      port: 587
      username: support@example.com
      password: ************
      properties:
        mail:
          smtp:
            auth: true
            starttls:
              enable: true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-28
      • 2012-10-19
      • 2014-09-16
      • 2019-04-02
      • 2017-08-31
      • 2020-02-05
      • 2023-02-26
      • 2018-03-08
      相关资源
      最近更新 更多