SMTP host issue with sendmail() in MATLAB r2013a
1 次查看(过去 30 天)
显示 更早的评论
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)
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!