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

8 views (last 30 days)
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?

Answers (1)

Varun Bhaskar
Varun Bhaskar on 10 Aug 2015
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 Comment
joeDiHare
joeDiHare on 10 Aug 2015
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!