SMTP 给出错误:- 邮箱不可用。服务器响应是:访问被拒绝 - HELO 名称无效(请参阅 RFC2821 4.1.1.1)

问题描述 投票:0回答:1

我正在远程计算机上运行一个 aspx 应用程序,该应用程序运行一个负责通过 SMTP 发送电子邮件的服务。它无法发送电子邮件并给出以下错误

异常类型:System.Net.Mail.SmtpException 异常消息:邮箱不可用。服务器响应是:访问被拒绝 - HELO 名称无效(请参阅 RFC2821 4.1.1.1)

相反,我在同一台远程计算机上创建了一个控制台应用程序,并编写了一个简单的程序来通过相同的 SMTP 详细信息发送电子邮件,并且它工作正常,以下是其工作代码

class Program
{
    static void Main(string[] args)
    {
        MailAddress to = new MailAddress("*********");

        MailAddress from = new MailAddress("******"); // Note :- from and user inside N/w Credentails is same


        MailMessage mail = new MailMessage(from, to);
       
        mail.Subject = "TESTING PLEASE IGNORE";
        
        mail.Body = "TESTING MAIL BODY";

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "*********";
        smtp.Port = 587;

        smtp.Credentials = new NetworkCredential(
            "********", "**********");
        smtp.EnableSsl = true;
        Console.WriteLine("Sending email...");
        smtp.Send(mail);

    }
}

这是不起作用的应用程序代码。

string id = "";
        string cc = "";
        string bcc = "";
        string to = "";
        MailMessage objMailMessage = new MailMessage();
        
        SmtpClient SmtpMail = new SmtpClient();
        SmtpMail.Host = "****"; 
        
        SmtpMail.Credentials = new System.Net.NetworkCredential("*********", "*************"); 
        SmtpMail.EnableSsl = true; 
        
        SmtpMail.Port = 587; 
        if (req != null)
        {
            Log("External email request queued internally: " + req.OuterXml);
            try
            {
                id = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["id"].Value;
                to = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["to"].Value;
                cc = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["cc"].Value;
                bcc = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["bcc"].Value;
        
                string from = "*********************";
                string subject = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["subject"].Value;
                string body = req.SelectSingleNode("/QuotationServer/EmailRequest").Attributes["body"].Value;
        
                objMailMessage.To.Add(new MailAddress(to.Replace(";",",")));

                if (cc.Trim() != "")
                {
                    objMailMessage.CC.Add(new MailAddress(cc.Replace(";", ",")));
                }
                if (bcc.Trim() != "")
                {
                    objMailMessage.Bcc.Add(new MailAddress(bcc.Replace(";", ",")));
                }
                objMailMessage.From = new MailAddress(from);
                objMailMessage.Subject = subject;
                objMailMessage.Body = body;
        


                if (req.SelectSingleNode("/QuotationServer/EmailRequest/Attachment").Attributes["path"] != null)
                {
                    string pdffile = req.SelectSingleNode("/QuotationServer/EmailRequest/Attachment").Attributes["path"].Value.ToString();
                    objMailMessage.Attachments.Add(new System.Net.Mail.Attachment(pdffile));
                }

                Log("server name: " + m_SMTPServer + ", password: " + m_SMTPpassword + ", user and port: " + m_SMTPuser + ", " + m_SMTPport + "");

               

                SmtpMail.Send(objMailMessage);
                }
                }

我尝试更改 SMTP 设置,启用 SSL 将默认凭据设置为 false 等,但没有任何效果。

可能是什么问题?

编辑(2023年10月26日)

问题似乎出在 .Net Framework 版本上

它在 4.6.1 上运行良好,但由于某种原因不能在 2.0 上运行?

c# asp.net smtp windows-services smtpexception
1个回答
0
投票

问题是当 SmtpClient 使用您的 aspx Web 服务器的主机名发送 HELO 命令时,该主机名无效。

这与 SSL 设置、邮件服务器的主机名或任何发件人/收件人/抄送地址无关。

© www.soinside.com 2019 - 2024. All rights reserved.