获得一个ASP错误:邮箱不可用。服务器响应为:拒绝访问 - 无效HELO域名(见RFC2821 4.1.1.1) [英] Getting a ASP Error: Mailbox unavailable. The server response was: Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

查看:1537
本文介绍了获得一个ASP错误:邮箱不可用。服务器响应为:拒绝访问 - 无效HELO域名(见RFC2821 4.1.1.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误,我知道我的凭据是正确的。有任何想法吗?这是一个Windows服务器上,但是我想用HostGator的SMTP设置我的电子邮件。这是当我提出一个简单的联系表单会发生什么。

错误:
信箱不可用。服务器响应为:拒绝访问 - 无效HELO域名(见RFC2821 4.1.1.1)

说明:在当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

异常详细信息:System.Net.Mail.SmtpException:邮箱不可用。服务器响应为:拒绝访问 - 无效HELO域名(见RFC2821 4.1.1.1)

源错误行61:

  59号线:
60号线:SmtpClient SMTP =新SmtpClient(SMTPSERVER,SMTPPORT);
第61行:smtp.Credentials =新的NetworkCredential(SMTPUserId,SMTPPassword);
行62:smtp.Send(邮件);
63号线:}

源文件:\\网站\\客户端\\报告\\ ContactUs.aspx.cs行:61

=============================================== ==========================

我的资料来源$ C ​​$ C:

 保护无效ImageButton1_Click(对象发件人,ImageClickEventArgs E)
    {
        字符串名称= txtFirstName.Text ++ txtLastName.Text;
        字符串clientID的=会话[客户ID]的ToString()。
        字符串消息= txtMessage.Text;
        字符串email = txtEmail.Text;
        串公司= txtCompany.Text;
        字符串手机= txtPhone.Text;        SMTPMailHelper.SendMail(电子邮件,myemail@domain.com,从客户联系:+ + clientID的:+姓名++的公司,消息);
    }

我漏掉了脚本,我以前不物质如条件语句。
,这是它的其余部分:

 公共类SMTPMailHelper
{
    常量字符串SMTPSERVER =mail.mydomain.com;
    常量字符串SMTPUserId =myemail@mydomain.com;
    常量字符串SMTPPassword =MyPasswordHidden;
    const int的SMTPPORT = 25;    公共静态无效的SendMail(字符串sendFrom,串SENDTO,弦乐主题,绳体)
    {
        MailAddress FROMADDRESS =新的MailAddress(sendFrom);
        MailAddress的toAddress =新的MailAddress(SENDTO);
        邮件MAILMESSAGE新= MAILMESSAGE();
        mail.From = FROMADDRESS;
        mail.To.Add(的toAddress);
        mail.Subject =主体;        如果(body.ToLower()包含(< HTML和GT;))
        {
            mail.IsBodyHtml = TRUE;
        }        mail.Body =身体;
        SmtpClient SMTP =新SmtpClient(SMTPSERVER,SMTPPORT);
        smtp.Credentials =新的NetworkCredential(SMTPUserId,SMTPPassword);
        smtp.Send(邮件);
    }
}


解决方案

您所遇到的问题是,SmtpClient是发出 HELO 与你的服务器是拒绝SMTP主机名/域串EHLO 命令。

我显然无法知道微软的SmtpClient实现的内在逻辑,但我怀疑你可能是一个NAT这意味着SmtpClient不能解决你的机器世界可见完全合格的域名后面。它只能解决您的计算机的FQDN的校内网上(与现实,它可能甚至不能它解析为一个实际的FQDN,它可能有满足于内部网络的IP地址)。

所以... SmtpClient大概是发出类似 EHLO [192.168.1.100] (或任何你的本地IP是),且服务器拒绝它,因为这是不IP地址,它是从接收包。

你需要做的就是通过访问这样的网站 HTTP找到你的外部IP地址是什么://www.whatismyip .COM / 或利用这样的网站 http://www.displaymyhostname.com/

要说明什么我说的,这里有一个小的演示程序:

 使用系统;
