Error sending email using SMTP oauth

Andrius Antipovas 6 Reputation points
2022-10-31T10:59:02.223+00:00

Hi all!

I just started to configurate my application from Basic Auth to oauth. I am using MSAL library to get token. I am providing scope "https://outlook.office365.com/.default". I get a valid token. With reading emails everythink works fine. But when my application try to send an email I get this error: Authentication unsuccessful [AS8PR04CA0035.eurprd04.prod.outlook.com]. Can someone help?

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,072 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
529 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,641 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Marilee Turscak-MSFT 36,411 Reputation points Microsoft Employee
    2022-10-31T22:24:08.147+00:00

    Hi @Andrius Antipovas ,

    The Outlook REST API is deprecated and this may have something to do with the issue. I have seen this error occur for a few people when they were mixing Graph and Outlook scopes. https://learn.microsoft.com/en-us/outlook/rest/compare-graph#moving-from-outlook-endpoint-to-microsoft-graph.

    It's difficult to know based on this information whether this is on the app side or the Outlook side of things. If you collect a fiddler trace it will be easier to determine the source. This is the article we usually reference in these scenarios: Authenticate an IMAP, POP or SMTP connection using OAuth | Microsoft Learn. If you cannot confirm whether there is something wrong with the access token, it would be worth checking with the Outlook/Exchange team on this question.

    Is the error you noted occurring after clicking save? Sometimes these button clicks trigger multiple request sequences. There is usually an app log that shows the token request and result as well as any subsequent connection requests, and the trace capture should confirm the same.

    Another possibility is that there is something blocking the traffic or enforcing restrictions, such as a spam blocker or proxy.

    If you don't find the solution in the logs and would prefer to share the fiddler trace over email, we can troubleshoot that way as well.

    Thanks,

    Marilee

    -

    If the information helped you, please Accept the answer. This will help us and other community members as well.

    0 comments No comments

  2. Andrius Antipovas 6 Reputation points
    2022-11-01T07:49:43.083+00:00

    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    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 AM6P191CA0103.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 1 Nov 2022 07:42:51 +0000
    DEBUG SMTP: connected to host "smtp.office365.com", port: 587
    09:42:52,208 INFO [stdout] (default task-61)
    09:42:52,210 INFO [stdout] (default task-61) EHLO LAPTOP-B9EFAE7N
    250-AM6P191CA0103.outlook.office365.com Hello [78.63.248.206]
    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 LAPTOP-B9EFAE7N
    250-AM6P191CA0103.outlook.office365.com Hello [78.63.248.206]
    250-SIZE 157286400
    250-PIPELINING
    250-DSN
    250-ENHANCEDSTATUSCODES
    250-AUTH LOGIN XOAUTH2
    250-8BITMIME
    09:42:52,472 INFO [stdout] (default task-61) 250-BINARYMIME
    09:42:52,472 INFO [stdout] (default task-61) 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: Attempt to authenticate using mechanisms: XOAUTH2
    DEBUG SMTP: Using mechanism XOAUTH2
    AUTH XOAUTH2 dXNlcj1jcm10ZXN0YXNAdmVyc2xvYWxqYW5zYXMubHQ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LOOK.COM]
    ERROR [stderr] (AsyncAppender-Worker-Thread-326) javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [AM6P191CA0103.EURP191.PROD.OUTLOOK.COM

    0 comments No comments

  3. Andrius Antipovas 6 Reputation points
    2022-11-01T08:06:58.403+00:00

    @Marilee Turscak-MSFT I added logs from my application.