Using gmail after May 30, 2022

125 次查看(过去 30 天)
I am currently using Matlab to send emails using Gmail with "less secure apps" selected to "ON" under Google Security. This topic has been discussed at length in several threads and I currently have no problems, however, as per Google: "To help keep your account secure, starting May 30, 2022, ​​Google will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password."
So, after May, 30th, I will no longer be able to use Matlab to send emails via Gmail. Does anyone have a work around for this?
  6 个评论
Joseph Hejl
Joseph Hejl 2022-3-16
I think I have it working. In Google Security "Less Secure Apps" is turned OFF. Enable 2-Step authentication and log in to the Google Gmail account. Search for "App Paswords", and under "Select app" type "MATLAB" without the quotes, then press "Generate" button. This produces a 16-digit passcode that is then used in place of the Gmail account password. So use the above code but replace
password = 'MyPassword'; %Your GMail password
with
password = 'MyPasscode'; %Your GMail 16-digit passcode
Rik
Rik 2022-3-16
It sounds like you should post that last comment as an answer. That way other people can try this solution as well.

请先登录,再进行评论。

采纳的回答

Joseph Hejl
Joseph Hejl 2022-3-16
I think I have it working. In Google Security "Less Secure Apps" is turned OFF. Enable 2-Step authentication and log in to the Google Gmail account. Search for "App Paswords", and under "Select app" type "MATLAB" without the quotes, then press "Generate" button. This produces a 16-digit passcode that is then used in place of the Gmail account password. So use the above code but replace
password = 'MyPassword'; %Your GMail password
with
password = 'MyPasscode'; %Your GMail 16-digit passcode
  6 个评论
Joseph Hejl
Joseph Hejl 2022-10-15
drummer, once the 16 digit passcode has been created, it works every time, no need to recreate the passcode.
YANBO JIANG
YANBO JIANG 2023-7-29
Could you please provide the current whole setting up to send email in MATLAB?

请先登录,再进行评论。

更多回答(1 个)

Ivan
Ivan 2023-11-21
In my side works perfect the folowing code
server='smtp.gmail.com';
setpref('Internet','E_mail', mail);
setpref('Internet','SMTP_Server', server);
setpref('Internet','SMTP_Username', mail);
setpref('Internet','SMTP_Password', password);
props = java.lang.System.getProperties
props.setProperty( 'mail.smtp.auth', 'true' );
props.setProperty( 'mail.smtp.user', mail );
props.setProperty( 'mail.smtp.password', password );
props.setProperty( 'mail.smtp.host', server );
props.setProperty( 'mail.smtp.port', '587' );
props.setProperty( 'mail.smtp.starttls.enable', 'true' );
Also,pay attention that App Paswordsincludesspaces between groups of numbers when you copy it from Google.

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by