简体   繁体   中英

Client does not have permissions to send as this sender | Works fine with JavaMail API 1.4 but not with 1.4.7

I found a similar question asked and I have same issue when sending an email with a different username than from name. The configurations in my private exchange server are in place to mark the username as alias of the from name.

com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.1 Client does not have permissions to send as this sender

I am able to send email with an alias when I use Java mail 1.4 version of API. However, the same fails, if I use 1.4.7 version. I assume any version higher than 1.4 is not working. Have anybody encountered the same? Is there any security configuration added to later versions or any additional parameters that needs to be passed?

Session Debug logs when error occurred using JavaMail v1.4.7 as below:

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: trying to connect to host "Exchange IP", port 143, isSSL false
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: protocolConnect login, host=Exchange IP, user=diffUser, password=<non-null>
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: AUTH: PLAIN
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "Exchange IP", port 25, isSSL false
220 EXC001-ABC.mycompany.org Microsoft ESMTP MAIL Service ready at Mon, 8 Jul 2019 16:49:59 +0100
DEBUG SMTP: connected to host "Exchange IP", port: 25

EHLO SCCM-10C.mycompany.org
250-EXC001-ABC.mycompany.org Hello [Machine IP]
250-SIZE 20971520
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-AUTH LOGIN
250-8BITMIME
250-BINARYMIME
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "20971520"
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 "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<from@company.org>
250 2.1.0 Sender OK
RCPT TO:<to@diffcompany.org>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   to@diffcompany.org
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: from@company.org
To: to@diffcompany.org
Message-ID: <1308244637.0.1562600999518.JavaMail.Sam-adm@SCCM-10C>
Subject: This is the Subject Line!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is actual message
.
550 5.7.1 Client does not have permissions to send as this sender
DEBUG SMTP: got response code 550, with response: 550 5.7.1 Client does not have permissions to send as this sender

RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1889)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1120)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at SendEmail.getExchangeStore(SendEmail.java:141)
    at SendEmail.main(SendEmail.java:14)
QUIT
221 2.0.0 Service closing transmission channel
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender

Debug Logs of working example with JavaMail v1.4

DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
DEBUG: protocolConnect login, host=Exchange IP, user=diffUser, password=<non-null>
A1 AUTHENTICATE PLAIN
+
A1 OK AUTHENTICATE completed.
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "Exchange IP", port 25, isSSL false
220 EXC001-ABC.mycompany.org Microsoft ESMTP MAIL Service ready at Mon, 8 Jul 2019 16:55:59 +0100
DEBUG SMTP: connected to host "Exchange IP", port: 25

EHLO SCCM-10C.mycompany.org
250-EXC001-ABC.mycompany.org Hello [Machine IP]
250-SIZE 20971520
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-AUTH LOGIN
250-8BITMIME
250-BINARYMIME
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "20971520"
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 "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<from@company.org>
250 2.1.0 Sender OK
RCPT TO:<to@diffcompany.org>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   to@diffcompany.org
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: from@company.org
To: to@diffcompany.org
Message-ID: <548246552.01562601360722.JavaMail.Sam-adm@SCCM-10C.mycompany.org>
Subject: This is the Subject Line!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is actual message
.
250 2.6.0 <548246552.01562601360722.JavaMail.Sam-adm@SCCM-10C.mycompany.org> [InternalId=344885] Queued mail for delivery
QUIT
221 2.0.0 Service closing transmission channel

When using JavaMail 1.4.7, you're authenticating to the SMTP server. When using JavaMail 1.4, you're not authenticating. Something about the way you're configuring authentication is causing different behavior. Perhaps you're doing

props.setProperty("mail.smtp.auth", true);

instead of

props.setProperty("mail.smtp.auth", "true");

In JavaMail 1.4, the first resulted in the property being set to false. In JavaMail 1.4.7 it now handles both string and primitive objects as the value and sets the property to true.

But I have no idea why your server rejects the message when you authenticate but accepts it when you're anonymous.

(Also, you need to change your password - the base64 encoded PLAIN authentication output includes your password.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM