本地发送一切正常,能够发送成功!
上传到服务器上后就出现了这种问题!(PS:服务器只是租的一个虚拟空间。)
异常信息如下:
(高手速来帮小弟看看!谢谢!)System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 74.125.53.109:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at SendMail.ProcessRequest(HttpContext context)
上传到服务器上后就出现了这种问题!(PS:服务器只是租的一个虚拟空间。)
异常信息如下:
(高手速来帮小弟看看!谢谢!)System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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 74.125.53.109:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at SendMail.ProcessRequest(HttpContext context)
string strMailFromPass = ConfigurationManager.AppSettings["MailFromPass"];
string strSmtpServer = ConfigurationManager.AppSettings["SmtpServer"];
SmtpClient client = new SmtpClient(strSmtpServer); //邮件发送类
client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(strMailFrom, strMailFromPass); client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network; string strSubject = string.Empty;
System.Text.StringBuilder strBody = new System.Text.StringBuilder(); strBody.Append("From: " + context.Request["frm_name"] + " <br />");
strBody.Append("EMail: " + context.Request["frm_email"] + " <br />");
//strBody.Append("Subject: " + context.Request["frm_subject"] + " <br />");
strSubject = context.Request["frm_subject"];
strBody.Append("Message: " + context.Request["frm_message"] + " <br />"); MailMessage message = null;
message = new MailMessage(strMailFrom, strMailTo, strSubject, strBody.ToString()); message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
try
{
client.Send(message);
}
catch (Exception ex)
{
context.Response.Write(ex.ToString());
}
这里面有一个,参考参考。
引用 5 楼 vincent_void 的回复:帮博哥顶贴啊!
人气,,人气呢?操,别发这种没营养的文字好吧
[/Quote
蛋疼。
/// 用于发邮件的方法
/// </summary>
/// <param name="username">显示的发件人名称</param>
/// <param name="subject">显示的主题名称</param>
/// <param name="toname">收件人邮箱号码</param>
/// <param name="body">内容</param>
public static void SendMessage(string username, string subject, string toname, string body)
{
MailAddress from = new MailAddress("[email protected]", username);
MailMessage mail = new MailMessage();
mail.Subject = subject;
mail.From = from;
//设置邮件的收件人
string address = "";
string displayName = ""; string[] mailNames = (toname + ";").Split(';');
foreach (string name in mailNames)
{
if (name != string.Empty)
{
if (name.IndexOf('<') > 0)
{
displayName = name.Substring(0, name.IndexOf('<'));
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
else
{
displayName = string.Empty;
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
mail.To.Add(new MailAddress(address, displayName));
}
}
//设置邮件的内容
mail.Body = body;
//设置邮件的格式
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
//设置邮件的发送级别
mail.Priority = MailPriority.Normal;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient client = new SmtpClient();
//设置用于 SMTP 事务的主机的名称,填IP地址也可以了
client.Host = "smtp.163.com";
//设置用于 SMTP 事务的端口,默认的是 25
//client.Port = 25;
client.UseDefaultCredentials = false;
//这里才是真正的邮箱登陆名和密码,比如我的邮箱地址是 hbgx@hotmail, 我的用户名为 hbgx ,我的密码是 xgbh
client.Credentials = new System.Net.NetworkCredential("邮箱帐号", "密码");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//都定义完了,正式发送了,很是简单吧!
client.Send(mail);
}
http://blog.csdn.net/keymo_
其中的“学习笔记37”