这是我写的代码
MailMessage msg = new MailMessage();
msg.From = new MailAddress("noreply@xxx.com", "My site Registratration");
msg.To.Add(new MailAddress(email, name, System.Text.Encoding.UTF8));
msg.Subject = "xxx- Register Account";
msg.IsBodyHtml = true;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.None;
msg.Priority = MailPriority.Normal;
StreamReader sr = new StreamReader(Server.MapPath("~/ActiveMail.htm"));
string temp = sr.ReadToEnd();
temp = temp.Replace("[###Name###]", name).Replace("[###Url###]", key);
msg.Body = temp;
SmtpClient smtp = new SmtpClient("mail.xxx.com");
System.Net.NetworkCredential perm = new System.Net.NetworkCredential("noreply@xxx.com", "My host email's password");
smtp.Credentials = perm;
smtp.Send(msg);
似乎它必须工作,但在 smtp.Send(msg) 部分我收到电子邮件无法发送的错误。有没有人可以帮助我?非常感谢
堆栈跟踪:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 110.4.46.160:25]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +225
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279
[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +6054548
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +314
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +322
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +146
System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
System.Net.Mail.SmtpClient.GetConnection() +50
System.Net.Mail.SmtpClient.Send(MailMessage message) +1484
[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1811
NewUser.SendEmail(String email, String name, String key) in g:\Programming\Projects\xxx\xxxWebsite(Mysql)\NewUser.aspx.cs:99
NewUser.SignupBtn_Click(Object sender, EventArgs e) in g:\Programming\Projects\xxx\xxxWebsite(Mysql)\NewUser.aspx.cs:69
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563