System.Net.Mail.SmtpFailedRecipientException and Exchange 2007

Posted by Ryan Baxter Fri, 30 Jan 2009 17:45:00 GMT

I’d recently been struggling with a .NET application that sends email via SMTP through Exchange 2007 outside of my domain at work. That is, until I found a workaround that uses the Exchange 2007 Pickup folder. This eliminated my authentication hassles and resolved the dreaded Mailbox unavailable. The server response was: 5.7.1 Unable to relay error. I’ve posted the solution here, but I also suggest reading the original post.

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

Keep in mind that you’ll either need sufficient write permission on the Pickup folder or be able to impersonate somebody that does. I happen to have written about identity impersonation a few months ago. You’re in luck.

Kudos to stackoverflow.com. I only wish I had enough rep to upvote the submitter. :(

Comments

Leave a response

Avatar
Edwin Comment_bubble 9 months later:
This is not so good. The best thing is to change the SMPT server to relay emails from authenticated server or users.
Avatar
Ryan Baxter Comment_bubble 9 months later:
I agree, but sometimes doing things the "best" way is outside of your control. It happens to all of us. Like I said, it's a workaround.