通过MATLAB发送电子邮件

时间:2014-10-22 14:50:45

标签: matlab email sendmail

我需要通过MATLAB发送电子邮件,我已经阅读了sendmail的说明和这里的许多答案。我已经尝试了3个电子邮件提供商,但我无法真正使用其中任何一个:

  • Gmail:我只能在停用我的病毒时发送电子邮件

  • Hotmail和Yahoo:使用sendmail时出错(第171行)异常阅读响应;连接重置

  • Hotmail和Yahoo(杀毒软件关闭):使用sendmail时出错(第171行)异常阅读响应;无法识别的SSL消息,明文连接?


这是代码

mail = 'user@service.com'; 
password = 'passwordgoeshere';
setpref('Internet','SMTP_Server','smtp.server.com');
setpref('Internet','E_mail',mail);
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');
props.setProperty('mail.smtp.socketFactory.port',port);
sendmail(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')

我使用了以下变量:

  • Gmail:smtp.gmail.com port = 465

  • Hotmail:smtp.live.com port = 465 and port = 587

  • Yahoo:smtp.mail.yahoo.com port = 587


由于停用防病毒软件不是一个好选择,任何人都可以帮我解决这个问题吗?

谢谢

4 个答案:

答案 0 :(得分:0)

Linux上的另一种方法是运行发送电子邮件的命令行。

unix('echo "message" | mail -s "subject" example@gmail.com');

Windows应该有类似的方法。

答案 1 :(得分:0)

适用于Gmail

更改您的设置,以便让安全性较低的应用访问您的帐户。转到“我的帐户”中的“安全性较低的应用”部分。 在“访问安全性较低的应用”旁边,选择启用。 (Google Apps用户请注意:如果您的管理员已锁定不太安全的应用帐户访问权限,则会隐藏此设置。)

在Matlab中:

mail = 'user@otherdomain.com';
password = 'myPassword';

% Set up the preferences
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);

% The following is necessary only if you are using GMail as
% your SMTP 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');

subject = 'Test subject';
message = 'Test message';

sendmail(mail,subject,message)

答案 2 :(得分:0)

简单声明

@Override
public Collection<Connection> getConnectionsFrom(Station station) {
    Map<Station, Connection> stationConnectionFrom = new HashMap<Station, Connection>();
    return Collections.singletonList((stationConnectionFrom.get(station));
}

删除扩展 @ service.com 以获取变量mail = 'user';

答案 3 :(得分:0)

您可以阅读https://support.kaspersky.com/4175并获取有关AntiVirus软件设置的IDEA,然后您可以尝试发送电子邮件。

在这里,我将使用 Gmail 并使用端口 587 来解释发送电子邮件。

  

注意:我会在获得Hotmail&amp; amp;的解决方案后更新答案雅虎。

我尝试过以多种方式发送电子邮件,我在 PDF 中提到了Sending email(GMAIL) using MATLAB公开提供的电子邮件。

Sending email(GMAIL) using MATLAB PDF 中,您将看到以下内容以及优秀的示例代码和图片。

  1. 向单个用户发送电子邮件 - (仅限Header消息)
  2. 向多个用户发送电子邮件 - (使用标题和正文消息)
  3. 向多个用户发送电子邮件 - (使用标题,正文消息和系统中的1个jpg文件)
  4. 向多个用户发送电子邮件 - (包含标题,正文消息和2个附件.jpg和.pdf)
  5. 感谢。

相关问题