交易失败。服务器响应为:5.7.1 <xyz@xyz.com>:拒绝中继访问</xyz@xyz.com>

时间:2015-03-23 00:15:43

标签: c# .net email smtpclient

我正在使用VS 2013 Ultimate Update 3并在IIS Express上运行我的应用程序(&#34; http://localhost:2689/&#34;)。我的应用程序用于发送电子邮件一切都工作正常,但由于某种原因,我不得不安装VS 2013 Ultimate Update 2,从那时起电子邮件功能无法正常工作。我再次安装了VS 2013 Ultimate Update 3但仍然无法使用电子邮件。我还在我的发布服务器上部署了相同的代码,电子邮件工作正常,但在Visual Studio中的本地IIS Express上却没有。以下是我的代码......

public void SendEmail(string ToMailAddress, string CCMailAddress, string MsgSubject, string MsgBody)
    {
        try
        {
            string FromMailID = System.Configuration.ConfigurationManager.AppSettings["FromMail"].ToString();
            string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString();
            string Host = System.Configuration.ConfigurationManager.AppSettings["Host"].ToString();
            string Port = System.Configuration.ConfigurationManager.AppSettings["Port"].ToString();

            using (MailMessage objMailMessage = new MailMessage())
            {
                objMailMessage.From = new MailAddress(FromMailID);

                string[] toMailAddresses = ToMailAddress.Split(',');
                foreach (string emailAddress in toMailAddresses)
                {
                    objMailMessage.To.Add(new MailAddress(emailAddress));
                }

                string[] ccMailAddresses = CCMailAddress.Split(',');
                foreach (string emailAddress in ccMailAddresses)
                {
                    objMailMessage.CC.Add(new MailAddress(emailAddress));
                }

                objMailMessage.Subject = MsgSubject;
                objMailMessage.Body = MsgBody;
                objMailMessage.IsBodyHtml = true;
                objMailMessage.Priority = MailPriority.High;
                objMailMessage.HeadersEncoding = System.Text.Encoding.UTF8;

                SmtpClient smtp = new SmtpClient();
                smtp.Host = Host;
                NetworkCredential NetworkCred = new NetworkCredential(FromMailID, Password);
                smtp.Credentials = NetworkCred;
                smtp.Port = Convert.ToInt32(Port);
                smtp.DeliveryFormat = SmtpDeliveryFormat.International;

                smtp.UseDefaultCredentials = true;

                // To be used in case SSL is required...
                //smtp.EnableSsl = true;
                //ServicePointManager.ServerCertificateValidationCallback = 
                //    delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

                smtp.Send(objMailMessage);
            }
        }
        catch(Exception ex)
        {
            throw ex;
        }
    }

请在这里建议有什么问题...请帮助......

0 个答案:

没有答案