Sending an email via Matlab, how do I fix an 'Authentication failed' error?

27 ビュー (過去 30 日間)
Iddo Weiner
Iddo Weiner 2016 年 11 月 1 日
編集済み: Iddo Weiner 2016 年 11 月 2 日
Hi,
I'm having trouble with sending emails through Matlab. I read about it, and tried all kinds of suggestions. Here is a detailed example for the type of codes I've been trying:
%
% parameters
mail = 'mymail@gmail.com'; % my gmail address
password = 'mypassword'; % my gmail password
host = 'smtp.mail.com';
% preferences
setpref('Internet','SMTP_Server', host);
setpref('Internet','E_mail',mail);
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.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
% Send the email
sendmail(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')
But I keep on getting this error:
%
Error using sendmail (line 171)
Authentication failed.
Any ideas what might be causing this? How do I get passed it?
Thanks

採用された回答

mizuki
mizuki 2016 年 11 月 2 日
Check the following two things:
1. Change the variable host as
host = 'smtp.gmail.com';
  1 件のコメント
Iddo Weiner
Iddo Weiner 2016 年 11 月 2 日
編集済み: Iddo Weiner 2016 年 11 月 2 日
Thanks,
The "gmail" was a typo, but the second suggestion worked. I thought I already adjusted my account for allowing less secure apps but apparently I didn't do it correctly.
Now it works :) thanks

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by