使用System.Net;
使用System.Linq的;
使用的System.Net.Sockets;
使用System.Collections.Generic;
使用System.Net.NetworkInformation;命名空间LocalHostName
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            变种ipAddresses = Dns.GetHostAddresses(www.google.com);
            Socket套接字;            的for(int i = 0; I< ipAddresses.Length;我++){
                插座=新的Socket(ipAddresses [I] .AddressFamily,SocketType.Stream,ProtocolType.Tcp);                尝试{
                    socket.Connect(ipAddresses [I],80);
                    Console.WriteLine(LocalEndPoint:{0},socket.LocalEndPoint);
                    打破;
                } {抓
                    socket.Dispose();
                    插座= NULL;                    如果第(i + 1 == ipAddresses.Length)
                        扔;
                }
            }            到Console.ReadLine();
        }
    }
}

不管IP地址,它打印出很可能是SmtpClient在使用它的一个 HELO / EHLO 命令。

坏消息是,有没有办法解决这个问题,System.Net.Mail.SmtpClient。

好消息是,我对我的汽车保险节省15%......呃,我是说,我已经写了叫我自己的电子邮件库的 MimeKit MailKit 可以的工作解决这个问题。

一些更多的好消息是,你可以轻松地投你System.Net.Mail.MailMessage对象转换成MimeKit.MimeMessage对象(虽然,很明显,这将是更好地完全超过切换到MimeKit和MailKit)。

  VAR的MimeMessage =(的MimeMessage)MAILMESSAGE;

这是你重新编写SMTPMailHelper一流的样子用MimeKit和MailKit:

 使用系统;
使用MimeKit;
使用MailKit.Net.Smtp;公共类SMTPMailHelper
{
    常量字符串SMTPSERVER =mail.mydomain.com;
    常量字符串SMTPUserId =myemail@mydomain.com;
    常量字符串SMTPPassword =MyPasswordHidden;
    const int的SMTPPORT = 25;    公共静态无效的SendMail(字符串sendFrom,串SENDTO,弦乐主题,绳体)
    {
        的MimeMessage消息=新的MimeMessage();
        TextPart文本;        message.From.Add(新MailboxAddress(,sendFrom));
        message.To.Add(新MailboxAdress(,SENDTO));
        message.Subject =主体;        如果(body.ToLower()。载有(< HTML和GT;))
            文本=新TextPart(HTML){文字=文本};
        其他
            文本=新TextPart(普通){文字=文本};        message.Body =身体;        使用(VAR SMTP =新SmtpClient()){
            //使用来自http://www.whatismyip.com/得到的IP地址
            //或主机名从http://www.displaymyhostname.com/得到
            smtp.LocalDomain =c-24-71-150-91.hsd1.ga.comcast.net;            smtp.Connect(SMTPSERVER,SMTPPORT,FALSE);
            smtp.Authenticate(SMTPUserId,SMTPPassword);
            smtp.Send(消息);
            smtp.Disconnect(真);
        }
    }
}

进口的一点是,你设置SmtpClient来。

的LOCALDOMAIN属性字符串

I am getting an error and I know my credentials are correct. Any ideas? This is on a Windows Server but I am wanting to use Hostgator SMTP settings for my email. This is what happens when I submit a simple contact form.

ERROR: Mailbox unavailable. The server response was: Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

Source Error Line 61:

Line 59:            
Line 60:             SmtpClient smtp = new SmtpClient(SMTPServer, SMTPPort);
Line 61:             smtp.Credentials = new NetworkCredential(SMTPUserId, SMTPPassword);
Line 62:             smtp.Send(mail);
Line 63:         }

Source File: \Websites\Client\Reports\ContactUs.aspx.cs Line: 61

=========================================================================

My Source Code:

  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string name = txtFirstName.Text + " " + txtLastName.Text;
        string clientID = Session["CustomerID"].ToString();
        string message = txtMessage.Text;
        string email = txtEmail.Text;
        string company = txtCompany.Text;
        string phone = txtPhone.Text;

        SMTPMailHelper.SendMail(email, "myemail@domain.com", "Contact from Client: " + clientID + ": " + name + " " + company, message);
    }

I LEFT OUT SOME SCRIPT THAT DID'T MATTER SUCH AS CONDITIONAL STATEMENTS. AND THIS IS THE REST OF IT:

 public class SMTPMailHelper
{
    const string SMTPServer = "mail.mydomain.com";
    const string SMTPUserId = "myemail@mydomain.com";
    const string SMTPPassword = "MyPasswordHidden";
    const int SMTPPort = 25;

