string MyPsd = "nanfei2010";
string MyEmail = "[email protected]";
MailMessage MMsg = new MailMessage(); MMsg.Subject = "this is a test mail"; MMsg.From = new MailAddress("[email protected]"); MMsg.To.Add(new MailAddress("[email protected]")); //MMsg.IsBodyHtml = true;//这里启用IsBodyHtml是为了支持内容中的Html。 MMsg.Body = "this is a test mail!!"; SmtpClient SClient = new SmtpClient();
SClient.Host = "smtp.gmail.com";//google的smtp地址
SClient.Port = 587;//google的smtp端口 SClient.EnableSsl = true; SClient.Credentials = new NetworkCredential(MyEmail, MyPsd);
SClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
SClient.Send(MMsg);
Response.Write("邮件已经发送成功");
}
catch (Exception ex)
{ Response.Write(ex.ToString());
}
代码在别人机子上运行没有错误.发送成功
在我自己机子上运行报这样的错误
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................(省略)有人说是Framework的问题....在线求教!
string MyEmail = "[email protected]";
MailMessage MMsg = new MailMessage(); MMsg.Subject = "this is a test mail"; MMsg.From = new MailAddress("[email protected]"); MMsg.To.Add(new MailAddress("[email protected]")); //MMsg.IsBodyHtml = true;//这里启用IsBodyHtml是为了支持内容中的Html。 MMsg.Body = "this is a test mail!!"; SmtpClient SClient = new SmtpClient();
SClient.Host = "smtp.gmail.com";//google的smtp地址
SClient.Port = 587;//google的smtp端口 SClient.EnableSsl = true; SClient.Credentials = new NetworkCredential(MyEmail, MyPsd);
SClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
SClient.Send(MMsg);
Response.Write("邮件已经发送成功");
}
catch (Exception ex)
{ Response.Write(ex.ToString());
}
代码在别人机子上运行没有错误.发送成功
在我自己机子上运行报这样的错误
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................(省略)有人说是Framework的问题....在线求教!
public static int SandMail(string FriendMail)
{
int result = 0;
string YueSaiBody = "测试内容";//正文 try
{
SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential( "[email protected]","nanfei2010");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]"); //接收人
mail.Subject = "测试";
mail.Body = "测试";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal; smtp.Send(mail);
result = 1;
}
catch (Exception ex)
{
result = 2;
} return result;
}
http://www.cnblogs.com/hotsoho.net/archive/2008/01/29/1206561.html
貌似不是SLL同道的问题吧?
试了下163的
System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at 提交.Button1_Click(Object sender, EventArgs e) in d:\project\Test\提交.aspx.cs:line 90