我遇到了“拒绝中继访问”错误,但是我可以将我的帐户与某些电子邮件程序关联。

我的代码:

        SmtpClient smtpClient = new SmtpClient();
        NetworkCredential basicCredential =
            new NetworkCredential("[email protected]", "xxx");
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("[email protected]");

        smtpClient.Host = "mail.xx.com";
        smtpClient.Port = 587;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = basicCredential;

        message.From = fromAddress;
        message.Subject = subject;
        message.IsBodyHtml = true;
        message.Body = body;
        message.To.Add("[email protected]");

        try
        {
            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //Relay access denied...
        }

有人知道原因吗?

最佳答案

由于您的smtp主机端口是587,我认为您应该在调用其Send方法之前将smtpClient.EnableSsl设置为true。

关于c# - 中继访问被拒绝5.7.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20454651/

10-11 02:04