Spring boot application return me : 550 Access denied – Invalid HELO name (See RFC2821 4.1.1.1)

huangapple go评论78阅读模式
英文:

Spring boot application return me : 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

问题

在尝试通过我的Spring Boot应用程序发送电子邮件时,我遇到了以下错误:

failures; nested exception is javax.mail.MessagingException: 无法向SMTP主机发送命令;
嵌套异常为:
java.net.SocketException: 软件引起的连接中止:套接字写入错误。失败的消息:com.sun.mail.smtp.SMTPSendFailedException:550访问被拒绝 - 无效的HELO名称(请参阅RFC2821 4.1.1.1);
嵌套异常为:
com.sun.mail.smtp.SMTPSenderFailedException:550访问被拒绝 - 无效的HELO名称(请参阅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应用程序上却不行。

英文:

while trying to send email via my spring boot application i got this error :

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)

My Spring boot application is generated with jhipster and here is my application-dev.yml config for mail config :

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

NB : example.com is just an example for not sharing confidential data, my config is correct i have tested it with and working great but not on my spring boot application

答案1

得分: 2

以下是翻译好的内容:

我已经提供了以下示例。
展示了我如何使用 spring-boot 发送电子邮件。

在您的 pom.xml 中添加 starter mail 依赖项:

<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);
        
     }
}
英文:

I have provided a sample below.
Showing how I send emails with spring-boot

add the starter mail dependency in your pom.xml :

&lt;dependency&gt;
   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
   &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
&lt;/dependency&gt;

Add the below bean in your Application class :

@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(&quot;mail.transport.protocol&quot;, &quot;smtp&quot;);
    props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
    props.put(&quot;mail.smtp.starttls.enable&quot;, &quot;true&quot;);
    props.put(&quot;mail.debug&quot;, &quot;true&quot;);
     
    return mailSender;

}

See an example, using the customJavaMailSenderImpl bean below :

@Service
public class emailSender{
   
   @Autowired
   JavaMailSenderImpl customJavaMailSenderImpl;

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


}

答案2

得分: 0

经过审核,我发现我忘记在我的 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
英文:

After review i found that i forgot to add some mail config in my application-dev.yml :

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

mail config should look like :

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

huangapple
  • 本文由 发表于 2020年9月6日 18:32:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63763156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定