Search code examples
c#emailexchange-serverexchange-server-2010

'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

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.


Solution

  • 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