使用Asp,NET发送电子邮件时,传输无法连接到服务器 [英] Transport failed to connect to the server when sending an Email using Asp,NET
本文介绍了使用Asp,NET发送电子邮件时,传输无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我使用System.Net.Mail从我的Web应用程序发送电子邮件,它在IIS 6.0中工作得非常好,但我已经转移了我的服务器到IIS7它无法发送邮件。我收到错误,因为传输无法连接到服务器。
System.Net.Mail.MailMessage msg = new MailMessage();
System.Net.Mail.SmtpClient client = new SmtpClient();
foreach (string addto in txtTo.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
msg.To.Add(txtTo.Text);
}
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(xxx@xxx.com, xxxxxx));
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.EnableSsl = true;
client.Host = 'mail.gmail.com';
client.Port =587;
msg.From = new MailAddress(ViewState["Usname"].ToString());
UserID = Convert.ToInt32(Session["UserId"]);
msg.Subject = txtSubject.Text;
string Subject = msg.Subject;
msg.IsBodyHtml = true;
msg.Body = txtMBody.Content;
Size = msg.Body.Length.ToString();
client.Send(msg);
上面提到的代码是发送邮件的示例代码,
我已配置IIS7 SMTP电子邮件服务器设置
任何人都可以帮忙解决这个问题,
the above mentioned code is sample code to send mails ,
And i have configured IIS7 SMTP Email Server Settings
can any one help to sort out this pls,
推荐答案
我认为client.Host
应为smtp.gmail.com
。
请参阅我之前的回答 - 从asp.net发送电子邮件到gmail [ ^ ]。
这篇关于使用Asp,NET发送电子邮件时,传输无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文