Relay access denied 5.7.1

Mustafa KIRILMAZ picture Mustafa KIRILMAZ · Dec 8, 2013 · Viewed 16.5k times · Source

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?

Answer

Yong Tiger picture Yong Tiger · Dec 8, 2013

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