java - 邮件发送异常 : Failed messages: com. sun.mail.smtp.SMTPSendFailedException

标签 java spring email smtp jakarta-mail

我尝试使用 javaMail、spring-boot 和 yahoo 发送电子邮件。我得到了这个 SMTPSendFailedException,我不知道为什么。

这里是异常的一部分:

ErrorPageFilter: Forwarding to error page from request [/registration] due to exception [Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in arguments
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments
]
org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in arguments
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments
; message exception details (1) are:
Failed message 1:
com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in arguments
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2203)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1694)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:433)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments

    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1703)
    ... 102 more
[2015-10-27 22:11:14.252] boot - 8407 DEBUG [http-nio-8080-exec-8] --- EndpointHandlerMapping: Looking up handler method for path /error
[2015-10-27 22:11:14.257] boot - 8407 DEBUG [http-nio-8080-exec-8] --- EndpointHandlerMapping: Did not find handler method for [/error]

电子邮件配置属性,我使用 yahoo 作为主机:

spring.mail.host=smtp.mail.yahoo.com
spring.mail.port=465
spring.mail.username=*****@yahoo.com
spring.mail.password=*****
spring.mail.default-encoding=UTF-8
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true

发送电子邮件的实现部分;

@Autowired
JavaMailSender javaMailSender;


    String recipientAddress = XXXX.getUser().getEmail();
    String subject = "Bienvenue chez AAAA";
    String message = "huhuu";
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(recipientAddress);
    email.setSubject(subject);
    email.setText(message + "\n");
    javaMailSender.send(email);

有人可以帮助我吗?

最佳答案

您使用的是什么版本的 JavaMail?你能捕捉到debug output吗? ?邮件服务器提示 SMTP MAIL FROM 命令,这可能意味着您的邮件的发件人地址设置不正确。由于您似乎没有明确设置它,也许 SimpleMailMessage 正在选择一个不好的默认值?将其明确设置为合法值可能会解决问题。

关于java - 邮件发送异常 : Failed messages: com. sun.mail.smtp.SMTPSendFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33378753/

相关文章:

Spring Integration - 未考虑邮件入站 channel 适配器的延迟轮询器

java - IBM Websphere MQ 监控

java - Java 使用 split 时出现 ArrayIndexOutOfBoundsException

ajax - Spring 安全性 + Ajax session 超时问题

spring - 如何覆盖范围 bean 进行测试?

email - Jenkins email-ext 插件认为我没有配置收件人

java - Android opencv 库引用无法正常工作

java - 如何在 Android 上创建渐进式 JPEG 图像

java - 提供上下文时出现异常 :annotation-config

PHP imap_search 收件箱/已发送项目