Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Our users can send emails from our ASP.NET Web application on the click of a button. In our testing environment, there is a strange thing going on.

The first time the application tries to send the email, we get the exception:

Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender

The funny thing is, when the user clicks on the button again (so the application tries to send the email again), it works, and the email is sent.

If you wait a while, you'll get the error again, but clicking for the second time will send the email without problems. If you would be fast enough to send a new email, it would work.

This is the (simplified) code we use:

Dim smtpClient As New SmtpClient(<smtp mail server goes here>)
smtpClient.UseDefaultCredentials = True
mailMessage.From = New MailAddress(<from address>)

This does work in the production environments though. We're using Microsoft Exchange, and so are our customers (the production environments).

Has anyone ever had anything similar (error the first time, works like a charm the second time)?

share|improve this question
what smtp/email server? – pablo Feb 21 '11 at 10:14
@pablo: Microsoft Exchange – Peter Feb 21 '11 at 13:43

I've seen this happen a few times before and here are the causes I have seen. Keep in mind these have only been seen in a large environment. If you are in a single dc, single exchange server environment these will not apply.

First off here is the MS article on this: Under the possible cuases you can see there are a lot of things at play.

One of your exchange servers relay permissions are not setup correctly.

This is most likley the cause. The mail may be taking a different route on the first and second try, while this might sound silly run message tracking on both messages, see if they go through the same server. If you see different paths check the settings on the bad one, could be a simple allow relay for authenticated users isnt checked.

AD permissions are wrong

You must have Send As permissions on the account that has the from address from your email. If it is working sometimes, but not others then it may be different pathings on mail routing, with different permissions between them.

Authentication isn't working correctly.

In the first instance of the script it may be that authentication fails, and in this instance the mail is denied as you do not have permission. In the second run of the script authentication is successfull. Unfortunately I do not know ASP well enough to understand the code above or advise on how to fix it. smtpClient.UseDefaultCredentials may not be the correct code for your environment. This will only authenticate if requested by the server and will use the credentials of the locally logged on user. If the server isn't asking for authentication the first time around then you wont be authed and may not have permission to send. Try changing it to some code that always authenticates.

One of your DCs or global catalogs is out of date or has bad information.

This is rare but it is possible that your domain controllers have out of sync information. Double check the server information on the from and to accounts via ldap or adsi edit and ensure they are identical across all dcs.

In all instances check the logs on the exchange server and ensure SMTP logging is enabled with all fields. Use message tracking to see exactly which servers this message is hitting.

share|improve this answer

It looks to me like you may have SMTP authentication enabled on the mail server but haven't included it in the code. In such a case the first time you try to send a message it effectively performs the authentication but fails to send the message. The next time the user is authenticated and the message goes through.

share|improve this answer

Try this :

    Dim client = New SmtpClient(<smtp mail server goes here>)
    MailerManager.ServerSMTP = client.Host.ToString()
    Catch ex As Exception
        'Error Message
    End Try
share|improve this answer
This does not help in any way. Please read the question. – Peter Jan 15 '14 at 12:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.