简体   繁体   English

从代码发送电子邮件时,“5.7.1客户端没有权限”错误

[英]'5.7.1 Client does not have permission' error while sending email from code

So I have this very basic program that is trying to send an e-mail, but I keep getting 所以我有这个非常基本的程序,试图发送电子邮件,但我一直在

Mailbox unavailable. 信箱不可用。 The server response was: 5.7.1 Client does not have permissions to send as this sender 服务器响应为:5.7.1客户端无权作为此发件人发送

Here is my program 这是我的计划

static void Main(string[] args)
{
    SmtpClient client = new SmtpClient("Server", 25);
    client.UseDefaultCredentials = false;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Credentials = new NetworkCredential("UserName", "Password");
    client.Send(new MailMessage("kevin@hopethisworks.com","Recipient"));
}

I know the credentials work, if I run SMTP Test Tool 3.0 with the same data everything works great. 我知道凭据有效,如果我使用相同的数据运行SMTP Test Tool 3.0一切都很好。

在此输入图像描述

Here is some screen shots on a receive connector set up for my IP on the exchange server 以下是在Exchange服务器上为我的IP设置的接收连接器的一些屏幕截图

在此输入图像描述

在此输入图像描述

Anybody have any ideas what would be causing this error in my code, but not within the simple SMTP testing tool? 任何人都有任何想法会在我的代码中导致此错误,但不是在简单的SMTP测试工具中? Am I missing some kind of authentication option somewhere? 我在某处遗漏了某种身份验证选项吗? I have quadruple checked all the information is correct and identical in both places and it works in the tool but not in the code. 我有四重检查所有信息在两个地方都是正确和相同的,它在工具中工作,但在代码中不起作用。

I found the problem, I needed to check the box 'Accept any sender' for authenticated users. 我发现了问题,我需要为经过身份验证的用户选中“接受任何发件人”复选框。

在此输入图像描述

More information here: http://technet.microsoft.com/en-us/library/aa997170(EXCHG.140).aspx 更多信息请访问: http//technet.microsoft.com/en-us/library/aa997170(EXCHG.140).aspx

I know this thread is quite old, but I just got the same trouble and have been scratching my head for a long time. 我知道这个线程已经很老了,但是我遇到了同样的麻烦并且长时间一直在摸不着头脑。 In my case, mail server didn't accept "foreign" sender, so for example if you are in @sample.com domain, it might be impossible to send mail from "user@anotherdomain.com", because server will reject this with 5.7.1 error. 在我的情况下,邮件服务器不接受“外国”发件人,因此,例如,如果您在@ sample.com域,可能无法从“user@anotherdomain.com”发送邮件,因为服务器将拒绝此5.7.1错误。 So, 2 things are important here: 1) Correct credentials which will be used to connect to the server; 因此,这里有两件事情很重要:1)正确的凭证,用于连接服务器; 2) Value of "From" field, as your server can reject mails from sender that belongs to another domain. 2)“发件人”字段的值,因为您的服务器可以拒绝来自属于另一个域的发件人的邮件。 In other words, if you are in @sample.com domain, try to add this as well new MailMessage {From = "someaddress@sample.com"}. 换句话说,如果您在@ sample.com域中,请尝试添加此新邮件以及新邮件来自{From =“someaddress@sample.com”}。

I had the same problem. 我有同样的问题。 I tested the SMTP settings in a separate console application and it worked fine. 我在单独的控制台应用程序中测试了SMTP设置,它运行正常。 After some googling, I realised my issue was the fact that I had specified the from address twice, once in my config: 经过一些谷歌搜索,我意识到我的问题是我在配置中指定了两次来自地址的事实:

<smtp deliveryMethod="Network" from="no.reply@somewhere.com">

And also in my code: 还有我的代码:

mail.From = new MailAddress("different@somewhere.com");

Removing the from address from the code resolved the issue. 从代码中删除发件人地址解决了问题。

I think you have to set UseDefaultCredentials to true: see powershell code 我认为你必须将UseDefaultCredentials设置为true:请参阅powershell代码

#SMTP server name
$smtpServer = "abcd.com.au"

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.UseDefaultCredentials = $true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 服务器响应为:5.7.1使用SMTP客户端发送电子邮件时未对客户端进行身份验证 - The server response was: 5.7.1 Client was not authenticated While Sending email using SMTP client 发送带有C#.Net错误5.7.1的电子邮件 - Sending email with C# .Net error 5.7.1 从控制台应用程序发送电子邮件时出错 - Error while sending email from Console application 信箱不可用。 服务器响应为:5.7.1客户端无权发送此发送者 - Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender SMTP错误:“客户端无权向此服务器提交邮件” - SMTP error: “Client does not have permission to submit mail to this server” 从 Windows 服务发送电子邮件:事务失败。 服务器响应为 5.7.1 客户端主机拒绝访问被拒绝 - Send Email from Windows Service: Transaction failed. the server response was 5.7.1 client host rejected access denied 从我的Gmail帐户发送电子邮件时出错 - Getting error while sending an email from my gmail account 从web.config发送带有凭据的电子邮件时出错 - Error while sending email with credentials from web.config 使用smtp客户端发送带有附件错误的电子邮件 - sending email with smtp client with attachment giving error 通过SMTP客户端发送电子邮件时出错 - Error in Sending Email via a SMTP Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM