Spring Boot邮件发件人错误:com.sun.mail.smtp.SMTPSendFailedException

时间:2019-03-26 15:40:19

标签: java spring-boot outlook office365

我想在Spring Boot应用程序中创建一个邮件发件人。这是我的配置和邮件发件人的代码

application.properties:

spring.mail.host=smtp.office365.com
spring.mail.username=********@outlook.com
spring.mail.password=********
spring.mail.port=587 
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.required=true

邮件发件人代码:

@Service
public class EmailSender {


    @Autowired 
    private  JavaMailSender javaMailSender; 

    public  void send ( String to , String subject , String body ) throws MessagingException {


        MimeMessage message = javaMailSender.createMimeMessage() ; 
        MimeMessageHelper helper ; 
        helper = new    MimeMessageHelper(message , true ) ;  
        helper.setSubject(subject);
        helper.setTo(to); 
        helper.setText(body ,true ); 
        javaMailSender.send(message);


    }

}

当我调用send方法时,我在stacktrace中有以下异常:

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:EE030000, 17.43559:0000000094000000000000000000000000000000, 20.52176:140FC28611004010F1030000, 20.50032:140FC28683174010F1030000, 0.35180:3D100000, 255.23226:00000000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:140FC286, 16.55847:8C000000, 17.43559:0000000070010000000000000100000000000000, 20.52176:140FC2861100F01F0A000000, 20.50032:140FC28683170011810F0000, 0.35180:00000000, 255.23226:00000000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:140FC286, 4.21921:DC040000, 255.27962:FA000000, 255.1494:64000000, 0.38698:00000000, 0.37692:05000780, 0.37948:1A010480, 5.33852:00000000534D545000000100, 4.56248:DC040000, 7.40748:010000000000010B05000780, 7.57132:000000000000000000000000, 1.63016:32000000, 4.39640:DC040000, 8.45434:014003006018492000000000000000001A010480, 5.10786:0000000031352E32302E313733302E3031373A564931505231304D42313930333A36356263666132632D336133352D343030662D616665622D34306239353462656436373500503000000000, 255.1750:A0000000, 255.31418:0A005636, 0.22753:A5000000, 255.21817:DC040000, 4.60547:DC040000, 0.21966:03003866, 4.30158:DC040000 [Hostname=VI1PR10MB1903.EURPRD10.PROD.OUTLOOK.COM]

1 个答案:

答案 0 :(得分:0)

您应该将“ From-header”设置为您的用户名。