    public static void SendMail(string sendFrom, string sendTo, string subject, string body)
    {
        MailAddress fromAddress = new MailAddress(sendFrom);
        MailAddress toAddress = new MailAddress(sendTo);
        MailMessage mail = new MailMessage();


        mail.From = fromAddress;
        mail.To.Add(toAddress);
        mail.Subject = subject;

        if (body.ToLower().Contains("<html>"))
        {
            mail.IsBodyHtml = true;
        }

        mail.Body = body;


        SmtpClient smtp = new SmtpClient(SMTPServer, SMTPPort);
        smtp.Credentials = new NetworkCredential(SMTPUserId, SMTPPassword);
        smtp.Send(mail);
    }
}

解决方案

The problem you are having is that the SmtpClient is issuing a HELO or EHLO command with a hostname/domain string that your server is SMTP rejecting.

I obviously cannot know the inner logic of Microsoft's SmtpClient implementation, but I suspect that you are probably behind a NAT which means that the SmtpClient cannot resolve the world-viewable fully qualified domain name of your machine. It can only resolve the FQDN of your machine on your "internal network" (and realistically, it probably can't even resolve it to an actual FQDN, it probably has to settle for the internal network IP address).

So... SmtpClient is probably sending something like EHLO [192.168.1.100] (or whatever your local IP is) and the server is rejecting it because that is not the IP address that it is receiving packets from.

What you'll need to do is find your external IP address by visiting a site like http://www.whatismyip.com/ or using the hostname detected by a site like http://www.displaymyhostname.com/.

To illustrate what I am talking about, here's a little demo program:

using System;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Net.NetworkInformation;

namespace LocalHostName
{
    class Program
    {
        static void Main (string[] args)
        {
            var ipAddresses = Dns.GetHostAddresses ("www.google.com");
            Socket socket;

            for (int i = 0; i < ipAddresses.Length; i++) {
                socket = new Socket (ipAddresses[i].AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                try {
                    socket.Connect (ipAddresses[i], 80);
                    Console.WriteLine ("LocalEndPoint: {0}", socket.LocalEndPoint);
                    break;
                } catch {
                    socket.Dispose ();
                    socket = null;

                    if (i + 1 == ipAddresses.Length)
                        throw;
                }
            }

            Console.ReadLine ();
        }
    }
}

Whatever IP address it prints out is likely to be the one that SmtpClient is using in its HELO/EHLO command.

The bad news is that there's no way to work around this problem with System.Net.Mail.SmtpClient.

The good news is that I saved 15% on my car insurance... er, I mean, I've written my own email libraries called MimeKit and MailKit that can work around this problem.

Some more good news is that you can easily cast your System.Net.Mail.MailMessage object into a MimeKit.MimeMessage object (although, obviously, it would be better to switch completely over to MimeKit and MailKit).

var mimeMessage = (MimeMessage) mailMessage;

Here's what your re-written SMTPMailHelper class would look like using MimeKit and MailKit:

using System;
using MimeKit;
using MailKit.Net.Smtp;

public class SMTPMailHelper
{
    const string SMTPServer = "mail.mydomain.com";
    const string SMTPUserId = "myemail@mydomain.com";
    const string SMTPPassword = "MyPasswordHidden";
    const int SMTPPort = 25;

    public static void SendMail(string sendFrom, string sendTo, string subject, string body)
    {
        MimeMessage message = new MimeMessage ();
        TextPart text;

        message.From.Add (new MailboxAddress ("", sendFrom));
        message.To.Add (new MailboxAdress ("", sendTo));
        message.Subject = subject;

        if (body.ToLower ().Contains ("<html>"))
            text = new TextPart ("html") { Text = text };
        else
            text = new TextPart ("plain") { Text = text };

        message.Body = body;

        using (var smtp = new SmtpClient ()) {
            // use the IP address gotten from http://www.whatismyip.com/
            // or the hostname gotten from http://www.displaymyhostname.com/
            smtp.LocalDomain = "c-24-71-150-91.hsd1.ga.comcast.net";

            smtp.Connect (SMTPServer, SMTPPort, false);
            smtp.Authenticate (SMTPUserId, SMTPPassword);
            smtp.Send (message);
            smtp.Disconnect (true);
        }
    }
}

The import bit is the string that you set the LocalDomain property of the SmtpClient to.

这篇关于获得一个ASP错误:邮箱不可用。服务器响应为:拒绝访问 - 无效HELO域名(见RFC2821 4.1.1.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