英文:
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
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
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("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
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,"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
得分: 0
经过审核,我发现我忘记在我的 application-dev.yml
中添加一些邮件配置:
mail.smtp.starttls.enable: true
和 mail.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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论