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
You should authenticate your SMTP client using credentials AND sender mailbox belonging to SMTP server you’re connecting to.