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

10,098

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.

Share:
10,098
Anuradha Kulkarni
Author by

Anuradha Kulkarni

Anuradha is interested in software design and development in MS technologies - C#, VB.Net, ASP.net, Silverlight, WPF, WCF.

Updated on June 04, 2022

Comments

  • Anuradha Kulkarni
    Anuradha Kulkarni almost 2 years

    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

  • Anuradha Kulkarni
    Anuradha Kulkarni about 12 years
    Thanks, David. Is it possible change this configuration? Or may be we just have to change the design little bit to accomodate this.
  • David
    David about 12 years
    @AnuradhaKulkarni: You might be able to change the configuration, but that's really outside the scope of anything I can help with. That's server administration and depends entirely on what SMTP service you're using. If you need to re-design a bit, you could try running a web service on the host that does allow email and having your other instances just access that service to send mail instead of sending it directly.