简体   繁体   English

使用OAuth和JavaMail发送电子邮件

[英]Sending an email with OAuth and JavaMail

I have an Outlook.com email account. 我有一个Outlook.com电子邮件帐户。 I want my Java app to be able to send emails from that email account using JavaMail. 我希望我的Java应用程序能够使用JavaMail从该电子邮件帐户发送电子邮件。 To do that, I've granted my app access via OAuth. 为此,我已经通过OAuth授予了我的应用访问权限。

I have been able to successfully connect via IMAP using the wonderful sample app available in msgshow.java. 我已经可以使用msgshow.java中提供的精彩示例应用程序通过IMAP成功连接。 However, I'm trying to send an email through my Outlook.com email account via SMTP and I'm not having any luck. 但是,我正在尝试通过SMTP通过Outlook.com电子邮件帐户发送电子邮件,但没有任何运气。 I've tried using both the msgsend.java and smtpsend.java apps. 我尝试使用msgsend.java和smtpsend.java应用程序。 However, I haven't had any luck. 但是,我没有任何运气。 I tried: 我试过了:

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

which returned: 返回:

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

I also tried: 我也尝试过:

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

I got: 我有:

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

How do you send email via JavaMail through Outlook.com using OAuth? 如何使用OAuth通过Outlook.com通过JavaMail发送电子邮件?

Thank you! 谢谢!

Did you see the instructions on the JavaMail wiki ? 您是否在JavaMail Wiki上看到说明 They show how to do it in Java, but you can do the same using msgshow.java by setting the properties on the command line, eg, "-Dmail.smtp.auth.login.disable=true". 它们显示了如何在Java中执行此操作,但是您可以通过在命令行上设置属性(例如“ -Dmail.smtp.auth.login.disable = true”)来使用msgshow.java进行操作。

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

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