IOException with sendmail: Connection reset by peer: socket write error

5 ビュー (過去 30 日間)
joeDiHare
joeDiHare 2015 年 8 月 9 日
コメント済み: joeDiHare 2015 年 8 月 10 日
I get the following error when using sendmail.m (R2010b):
IOException while sending message:
Connection reset by peer: socket wrtie error
This does not happen all the times, but very frequently when I try to send consecutive emails through an automated script.
Example code:
% send 3 email with attachments
for email_counter=1:3
recipient = 'example@gmail.com';
message = [' ' 10 'Docs attached'];
subject = 'docs';
sender = 'example@gmail.com';
psswd = 'password';
attachments = {'doc1.pdf', 'doc2'};
setpref('Internet','E_mail',sender);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',sender);
setpref('Internet','SMTP_Password',psswd);
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');
sendmail(recipient, subject, message, attachments);
end
Typically, by email number 2 the script would crash and throw an exception.
Any help?

回答 (1 件)

Varun Bhaskar
Varun Bhaskar 2015 年 8 月 10 日
Hello,
Since you are observing the above error only when you call the ‘sendmail’ function in a loop, try the following steps:
1) Disable anti-virus.
2) Include a pause of 5s after the ‘sendmail’ call in each iteration of the loop to ensure that one call is completed before the next one is invoked in the following manner:
pause(5)
  1 件のコメント
joeDiHare
joeDiHare 2015 年 8 月 10 日
Hi Varun, thanks for your reply.
The problem occurs also, sometimes, for single instances of sendmail.
I had tried to use the pause command before without luck.
Instead, disabling the anti-virus seems to reduce the problem. I wonder why?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by