然后,在matlab命令窗口(command window),输入: doc sendmail,函数介绍如下:
1
2
3
4
5
6
7
8
9
10
|
MailAddress =
'XXXXXXXX@126.com'
;% 发送地址
password =
'XXXX'
; %密码
setpref(
'Internet'
,
'E_mail'
,MailAddress);
setpref(
'Internet'
,
'SMTP_Server'
,
'smtp.126.com'
);%SMTP服务器
setpref(
'Internet'
,
'SMTP_Username'
,MailAddress);
setpref(
'Internet'
,
'SMTP_Password'
,password);
props = java.lang.System.getProperties;
props.setProperty(
'mail.smtp.auth'
,
'true'
);
%sendmail(to, subject, content);
% 举个例子,比如想把前面运行得到精确度数据发送给程序员
accuracy=0.888;
% 收件人
receiver='myself@123.com';
% 邮件标题
mailtitle='pattern recognition';
% 邮件内容
mailcontent=['mission compeleted! ',... 'accuracy=',num2str(accuracy)];
% 发送
sendmail(receiver, mailtitle, mailcontent);
|
为了以后方便使用,可以包装成一个函数:
1
2
3
4
5
6
7
8
9
10
|
function mailTome(subject,content)
MailAddress =
'XXXXXX@126.com'
;
password =
'X'
;
setpref(
'Internet'
,
'E_mail'
,MailAddress);
setpref(
'Internet'
,
'SMTP_Server'
,
'smtp.126.com'
);
setpref(
'Internet'
,
'SMTP_Username'
,MailAddress);
setpref(
'Internet'
,
'SMTP_Password'
,password);
props = java.lang.System.getProperties;
props.setProperty(
'mail.smtp.auth'
,
'true'
);
sendmail(
'X'
,subject,content); <br>end
|
得到mail2me这个函数之后,只要在程序后面加上一句类似的:
mailTome('Program Over','**** Program has finished');
真的没有问题了么?程序员的思想总是接近完备的。
函数中存在个人隐私(手机号码和密码),如果被人看到然后用来捉弄你就不好了。 MATLAB也是完备的,她提供了一种很好的内容保护机制: protected-code。
Command Window 键入:
1
|
pcode mailTome
|
然后删除mail2me.m。在此之后,再次输入:
1
|
mailTome(
'Is OK?'
,
'见证奇迹的时刻到了'
);
|
从此,再也不会有第二个人知道你这个函数里面的内容了.
转载地址:http://www.cnblogs.com/ywl925/p/3574011.html