Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Net.Mail.SmtpException:发送邮件失败。System.Net.WebException:无法解析远程名称_C#_Asp.net_.net_Asp.net Mvc_Email - Fatal编程技术网

C# System.Net.Mail.SmtpException:发送邮件失败。System.Net.WebException:无法解析远程名称

C# System.Net.Mail.SmtpException:发送邮件失败。System.Net.WebException:无法解析远程名称,c#,asp.net,.net,asp.net-mvc,email,C#,Asp.net,.net,Asp.net Mvc,Email,发送几封邮件后,Web应用程序出现错误: System.Net.Mail.SmtpException:发送邮件失败。System.Net.WebException:无法解析远程名称 当我用我的C.Net代码发送邮件时。 我的应用程序托管在云服务器上,一段时间后出现此错误,当我重新启动应用程序池时,它会再次工作 public void SendMailstring-ToEmailID、string-CCEmailID、string-Subject、string-Body、System.Collec

发送几封邮件后,Web应用程序出现错误: System.Net.Mail.SmtpException:发送邮件失败。System.Net.WebException:无法解析远程名称 当我用我的C.Net代码发送邮件时。 我的应用程序托管在云服务器上,一段时间后出现此错误,当我重新启动应用程序池时,它会再次工作

public void SendMailstring-ToEmailID、string-CCEmailID、string-Subject、string-Body、System.Collections.ArrayList\u-Attachments=null MailMessage mm=null; SmtpClient smtp=null

        try
        {
            string strPath = "";
            string strReplacepath = "";

            if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null)
            {
                strPath = System.Web.HttpContext.Current.Request.Url.ToString();
                strReplacepath = System.Web.HttpContext.Current.Request.Url.PathAndQuery;
                strPath = strPath.Replace(strReplacepath, "/");
            }
            else if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["DomainName"]))
            {
                strPath = System.Configuration.ConfigurationManager.AppSettings["DomainName"];
            }

            Body = Body.Replace("@@LOGO@@", GetImage(strPath, "Content/images/logo.jpg"));
            Body = Body.ToString().Replace("@@Year@@", DateTime.Now.Year.ToString());

            mm = new MailMessage();
            mm.Subject = Subject;
            mm.Body = Body;
            mm.IsBodyHtml = true;
            mm.To.Add(ToEmailID);

            if (!string.IsNullOrEmpty(CCEmailID))
                mm.CC.Add(CCEmailID);

            mm.Bcc.Add("My Email Address");

            if (_Attachments != null && _Attachments.Count > 0)
            {
                for (int i = 0; i < _Attachments.Count; i++)
                {
                    mm.Attachments.Add((Attachment)_Attachments[i]);
                }
            }
            smtp = new SmtpClient();
            smtp.EnableSsl = true;
            smtp.Timeout = 25000;

            smtp.Send(mm);

        }
        finally
        {
            foreach (Attachment attachment in mm.Attachments)
            {
                attachment.Dispose();
            }

            if (_Attachments != null)
                _Attachments.Clear();

            if (mm != null)
                mm.Dispose();

            if (smtp != null)
                smtp.Dispose();

            mm = null;
            smtp = null;
            _Attachments = null;

        }
}


我使用了smtp.gmail.com,端口为587。

DNS错误?不管怎样,你试了什么?你调试了代码吗?嗨,克里斯,我添加了我的邮件发送功能代码。嗨,纳迪姆,我在本地IIS中检查了我的应用程序,然后将我的代码部署到服务器回收应用程序池并进行测试,它工作了一段时间,过了一段时间停止发送邮件。不,我无法在服务器上调试我的代码。