使用MailKit从第三方托管提供商连接到邮件服务器



如果我通过第三方托管提供商(例如A2托管(托管ASP.NET Core应用程序,是否可以使用它来发送带有邮件套件的邮件?我尝试了许多不同的事情和客户端。连接只是悬挂并最终引发了例外。ex为null。

这是我的代码:

            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect("mail.mydomain.com", 25, false);
                // Note: since we don't have an OAuth2 token, disable
                // the XOAUTH2 authentication mechanism.
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                // Note: only needed if the SMTP server requires authentication
                client.Authenticate("contact@mydomain.com", "PASSWORD");
                client.Send(message);
                client.Disconnect(true);
            }

事实证明,我的ISP(comcast(阻止了端口25。我的托管公司告诉我,出于这个原因,他们打开了港口2525。我将其更改为2525,它起作用了。如果您遇到类似问题,请联系您的托管公司,并查看他们可能打开的其他端口。

最新更新