Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed

I have written ASP.Net code to send mails from domain1.com mail account such as [email protected]. This code work fine otherwise and the mails go. But when the same code executes on domain2.com, even with correct userid-pwd it gives the following error:

System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1) at System.Net.Mail.SmtpClient.Send(MailMessage message)

Is there any way to fix this?

If we have to add this domain in the list of allowed rcphosts, how can that be done?

The code written is something like this:

MailMessage message;
bool success;
message = new MailMessage(from, to);
Attachment file;
SmtpClient lclient;


lclient = new SmtpClient("mail.domain1.com", 587);
lclient.EnableSsl = false;

message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;

lclient.SendCompleted += new 
SendCompletedEventHandler(SendCompletedCallback);
lclient.UseDefaultCredentials = false;
lclient.Credentials = new NetworkCredential(userID, password);
try
{

  lclient.Send(message);
  success = true;
  if (message != null)
      message.Dispose();
  success = true;
  return (success);
}
catch (Exception ex)
{  
    //...
}

Thanks

like image 671
Anuradha Kulkarni Avatar asked Apr 23 '12 14:04

Anuradha Kulkarni


1 Answers

The code works fine. The error is a rejection from the SMTP server. It would seem that the server, when accessed from Domain1, allows you to forward mail through it. When accessed from Domain2, it does not. Changing this would be a configuration on the SMTP server.

Note that this is common practice for SMTP services. They generally don't allow anybody to send mail through them to any address. (That would leave them wide open for spammers and other such unwanted activities.) So, if you're trying to access Domain1's SMTP service from outside of Domain1, it's probably just rejecting that.

like image 168
David Avatar answered Oct 21 '22 04:10

David