使用SMTP发送邮件时出现异常 [英] Getting Exception when sending mail using SMTP

查看:135
本文介绍了使用SMTP发送邮件时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我想使用SMTP客户端发送邮件时,出现错误事务失败.服务器响应为:m1pismtp01-005.prod.mesa1.xxx.net".

我使用了以下代码.

Hi all,

I''m getting the error "Transaction failed. The server response was: m1pismtp01-005.prod.mesa1.xxx.net" when i want to send the mail using the SMTP Client.

I used the below code.

MailMsg            = new MailMessage();
MailMsg.IsBodyHtml = true;

 
TheCredential      = new System.Net.NetworkCredential("xxxxx", "xxxx");

 
MailMsg.From       = new MailAddress("xxxxxx");
MailMsg.Priority   = MailPriority.Normal;

 
SMTPClient = new System.Net.Mail.SmtpClient("xxxxxx", 25);

 
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
{ 
    return true; 
};

 
SMTPClient.UseDefaultCredentials = false;
SMTPClient.Credentials = TheCredential;
SMTPClient.EnableSsl = false;

 
MailMsg.IsBodyHtml = true;
MailMsg.To.Add(To);
MailMsg.Subject = Subject;
string htmlBody = Body;

 
AlternateView htmlView = AlternateView.CreateAlternateViewFromString
                         (htmlBody, 
                          null, 
                          MediaTypeNames.Text.Html);
MailMsg.AlternateViews.Add(htmlView);

 
try
{
    MailMsg.BodyEncoding = System.Text.Encoding.UTF8;
    SMTPClient.Send(MailMsg);
    return "Mail Sent Successfully";
}
catch(Exception ex)
{
}



预先感谢



Thank in advance

推荐答案

最可能也是常见的原因是中继问题,这意味着您要使用的SMTP服务器尚未配置为中继电子邮件.

请注意,这是最佳猜测,因为您尚未提供实际的SMTP错误消息.
The most likely and common reason is a relay issue, meaning the SMTP server you are trying to use has not been configured to relay email.

Note that this is a best guess, since you haven''t provided the actual SMTP error message.


这篇关于使用SMTP发送邮件时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