The sendgmail function, which I write by myself and works well on version MATLAB 2015b, is not working on version after 9.0(MATLAB 2016a and 2016b)

1 view (last 30 days)
The m file shows as follows.
function lzhanu(recipient, subject, content, attachment)
% MATLABMAIL Send an email from a predefined account.
% See also sendmail.
sender = '*';%It is sender address.
psswd = '*';%It is sender password.
setpref('Internet','SMTP_Server','smtp.gmail.com');%It is the smtp serve of sender's mail.
setpref('Internet','E_mail',sender);
setpref('Internet','SMTP_Username',sender);
setpref('Internet','SMTP_Password',psswd);
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');
switch nargin
case 3
sendmail(recipient, subject, content);
case 4
sendmail(recipient, subject, content, attachment);
end
disp(['The email to ' recipient 'is successful!'])
end
The function works well on Matlab 2015b, but when I use Matlab 2016a, I went wrong and command window shows that
Could not connect to SMTP host: smtp.office365.com, port: 25;
Operation timed out
Error in sendgmail (line 23)
sendmail(recipient, subject, content);
Can anyone explain the reason and help me tackle this problem? Thank you!
  1 Comment
Jordan Ross
Jordan Ross on 22 Sep 2016
Hi Zihao,
This issue could be related to the following MATLAB Answers post: https://www.mathworks.com/matlabcentral/answers/229092-sendmail-authentication-error-with-gmail
Also, check that your MATLAB web settings are the same between both your R2015b and R2016a installations. You can check these settings by going to Preferences > MATLAB > Web.

Sign in to comment.

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!