使用集群计算的时候,我常常无法预估提交的任务何时结束,
这个时候在任务的最后添加一条邮件提醒,如虎添翼。



结合此篇食用更佳!实测Matlab比IFTTT快。

主要用到的函数是sendmail:

sendmail(recipients,subject)
sendmail(recipients,subject,message)
sendmail(recipients,subject,message,attachments)

function MySendMail(subject,content,attachments)
%--------------------------------------------------------------------------
% Description:  To send email via Matlab built-in Java.
%               Gmail can be changed to any SMPT email provider.
%               Each Input can be set to [] if it should be, or it will
%               send a demo as below.
%
% Input :   subject,char
%           content,char
%           attachments,char,a file path
%        
% Based on: https://blog.csdn.net/ouening/article/details/52079747
%
% Create on 2019-07-18, by Hengkai Yao, @TAMU College Station,TX,US
%--------------------------------------------------------------------------

% Gmail SMPT Reference
% https://support.google.com/mail/answer/7126229?hl=zh-Hans&visit_id=636990788620179468-3947722520&rd=2

MailAddress = 'hengkai.yao@gmail.com';% Change to your sending email address            
password    = 'yourEmailPassword'    ;% Change to your sending email password   
SMPTAddress = 'smtp.gmail.com'       ;% Change to your SMTP provider address
smtpPort    = '465'                  ;% Change to your SMTP port

setpref('Internet','E_mail',       MailAddress);
setpref('Internet','SMTP_Server',  SMPTAddress);   
setpref('Internet','SMTP_Username',MailAddress);      
setpref('Internet','SMTP_Password',password);

props = java.lang.System.getProperties;             % use Java
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
    'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port',smtpPort);


subject = 'MATLAB Sendmail Function Test';             % Change to your own subject
content = 'Hello,this is sent by Sendmail Function. '; % Change to your own content
attachments = './MySendMail.m';                        % Change to your own Attachments
recipients  = 'hengkai.yao@gmail.com';                 % Change to your reveiving mail address

sendmail(recipients,subject,content,attachments);

发送后,收件人的邮箱图示如下:
Screen Shot 2019-07-18 at 16.18.01.png

程序下载地址:MySendMail_empty.m

Last modification:August 3rd, 2019 at 05:07 pm
If you think my article is useful to you, please feel free to appreciate