SMTP 发送多封邮件

SMTP Sending multiple emails

我必须在每个月的第一天向大约 150 人发送提醒电子邮件。

好像还不错,但是这个月...我开始得到

Caused by: javax.mail.AuthenticationFailedException: 421 4.3.2 Service not active [BN6PR1801CA0007.namprd18.prod.outlook.com]

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965) ~[javax.mail-1.6.2.jar!/:1.6.2]
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876) ~[javax.mail-1.6.2.jar!/:1.6.2]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780) ~[javax.mail-1.6.2.jar!/:1.6.2]
at javax.mail.Service.connect(Service.java:366) ~[javax.mail-1.6.2.jar!/:1.6.2]

突然出现这个错误信息。

它仍然可以很好地发送给少数人。

当我尝试大量的人时,它发送给大约 10 个人并抛出该错误。 然后,它会在几分钟后发送其余的电子邮件;但是,由于错误,它似乎没有正确结束循环。

---application.properties---

spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.username=xx@xxxx.com
spring.mail.password=xxxxxx
spring.mail.properties.mail.transport.protocol=smtps
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtps.timeout=8000

---发送方式---

public void sendEmail(String tok, String email, int file, String msg, String to) throws UnsupportedEncodingException, MessagingException, FileNotFoundException
    {       
        FilePath fp = new FilePath();
        String token = tok;
        String recipientAddress = email;
        String subjectConfirm = "Confirm " + to;
        String subjectAlert = "Alert " +  to;
        String confirmationUrl = fp.getServer() + "/to/filesConfirm?token=" + token;
        String message = msg;

        MimeMessagePreparator preparator = new MimeMessagePreparator() {

            public void prepare(MimeMessage mimeMessage) throws Exception {

                mimeMessage.setRecipient(Message.RecipientType.TO, 
                        new InternetAddress(recipientAddress));
                mimeMessage.setFrom(new InternetAddress("xx@xxxx.com"));

                if (file > 0) 
                {
                    mimeMessage.setSubject(subjectConfirm);
                    mimeMessage.setContent(message + "<br>" + "<a target='_blank' href="+confirmationUrl+"><button>Confirm</button></a>"
                            + "<br>" + "If the button above doesn't work, please click or copy&paste the address below to 'Confirm'."
                            + "<br>" + confirmationUrl, "text/html;charset=UTF-8");
                }
                else
                {
                    mimeMessage.setText(message);
                    mimeMessage.setSubject(subjectAlert);
                }
            }
        }; this.mailSender.send(preparator);
    }

我已经通过将主机切换到 amazon 来修复它