Relay access denied 5.7.1
Asked Answered
M

5

8

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?

Mazarin answered 8/12, 2013 at 14:42 Comment(0)
C
4

Since your smtp host port is 587, I think you should set smtpClient.EnableSsl to true before calling its Send method.

Cowitch answered 8/12, 2013 at 14:58 Comment(0)
C
3

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.

Communist answered 9/10, 2014 at 21:14 Comment(0)
M
1

Please try

        SmtpClient client = new SmtpClient("[email protected]");

        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("[email protected]", "xxx");
        client.Port = 587;
        client.EnableSsl = true;

        MailMessage maili = new MailMessage();
        maili.Body = body;
        maili.Subject = subject;
        maili.IsBodyHtml = true;
        maili.From = new MailAddress("[email protected]");
        maili.To.Add("[email protected]");

        try
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            client.Send(maili);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        maili.Dispose();
Mazarin answered 16/12, 2013 at 13:23 Comment(1)
What is your try-catch good for apart from resetting the stack trace?Entophyte
R
1

In my case, the smtp password had changed, and gave me this error...

Resiniferous answered 7/3, 2016 at 17:40 Comment(0)
P
0

Usually it's very simple: the "From" e-mail address must have the same domain name as the domain name of the account from which the e-mail is being sent. So, if you send e-mail through a Hotmail account with the e-mail address e.g. "[email protected]", the "From" address must be set to the same.

Password answered 9/1, 2020 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.