Relay access denied 5.7.1

Viewed 19608

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("xx@xx.com", "xxx");
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("xx@xx.com");

        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("aa@aa.com");

        try    
        {
            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //Relay access denied...
        }

Does anyone know the reason for this?

5 Answers

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. "john.doe@hotmail.com", the "From" address must be set to the same.

Related