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

I faced this message when I was trying to enable E-Mail sending on VPS hosting using Windows Server 2008 R2.

Here are the things to do to solve it:

1. Check if you have SMTP feature installed, because it is not installed by default. If not, install it using “Server Manager -> Features”. Here you should add the SMTP feature with all the necessary services.

2. Open the ISS Manager, double-click “SMTP E-mail”, apply the below settings:
E-mail Address = [some name || admin || whatever you like]@[yourwebsite].com
SMTP Server = localhost (check “Use localhost”)
Port = 25
Authentication = Windows

3. If you are sending E-mails programmatically below are the rules you must apply: (C#)
Note: This is not the full code, just the key points!

client.Host = "127.0.0.1";
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("  [some name || admin || whatever you like]@[yourwebsite].com ", "heading of yor e-mail message here");

4. web.config

<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[some name || admin || whatever you like]@[yourwebsite].com">
<network host="127.0.0.1" port="25" />
</smtp>
</mailSettings>
</system.net>

5. Open “IIS 6.0 Manager” (installed when adding SMTP feature to Windows Server 2008 R2)

Under the “SMTP Virtual Server” right-click “Domains”
Add a new domain as “Alias”, name it [yourwebsite].com

Everything should be fine now. You should be able to send E-mails to your users programmatically.

Hope this helps someone.
Good luck,
Serdar.

Leave a Reply

Your email address will not be published. Required fields are marked *