如何使用matlab发邮件 sendmail 您所在的位置:网站首页 电脑怎么发送邮件到指定邮箱 如何使用matlab发邮件 sendmail

如何使用matlab发邮件 sendmail

2024-07-02 01:41| 来源: 网络整理| 查看: 265

当我们在电脑上运行一个耗时非常大的程序时,有时需要让程序运行完后自动将数据、结果通知自己,这个过程可以用matlab来完成。

MATLAB提供了一个sendmail函数以供使用:

sendmail(收件人邮箱,标题) sendmail(收件人邮箱,标题,内容) sendmail(收件人邮箱,标题,内容,附件名)

说明

sendmail(recipients,subject) 向 recipients 发送具有指定 subject 的电子邮件。对于单个收件人,请将 recipients 指定为字符向量或字符串。对于多个收件人,请将 recipients 指定为字符向量元胞数组或字符串数组。subject 必须是字符向量或字符串。sendmail(recipients,subject,message) 包括指定的 message。如果 message 是字符向量或字符串,则 sendmail 自动在 75 个字符处对文本换行。要强制在消息文本中换行,请使用 10,如示例中所示。如果 message 是字符向量元胞数组或字符串数组,则每个元素代表一行新文本。sendmail(recipients,subject,message,attachments) 附加 attachments 输入参数中列出的文件。attachments 可以是字符向量、字符向量元胞数组或字符串数组。

示例

将包含两个附件的消息发送到假设的电子邮件地址: sendmail('[email protected]',... 'Test subject','Test message',... {'folder/attach1.html','attach2.doc'}); 将包含强制换行符(使用 10)的消息发送到假设的电子邮件地址: sendmail('[email protected]','New subject', ... ['Line1 of message' 10 'Line2 of message' 10 ... 'Line3 of message' 10 'Line4 of message']); 生成的消息为: Line1 of message Line2 of message Line3 of message Line4 of message

默认情况下,sendmail 函数不支持需要身份验证的电子邮件服务器。要支持这些服务器,请使用以下形式的命令更改您的系统设置并设置 SMTP 用户名和密码的预设:

setpref('Internet','SMTP_Server','my_server.example.com'); setpref('Internet','E_mail','[email protected]'); props = java.lang.System.getProperties; props.setProperty('mail.smtp.auth','true');

同时还需要设置服务器端口:

setpref('Internet','SMTP_Username','[email protected]'); setpref('Internet','SMTP_Password','mypassword');

如果使用QQ邮箱需要在设置–账户–POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务开启服务 在这里插入图片描述

接下来就可以使用sendmail发送邮件了: sendmail(‘收件人’, ‘标题’, ‘内容’,‘附件路径’)

下面是一个示例,可以根据自己需求更改

function sendmails(address,object,content) if nargin==2 content=object; object=[]; elseif nargin==1 content=address; address='收件人邮箱'; object='邮件主题'; elseif nargin==3 else error('参数错误'); end mail='自己的邮箱'; password='邮箱密码'; setpref('Internet','E_mail',mail); % setpref('Internet','SMTP_Server','smtp.gmail.com');% 如果用gmail邮箱,qq邮箱同理 setpref('Internet','SMTP_Server','smtp.163.com'); setpref('Internet','SMTP_Username',mail); setpref('Internet','SMTP_Password',password); props=java.lang.System.getProperties; props.setProperty('mail.smtp.auth','true'); % 开启权限控制 props.setProperty('mail.smtp.socketFactory.class',... 'javax.net.ssl.SSLSocketFactory'); % % 设置邮箱发送服务器端口,这里是465端口 props.setProperty('mail.smtp.socketFactory.port','465'); sendmail(address,object,content); end


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有