RSS
 

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

20 May

I have got this issue many times, when I try to send email using smtp. There can be several causes for this. You have to allow relay for mail to be sent to outside servers like gmail.com. For sending mail within your server you don’t have to do this. You can find some helps from the following links:
Help1
Help2
Help3

The code I have used is given below:

using System.Net.Mail;

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
smtpClient.Port = 25;
smtpClient.Host = “smtp.domain.com”;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(“webmail username”, “webmail password”);
message.From = new MailAddress(“webmail username”);
message.To.Add(“test@gmail.com”);
string emailBody = “Hi,

Welcome

“;
message.Body = emailBody;
message.Subject = “testing”;
message.IsBodyHtml = true;
smtpClient.Send(message);

But, after making the changes on the server, as specified on the above links, I was still getting the same error. Then I added the following line in between the above code.
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

Then the error was gone.

 
3 Comments

Posted in asp.net, email

 

Leave a Reply

 
 
  1. Arun

    July 19, 2010 at 10:09 am

    heyy this blog is quiet interesting..
    keep up the gud work…

     
  2. gucci handbags

    August 4, 2010 at 7:00 pm

    Thank you for building your blog site, I located you on Google and I need to say I’m impressed. Appreciate it yet again…

     
  3. Alexander4

    July 13, 2011 at 12:03 am

    buy@generic.abana” rel=”nofollow”>…

    Need cheap generic ABANA?…