1
votes

I am trying to send email via System.Net.Mail. On clicking send I am getting the following exception

System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: We do not relay non-local mail

        MailAddress toAddress = new MailAddress(toEmail);
        MailAddress fromAddress = new MailAddress(fromEmail);
        MailMessage mailMsg = new MailMessage(fromAddress, toAddress);

        mailMsg.Subject = EmailSubject;
        mailMsg.Body = MessageBody.ToString();
        mailMsg.IsBodyHtml = true;


        System.Net.Mail.SmtpClient smtp = new SmtpClient(EmailSettings.SmtpServer);
        smtp.Send(mailMsg);

That is all I am doing.

What workaround should I take for this to work

2
use a local smtp server (in your domain) or find one that does allow relaying with authentication.Mitch Wheat
It'll help if you show some code, and anything related that you've defined in your web.config if applicable.Brissles
both the to and from address are from the same serverSandhurst
@Sandhurst: That might be not enough. Not only they have to be from the same server but also that server name should equal EmailSettings.SmtpServer value - including subdomains.Sergey Kudriavtsev

2 Answers

2
votes

You should authenticate your SMTP client using credentials AND sender mailbox belonging to SMTP server you're connecting to.

0
votes

Also (depending on your mail server) the fromAddress needs to be an actual account on the mail server.