尝试以其访问权限{serverIp}禁止的方式访问套接字:587

时间:2018-05-31 17:33:48

标签: .net smtpclient

我的网站托管在一个不允许打开端口587的网络服务器上,因此我无法使用此代码发送邮件:

        string mailAddress = ConfigurationManager.AppSettings["mailAddress"];
        string displayName = ConfigurationManager.AppSettings["displayName"];
        string password = ConfigurationManager.AppSettings["mailPassword"];
        string smtpHost = ConfigurationManager.AppSettings["smtpHost"];
        int smtpPort = int.Parse(ConfigurationManager.AppSettings["smtpPort"]);

        using (SmtpClient smtp = new SmtpClient(smtpHost, smtpPort)
        {
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(mailAddress, password)
        })
        {
            message.From = new MailAddress(mailAddress, displayName);
            smtp.Send(message);
        }

我一直收到这条消息: “尝试以其访问权限{serverIp}禁止的方式访问套接字:587”

有另一种方式(同样简单)发送邮件吗?

0 个答案:

没有答案