SMTP host issue with sendmail() in MATLAB r2013a

조회 수: 1 (최근 30일)
Isma
Isma 2015년 10월 16일
Hi all,
While attempting to send email to other accounts than Yahoo and Gmail, it aborts as I experience an authentification issue. Does anyone know a specific reason and a way around to overcome this matter?
Error using sendmail (line 172)
Could not connect to SMTP host: mail.xxxx.com, port: 25;
Connection timed out: connect
end
see below the code:
clc
% Define these variables appropriately:
mail = 'myemail@xx.com'; %my email address
recipient='recipmail@xx.com';
server='mail.xxxx.com'; % <> from 'smtp.mail.xxxx.com' that is not recognised at all
posdat=char(inputdlg('Enter date (yyyymmdd):'));
fid='C:\local\';
file1='\out';
file2='\dist.pdf';
attach1=cellstr(strcat(fid,posdat,file1));
attach2=cellstr(strcat(fid,posdat,file2));
attach = [attach1 attach2];
%smtp.mail.yahoo.com = Yahoo Server
%smtp.gmail.com= Gmail Server
password = 'xxxx'; %my pass
setpref('Internet','SMTP_Server',server);
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','25'); % <> from port '465'
% Send the email. Note that the first input is the address you are sending the email to
sendmail(recipient,'TEST','test files are attached,',attach)
I hoped the post found on NET.addAssembly could have helped as I've also tried:
clc
user='myemail@xx.com';
pass='xxx';
recipient='recipmail@xx.com';
NET.addAssembly('System.Net')
import System.Net.Mail.*;
mySmtpClient = SmtpClient('mail.xxx.com');
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = System.Net.NetworkCredential(user, pass);
from = MailAddress(user);
to = MailAddress(recipient);
myMail = MailMessage(from, to);
myMail.Subject = ['Test message: ' datestr(now)];
myMail.SubjectEncoding = System.Text.Encoding.UTF8;
myMail.Body = '<b>Test Mail</b><br>using <b>HTML</b>';
myMail.BodyEncoding = System.Text.Encoding.UTF8;
myMail.IsBodyHtml = true;
mySmtpClient.Send(myMail)
which ends up with:
Message: Failure sending mail.
Source: System
HelpLink:
Thus, any relevant feedback would be much appreciated. Best,

답변 (0개)

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by