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("kevin@hopethisworks.com","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.

Steve Czetty
  • 6,147
  • 9
  • 39
  • 48
Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138

4 Answers4

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

Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138
  • 1
    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. – Erik Kowalewski Jun 28 '13 at 19:31
  • Thanks a ton! I needed to do this on the Client Frontend Connector and also the Client Proxy Connector! – partyd Jul 16 '17 at 15:55
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 "user@anotherdomain.com", 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 = "someaddress@sample.com"}.

aleor
  • 286
  • 2
  • 5
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="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.

ViqMontana
  • 5,090
  • 3
  • 19
  • 54
-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
rchacko
  • 1,965
  • 23
  • 24