客户端无权作为此发件人发送 |适用于 JavaMail API 1.4 但不适用于 1.4.7
Client does not have permissions to send as this sender | Works fine with JavaMail API 1.4 but not with 1.4.7
我发现了一个类似的问题,并且在使用与姓名不同的用户名发送电子邮件时遇到了同样的问题。我的私人交换服务器中的配置已到位以将用户名标记为发件人名称的别名。
com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.1 Client does not have permissions to send as this sender
当我使用 Java 邮件 1.4 版本 API 时,我可以发送带有别名的电子邮件。但是,如果我使用 1.4.7 版本,同样会失败。我假设任何高于 1.4 的版本都不起作用。有人遇到过相同的吗?后面的版本有没有增加安全配置或者需要传递什么额外的参数?
使用 JavaMail v1.4.7 发生错误时的会话调试日志如下:
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
使用 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
使用 JavaMail 1.4.7 时,您正在向 SMTP 服务器进行身份验证。使用 JavaMail 1.4 时,您没有进行身份验证。您配置身份验证的方式导致了不同的行为。也许你正在做
props.setProperty("mail.smtp.auth", true);
而不是
props.setProperty("mail.smtp.auth", "true");
在 JavaMail 1.4 中,第一个导致 属性 被设置为 false。在 JavaMail 1.4.7 中,它现在将字符串和原始对象都作为值处理,并将 属性 设置为 true。
但我不知道为什么您的服务器在您进行身份验证时拒绝该邮件,而在您匿名时接受该邮件。
(另外,您需要更改密码 - base64 编码的 PLAIN 身份验证输出包括您的密码。)
我发现了一个类似的问题,并且在使用与姓名不同的用户名发送电子邮件时遇到了同样的问题。我的私人交换服务器中的配置已到位以将用户名标记为发件人名称的别名。
com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.1 Client does not have permissions to send as this sender
当我使用 Java 邮件 1.4 版本 API 时,我可以发送带有别名的电子邮件。但是,如果我使用 1.4.7 版本,同样会失败。我假设任何高于 1.4 的版本都不起作用。有人遇到过相同的吗?后面的版本有没有增加安全配置或者需要传递什么额外的参数?
使用 JavaMail v1.4.7 发生错误时的会话调试日志如下:
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
使用 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
使用 JavaMail 1.4.7 时,您正在向 SMTP 服务器进行身份验证。使用 JavaMail 1.4 时,您没有进行身份验证。您配置身份验证的方式导致了不同的行为。也许你正在做
props.setProperty("mail.smtp.auth", true);
而不是
props.setProperty("mail.smtp.auth", "true");
在 JavaMail 1.4 中,第一个导致 属性 被设置为 false。在 JavaMail 1.4.7 中,它现在将字符串和原始对象都作为值处理,并将 属性 设置为 true。
但我不知道为什么您的服务器在您进行身份验证时拒绝该邮件,而在您匿名时接受该邮件。
(另外,您需要更改密码 - base64 编码的 PLAIN 身份验证输出包括您的密码。)