繁体   English   中英

使用OAuth和JavaMail发送电子邮件

[英]Sending an email with OAuth and JavaMail

我有一个Outlook.com电子邮件帐户。 我希望我的Java应用程序能够使用JavaMail从该电子邮件帐户发送电子邮件。 为此,我已经通过OAuth授予了我的应用访问权限。

我已经可以使用msgshow.java中提供的精彩示例应用程序通过IMAP成功连接。 但是,我正在尝试通过SMTP通过Outlook.com电子邮件帐户发送电子邮件,但没有任何运气。 我尝试使用msgsend.java和smtpsend.java应用程序。 但是,我没有任何运气。 我试过了:

java -Dmail.smtp.starttls.enable=true msgsend -d -M smtp-mail.outlook.com -U myAddress@outlook.com -P [oauthAccessToken] recipient@domain.com

返回:

550 5.7.3 Requested action aborted; user not authenticated
DEBUG SMTP: got response code 550, with response: 550 5.7.3 Requested action aborted; user not authenticated

RSET
DEBUG SMTP: EOF: [EOF]
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.3 Requested action aborted; user not authenticated
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.3 Requested action aborted; user not authenticated

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2202)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1693)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)
    at javax.mail.Transport.send0(Transport.java:254)
    at javax.mail.Transport.send(Transport.java:124)
    at msgsend.main(msgsend.java:188)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.3 Requested action aborted; user not authenticated

    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1700)
    ... 4 more

我也尝试过:

java -Dmail.smtp.starttls.enable=true smtpsend -d -A -M smtp-mail.outlook.com -U myAddress@outlook.com -P [oauthAccessToken] recipient@domain.com

我有:

DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
Got Exception: javax.mail.AuthenticationFailedException: 535 5.0.0 Authentication Failed

如何使用OAuth通过Outlook.com通过JavaMail发送电子邮件?

谢谢!

您是否在JavaMail Wiki上看到说明 它们显示了如何在Java中执行此操作,但是您可以通过在命令行上设置属性(例如“ -Dmail.smtp.auth.login.disable = true”)来使用msgshow.java进行操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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