当我尝试使用C#代码在远程服务器上使用smtp发送邮件时,它会抛出此错误.Plz帮助我。谢谢提前 [英] When I m trying to send mail using smtp on remote server using C# code then it is throwing this error.Plz help me out.Thanks in advance
问题描述
连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应74.125.200.108:587
描述:未处理的异常在执行当前Web请求期间发生。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Net.Sockets.SocketException:连接尝试失败因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应74.125.200.108:587
源错误:< br $>
第138行:
第139行:smtp.EnableSsl = true;
第140行:smtp.Send(mail);
第141行:ClientScript.RegisterStartupScript(GetType(),alert,alert('Email Sent Successfully。');,true);
第142行:}
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.200.108:587
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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.200.108:587
Source Error:
Line 138:
Line 139: smtp.EnableSsl = true;
Line 140: smtp.Send(mail);
Line 141: ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email Sent Successfully.');", true);
Line 142: }
推荐答案
尝试下面的代码使用gmail发送邮件。
Try below code to send mail using gmail.
public string senMail(string emailId, string MailBody)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); //Gmail SMTP Client
mail.From = new MailAddress("abc@gmail.com"); //Sender email ID
mail.To.Add(emailId);
mail.Subject = "Email Subject";
mail.Body = mailBody;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc152wte.7"); //Sender email and password (login credential)
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return "";
}
这篇关于当我尝试使用C#代码在远程服务器上使用smtp发送邮件时,它会抛出此错误.Plz帮助我。谢谢提前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!