sendasdeniedexception.mapiexceptionsendasdenied-无法通过java发送邮件-即使在outlook上启用了smtp

r7s23pms  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(496)

我有这个java代码。java代码只处理通过outlook发送的邮件。这个例子是一个最小的工作例子。请注意,它不是office 365。这是正常的前景。

@Configuration
@PropertySource("classpath:application.properties")
public class MailConfiguration {

    @Value("${configuration.MailConfiguration.host}")
    private String host;
    @Value("${configuration.MailConfiguration.port}")
    private int port;
    @Value("${configuration.MailConfiguration.username}")
    private String username;
    @Value("${configuration.MailConfiguration.password}")
    private String password;

    @Bean
    public JavaMailSender getJavaMailSender() {

        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;
    }
}

我发出这样的信息。在这里 email = myMail@outlook.com 以及 subject 只是一根线。

// Send message
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setTo(email);
    msg.setSubject(subject);
    msg.setText("Message: " + message +"\nCause: " + cause);
    try {
        javaMailSender.send(msg);
    }catch(Exception e) {
        // Something went wrong
    }

当我运行上面的代码时,我得到了这个错误。我在想为什么。

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
220 HE1PR0701CA0065.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 25 Dec 2020 01:56:03 +0000
DEBUG SMTP: connected to host "smtp.office365.com", port: 587
EHLO dell-Precision-M6400
250-HE1PR0701CA0065.outlook.office365.com Hello [213.89.50.140]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO dell-Precision-M6400
250-HE1PR0701CA0065.outlook.office365.com Hello [213.89.50.140]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.office365.com, user=myMail@outlook.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<dell@dell-Precision-M6400>
250 2.1.0 Sender OK
RCPT TO:<myMail@outlook.com>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   myMail@outlook.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Fri, 25 Dec 2020 02:56:05 +0100 (CET)
To: myMail@outlook.com
Message-ID: <783908570.5.1608861365004@dell-Precision-M6400>
Subject: Alarm Message Subject Title
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Message: hejehej
Cause: Mesurement exceeded the threshold at analog input 0.
.
554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 

RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW: 
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.

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2373)
    at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2095)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1301)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:465)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:323)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:312)
    at se.danielmartensson.service.MailService.sendMessage(MailService.java:44)
    at se.danielmartensson.threads.SamplingThread.run(SamplingThread.java:227)
QUIT
221 2.0.0 Service closing transmission channel

我在outlook中启用了pop和imap。但是,我还是不能送。如你所见,我可以登录 DEBUG SMTP: AUTH LOGIN succeeded .
但为什么会这样呢?

bis0qfac

bis0qfac1#

这是一个与登录/发件人相关的问题。
554 5.2.0 SendAsDenied 您正试图使用与outlook登录地址不同的发件人发送邮件。
在您的情况下,您的登录名是 MAILFROM 您尝试发送的是另一个:
MAIL FROM --> dell@dell-Precision-M6400 LOGIN --> myMail@outlook.com 所以呢 SendAs (dell@dell-Precision-M6400) Denied 被抛出。
要进行简单的测试,请尝试发送相同的邮件,但outlook凭据设置为 MAILFROM . 它应该不会出错。
要设置不同的有效发件人,请在outlook管理面板中添加新发件人。如果尝试使用不同于您登录名的发件人发送电子邮件,则可以避免例外情况。

相关问题