简体   繁体   English

将白名单IP gmail smtp-System.Net.Mail.SmtpException:发送邮件失败

[英]Whitelist IP gmail smtp - System.Net.Mail.SmtpException: Failure sending mail

I have the following code that sends an email. 我有以下代码发送电子邮件。 It works fine locally but when deploying on my hostgator windows server I get the exception below. 它在本地运行良好,但是在hostgator Windows服务器上部署时,出现以下异常。

I would guess that I need to whitelist my servers IP in gmail somwhow but how do I do that? 我想我需要在gmail somwhow中将我的服务器IP列入白名单,但是我该怎么做呢?

Code: 码:

            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);
            }

Exception: 例外:

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

I had the same problem with Hostgator , and I tried switching between many email service providers. 我在Hostgator上遇到了同样的问题,我尝试在许多电子邮件服务提供商之间进行切换。 But HG was blocking their SMTP sockets. 但是HG阻止了他们的SMTP套接字。

Now I'm sending mails from MailGun using their REST API. 现在,我使用他们的REST API从MailGun发送邮件。 Use any Transactional Email Service API . 使用任何交易电子邮件服务API You'll get .Net clients for MailGun and Mandrill in NuGet. 您将在NuGet中获得MailGunMandrill的 .Net客户端。 Or you can call their API using RestSharp 或者您可以使用RestSharp调用其API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Net.Mail.SmtpException {“发送电子邮件失败。”} - System.Net.Mail.SmtpException {“Failure Sending Email.”} System.Net.Mail.SmtpException:发送邮件失败。 无法从传输连接中读取数据 - System.Net.Mail.SmtpException: Failure sending mail. Unable to read data from the transport connection 出现错误:-System.net.mail.SmtpException - Getting error:-System.net.mail.SmtpException System.Net.Mail.SmtpException:发送邮件失败。 无法建立连接,因为目标计算机主动拒绝它127.0.0.1:25 - System.Net.Mail.SmtpException: Failure sending mail. No connection could be made because the target machine actively refused it 127.0.0.1:25 System.Net.Mail.SmtpException:邮箱不可用 - System.Net.Mail.SmtpException: Mailbox unavailable 尝试在System.dll中使用smtp'System.Net.Mail.SmtpException'发送电子邮件时出错 - error when trying to send email using smtp 'System.Net.Mail.SmtpException' in System.dll System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证 - System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated system.net.mail.smtpException:无法连接到远程服务器? - system.net.mail.smtpException :Unable to connect to the remote server? System.Net.Mail.SmtpException:该地址具有无效的主机名 - System.Net.Mail.SmtpException: The address has an invalid host name 如何修复 System.Net.Mail.SmtpException - How Can I Fix System.Net.Mail.SmtpException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM