C# 信箱不可用。服务器响应为:5.7.1 无法中继错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15717743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 17:43:30  来源:igfitidea点击:

Mailbox unavailable. The server response was: 5.7.1 Unable to relay Error

c#asp.netsmtpclient

提问by Arjun

I have Hosted one of my website on netsol server. From there a contact.aspxhas to send email using exchange server. When I attempt to send an email:

我在 netsol 服务器上托管了我的网站之一。从那里contact.aspx必须使用交换服务器发送电子邮件。当我尝试发送电子邮件时:

Error: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

错误:邮箱不可用。服务器响应为:5.7.1 无法中继

Code:

代码:

MailMessage message = new MailMessage(@"[email protected]", 
                                      @"[email protected]",
                                       "New Message",
                                       "Exchange");
SmtpClient mail = new SmtpClient("exchange.abc.com", 29);
mail.EnableSsl = true;
mail.Credentials = new NetworkCredential(@"[email protected]", @"password");
mail.UseDefaultCredentials = false;
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.Send(message);

Options I tried:

我试过的选项:

  • Tested on Port 465 or 587 or 25
  • Changed SmtpDeliveryMethod.PickupDirectoryFromIis
  • can't configure IIS (SMTP server) as it is hosted on someone else's server
  • 在端口 465 或 587 或 25 上测试
  • 更改了 SmtpDeliveryMethod.PickupDirectoryFromIis
  • 无法配置 IIS(SMTP 服务器),因为它托管在其他人的服务器上

回答by Jim Mischel

The default configuration of most SMTP servers is not to relay from an untrusted source to outside domains. For example, imagine that you contact the SMTP server for foo.com and ask it to send a message to [email protected]. Because the SMTP server doesn't really know who you are, it will refuse to relay the message. If the server diddo that for you, it would be considered an open relay, which is how spammers often do their thing.

大多数 SMTP 服务器的默认配置是不从不受信任的源中继到外部域。例如,假设您联系 foo.com 的 SMTP 服务器并要求它向 [email protected] 发送消息。因为 SMTP 服务器并不真正知道您是谁,所以它会拒绝中继消息。如果服务器确实为您这样做了,它将被视为开放中继,这就是垃圾邮件发送者经常做的事情。

If you contact the foo.com mail server and ask it to send mail to [email protected], it mightlet you do it. It depends on if they trust that you're who you say you are. Often, the server will try to do a reverse DNS lookup, and refuse to send mail if the IP you're sending from doesn't match the IP address of the MX record in DNS. So if you say that you're the bar.com mail server but your IP address doesn't match the MX record for bar.com, then it will refuse to deliver the message.

如果您联系 foo.com 邮件服务器并要求其将邮件发送到 [email protected],它可能会让您这样做。这取决于他们是否相信你就是你所说的那个人。通常,服务器会尝试进行反向 DNS 查找,并在您发送的 IP 与 DNS 中 MX 记录的 IP 地址不匹配时拒绝发送邮件。因此,如果您说您是 bar.com 邮件服务器,但您的 IP 地址与 bar.com 的 MX 记录不匹配,那么它将拒绝传递邮件。

You'll need to talk to the administrator of that SMTP server to get the authentication information so that it will allow relay for you. You'll need to present those credentials when you contact the SMTP server. Usually it's either a user name/password, or it can use Windows permissions. Depends on the server and how it's configured.

您需要与该 SMTP 服务器的管理员交谈以获取身份验证信息,以便为您进行中继。当您联系 SMTP 服务器时,您需要出示这些凭据。通常它是用户名/密码,或者它可以使用 Windows 权限。取决于服务器及其配置方式。

See Unable to send emails to external domain using SMTPfor an example of how to send the credentials.

有关如何发送凭据的示例,请参阅无法使用 SMTP 向外部域发送电子邮件

回答by ttomsen

WE had this issue. everything was setup fine in terms of permissions and security.

我们有这个问题。在权限和安全性方面,一切都设置得很好。

after MUCH needling around in the haystack. the issue was some sort of heuristics. in the email body , anytime a certain email address was listed, we would get the above error message from our exchange server.

在大海捞针后。问题是某种启发式方法。在电子邮件正文中,任何时候列出某个电子邮件地址,我们都会从我们的交换服务器收到上述错误消息。

it took 2 days of crazy testing and hair pulling to find this.

花了2天的疯狂测试和拔头发才找到这个。

so if you have checked everything out, try changing the email body to only the word 'test'. If after that, your email goes out fine, you are having some sort of spam/heuristic filter issue like we were

因此,如果您已检查所有内容,请尝试将电子邮件正文更改为仅“测试”一词。如果在那之后,您的电子邮件发送正常,则您遇到了某种垃圾邮件/启发式过滤器问题,就像我们一样

回答by Tomas Kubes

I use Windows Server 2012 for hosting for a long time and it just stop working after a more than years without any problem. My solution was to add public IP address of the server to list of relays and enabled Windows Integrated Authentication.

我使用 Windows Server 2012 托管很长时间,它在多年后停止工作,没有任何问题。我的解决方案是将服务器的公共 IP 地址添加到中继列表并启用 Windows 集成身份验证。

I just made two changes and I don't which help.

我只是做了两个更改,但我没有帮助。

Go to IIS 6 Manager

转到 IIS 6 管理器

Go to IIS 6 Manager

转到 IIS 6 管理器

Select properties of SMTP server

选择 SMTP 服务器的属性

Select properties of SMTP server

选择 SMTP 服务器的属性

On tab Access, select Relays

在选项卡访问上,选择继电器

On tab Access, select Relays

在选项卡访问上,选择继电器

Add your public IP address

添加您的公共 IP 地址

Add your public IP address

添加您的公共 IP 地址

Close the dialog and on the same tab click to Authentication button.

关闭对话框并在同一选项卡上单击“身份验证”按钮。

Add Integrated Windows Authentication

添加集成 Windows 身份验证

Add Integrated Windows Authentication

添加集成 Windows 身份验证

Maybe some step is not needed, but it works.

也许不需要某些步骤,但它有效。