MATLAB脚本发送邮件

来源:互联网 发布:南京行知基地冬季学农 编辑:程序博客网 时间:2024/06/01 09:44

最近看到一段MATLAB发送邮件的代码,测试了一下可以,在此分享一下。

测试环境:MATLAB2010

function MySendMail%% 发送邮件a = rand(100);DataPath = [matlabroot,filesep,'mydata.mat'];       % filesep='\'save DataPath a ;                                   % 将变量a的值保存为mydata.mat           MailAddress = '发送邮件的邮箱地址';            password = '发送邮箱的密码'; setpref('Internet','E_mail',MailAddress);setpref('Internet','SMTP_Server','smtp.163.com');   % STMP服务器地址,不同域名的邮箱地址有不同SMTP服务器地址,可以查询的setpref('Internet','SMTP_Username',MailAddress);    % 发送文件的邮箱setpref('Internet','SMTP_Password',password);props = java.lang.System.getProperties;             % 使用Javaprops.setProperty('mail.smtp.auth','true');props.setProperty('mail.smtp.socketFactory.class', ...    'javax.net.ssl.SSLSocketFactory');props.setProperty('mail.smtp.socketFactory.port','994');    subject = 'MATLAB 发的测试邮件';                             % 邮件主题content = '你好,这份邮件是我用MATLAB发的,数据见附件';        % 邮件内容sendmail('接收邮件的邮箱地址',subject,content,DataPath);     % 接收邮件的邮箱,主题名,内容和文件路径
0 0
原创粉丝点击