How do I send emails outside my domain with Exchange 2007 and c#

17,635

Solution 1

Try #2... How about using a Exchange Pickup Folder instead? They are a faster way to send emails through Exchange because it just creates the email and drops it in the folder, no waiting to connect to the server or waiting for a reply. Plus I think it skips the whole relay issue.

Configure youur SmtpClient like so:

SmtpClient srv = new SmtpClient("exchsrv2007", 25) {
    DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
    PickupDirectoryLocation = "\\exchsrv2007\PickupFolder"
}
...

Solution 2

Authenticate to the exchange server.

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.aspx


DefaultNetworkCredentials returns empty strings for username etc and causes this exception...

Here is an example, and here is another of sending authenticated message with System.Net.Mail.

Solution 3

You'll need to get your exchange admin to configure exchange to allow sending outside the domain. In my experience they've been reluctant to do so because of spam concerns.

If its' for limited use, you can set up server-side rules in exchange to forward messages meeting certain criteria outside the domain. You might be able to use VBA in these as well to pretty things up, but I am not sure.

Share:
17,635

Related videos on Youtube

jmcd
Author by

jmcd

I've been coding since my Father bought me Commodore-64 as a Christmas present, and after many years of re-writing a home grown game C++ game engine by night as I worked for the man during the day, journeying into .NET and C# in the past five years, followed by a very happy and productive present in Rails and the Ruby eco-system. TDD, BDD and Agile methods are of great interest to me.

Updated on April 17, 2022

Comments

  • jmcd
    jmcd about 2 years

    I am able to send emails using the typical C# SMTP code across Exchange 2007 as long as both the from and to addresses are within my domain.

    As soon as I try to send emails outside the domain I get:

    Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

    How can I get exchange to accept my email and send it out to the internet?

  • jmcd
    jmcd over 15 years
    I've followed this artice and it didn't make any difference :(
  • jmcd
    jmcd over 15 years
    DefaultNetworkCredentials returns empty strings for username etc and causes this exception: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender
  • scottm
    scottm over 15 years
    +1 Usually larger corporations have multiple exchange servers and at least one is allowed to forward email outside the domain.
  • nuthan ratnam vara
    nuthan ratnam vara over 15 years
    Not by default, the network path would need to be shared and the process ASP.NET is running as (or the impersonation) would need permissions to access the directory.
  • Xavier Young
    Xavier Young over 15 years
    Can you tell most of my experience with Exchange has been with smaller companies :D
  • Mozy
    Mozy over 14 years
    +1 for such a time saving solution. Solves my problem perfectly.
  • Chris Snowden
    Chris Snowden almost 13 years
    +1 client.Credentials = CredentialCache.DefaultNetworkCredentials; solved my relaying issue. Relays fine using this.