MATLAB: Do I get a “Permission denied” when I use SENDMAIL in MATLAB (R2013b) PreRelease

ipv4ipv6MATLABsendmail

I have a script that I have been using with the SENDMAIL function. The script works fine in MATLAB (R2010a) and (R2013a). However, in R2013b PreRelease, I obtain the following error:
Error using sendmail (line 168)
Could not connect to SMTP host: mail.myHost.com, port: 25;
Permission denied: connect
Or I see the following error:
Error using sendmail (line 172)
Could not connect to SMTP host: mail.myHost.com, port: 25;
Network is unreachable: connect
This happens even if I have the same SETPREF and email address as in R2010a and R2013a:
>> setpref('Internet', 'SMTP_Server', 'mail.myHost.com');

Best Answer

It seems that the error is due to a Java Socket Exception, triggered by an interaction between Java 7 and an IPv4 connection.
The Java Development Toolkit 7 (JDK) supports IPv6 on Windows machines. When you try to connect to an IPv4 address, JDK7 will use an IPv6 address that was mapped to an IPv4.
To remedy this issue, you would need to use the following flag in the java run time:
-Djava.net.preferIPv4Stack=true
One method to achieve this:
1) Create "java.opts" file in matlabroot\bin\arch folder.
2) Write the following line in "java.opts" file:
-Djava.net.preferIPv4Stack=true
3) Restart MATLAB.
Here is a relevant external link that discusses this issue: