I've got the error "Relay access denied", but I can connect my account with some email programs.
My code:
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential =
new NetworkCredential("[email protected]", "xxx");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("[email protected]");
smtpClient.Host = "mail.xx.com";
smtpClient.Port = 587;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
message.To.Add("[email protected]");
try
{
smtpClient.Send(message);
}
catch (Exception ex)
{
//Relay access denied...
}
Does anyone know the reason for this?
You must be authorized to use a mail server for relaying. Unauthorized users will always receive the "Relaying Denied" error. To use a mail server, you must prove to the mail server that you are authorized to send email. By far the most common cause is that no user name and password were specified.
That error message means the message has been rejected by the recipient's domain (the receiving end), and so, your outgoing SMTP server failed to deliver it. This is not something you can fix from your end as the sender.
This means that you are trying to send the mail from an outgoing mail server (SMTP) other than the one that is associated to your mailbox, and that the outgoing mail server does not allow such an action.
It's likely that the server isn't set up correctly to receive and relay messages sent from <Microsoft _365_domain>..." This issue can occur if connectors have been enabled in the Microsoft 365 domain's Exchange Online, 'mail flow' settings and those connectors are either no longer active or are faulty.
Since your smtp host port is 587, I think you should set smtpClient.EnableSsl to true before calling its Send method.
Although this question is almost a year old now, I just stumbled upon the solution to a similar problem today. Apparently, the System.Net.Mail.SmtpClient
class does not support the AUTH PLAIN
method. Unfortunately, the SMTP server I was trying to use only offered AUTH PLAIN
. Since the SmtpClient
class and my server couldn't agree on an authentication method, the SmtpClient
tried to send mails without authentication which got rejected by the SMTP server...
You should make sure that the SMTP server you are using offers at least one of the authentication mechanisms that SmtpClient
supports. I couldn't find an exhaustive list of supported mechanisms but my server is now offering AUTH LOGIN
which works with SmtpClient
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With