Automated Mail Through MATLAB
Use of sendmail function to send an email from a gmail account
Use of sendmail function to send an email from a gmail account
function SendEmailFromMatlab(emailto,subject,message,attachment)
%Specify the Gmail accout and password.
mail = 'XXXX'; % App Password (a 16-digit passcode)
password = 'XXXXX'; %Your GMail password
% Set up Gmail SMTP service and email preferences.
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
%%%setpref('Internet','SMTP_Server','smtp.aol.com'); This works for AOL account
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
% Gmail server.
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');
props.setProperty('mail.smtp.starttls.enable','true');
sendmail(emailto,subject,message,attachment)