'5.7.1 Client does not have permission' error while sending email from code
Asked Answered
E

4

14

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

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("[email protected]","Recipient"));
}

I know the credentials work, if I run SMTP Test Tool 3.0 with the same data everything works great.

enter image description here

Here is some screen shots on a receive connector set up for my IP on the exchange server

enter image description here

enter image description here

Anybody have any ideas what would be causing this error in my code, but not within the simple SMTP testing tool? 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.

Edris answered 22/8, 2012 at 20:44 Comment(0)
E
11

I found the problem, I needed to check the box 'Accept any sender' for authenticated users.

enter image description here

More information here: http://technet.microsoft.com/en-us/library/aa997170(EXCHG.140).aspx

Edris answered 30/8, 2012 at 13:36 Comment(2)
This totally saved me. Thanks a TON! Also, for what it's worth - this ability was working fine with our Exchange 2003 box. When we updated to 2010, it stopped working. That led me to this article. The 'Accept any sender' option must have been either new with Ex2010 or it reset the option with the upgrade.Revet
Thanks a ton! I needed to do this on the Client Frontend Connector and also the Client Proxy Connector!Simple
E
4

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 "[email protected]", because server will reject this with 5.7.1 error. So, 2 things are important here: 1) Correct credentials which will be used to connect to the server; 2) Value of "From" field, as your server can reject mails from sender that belongs to another domain. In other words, if you are in @sample.com domain, try to add this as well new MailMessage {From = "[email protected]"}.

Entresol answered 16/4, 2015 at 14:18 Comment(1)
setting up the from address as the same that sends the credentials.. Helped me. ThanksHowes
I
0

I had the same problem. I tested the SMTP settings in a separate console application and it worked fine. 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="[email protected]">

And also in my code:

mail.From = new MailAddress("[email protected]");

Removing the from address from the code resolved the issue.

Inglis answered 6/9, 2017 at 8:15 Comment(0)
S
-1

I think you have to set UseDefaultCredentials to true: see powershell code

#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
Shikari answered 12/9, 2016 at 4:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.