Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 799
jmcd Avatar asked Jan 14 '09 18:01

jmcd


2 Answers

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"
}
...
like image 193
DavGarcia Avatar answered Sep 18 '22 16:09

DavGarcia


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.

like image 28
Zoredache Avatar answered Sep 18 '22 16:09

Zoredache