Using sendmail with gmail oauth2 credentials

57 ビュー (過去 30 日間)
Petorr
Petorr 2022 年 6 月 8 日
コメント済み: Petorr 2022 年 6 月 8 日
I want to send emails programmatically from matlab through gmail, using sendmail. Gmail recently ended support for simple user&password SMTP and they now require oauth2. I almost have oauth2 working, but I think I am stuck on setting up sendmail to properly use "XOAUTH2" credentials. Sendmail returns an error, "Authentication failed."
My question is: assuming I have a valid access token with permissions "scope" set to https://mail.google.com, how do I configure the settings to use sendmail with XOAUTH2?
Any help appreciated, thanks!
  2 件のコメント
Petorr
Petorr 2022 年 6 月 8 日
I have set up my smtp environment like this:
setpref('Internet','SMTP_Server',email_server);
setpref('Internet','E_mail',email_address);
setpref('Internet','SMTP_Username',email_user);
setpref('Internet','SMTP_Password',access_token);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.port','587');
props.setProperty('mail.smtp.starttls.enable', 'true' );
props.setProperty('mail.smtp.starttls.required','true');
props.setProperty('mail.smtp.ssl.enable','true')
props.setProperty('mail.smtp.user',email_address);
props.setProperty('mail.smtp.host','smtp.gmail.com');
props.setProperty('mail.smtp.port','587');
props.setProperty('mail.smtp.auth.mechanisms',['XOAUTH2']);
Petorr
Petorr 2022 年 6 月 8 日
sendmail error:
Authentication failed.
% more detailed:
% 'Java exception occurred:
% javax.mail.AuthenticationFailedException
% at javax.mail.Service.connect(Service.java:306)
% at javax.mail.Service.connect(Service.java:156)
% at javax.mail.Service.connect(Service.java:105)
% at javax.mail.Transport.send0(Transport.java:168)
% at javax.mail.Transport.send(Transport.java:98)
% '

サインインしてコメントする。

採用された回答

Jan
Jan 2022 年 6 月 8 日
  1 件のコメント
Petorr
Petorr 2022 年 6 月 8 日
Yes, I saw that answer and it seems to work so far. I just don't know how long google will support this almost-the-same workaround, if the password expires occasionally or not, etc etc so I was hoping to get the whole oauth2 thing working. The method in the above answer does let me send emails as before, with gmail credentials and sendmail. Thanks Jan!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by