0

我有以下发送电子邮件的代码。它在本地运行良好,但是在我的 hostgator windows 服务器上部署时出现以下异常。

我想我需要在 gmail somwhow 中将我的服务器 IP 列入白名单,但我该怎么做呢?

代码:

            var fromAddress = new MailAddress("XXX@gmail.com", "From XXX");
            var toAddress = new MailAddress("XXX@gmail.com", "To XXX");
            const string fromPassword = "XXX";
            const string subject = "Email Headline";
            string body = "Email Body";

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
            {
                smtp.Send(message);
            }

例外:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 173.194.77.109:587
4

1 回答 1

0

我对 Hostgator 也有同样的问题,我尝试在许多电子邮件服务提供商之间切换。但是 HG 阻止了他们的 SMTP 套接字。

现在我使用他们的 REST API从MailGun发送邮件。使用任何事务性电子邮件服务 API。您将在 NuGet 中获得MailGunMandrill的 .Net 客户端。或者您可以使用RestSharp调用他们的 API

于 2014-01-20T09:46:17.170 回答