0

I tried to send mails from Microsoft Exchange from our organization, but I get the error message: The customer is not allowed to submit mail to this server. The response from the server was: 4.7.1 : Relay access denied

My Code is :

private void button2_Click(object sender, EventArgs e)
    {
        string Username = "MyUsername";
        string Password = "MyPassword ";
        string SmtpServer = "OurSmtpServer";
        string From = Username + "SmtpServer ";

        System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
        NetworkCredential basicCredential = new NetworkCredential(Username, Password, SmtpServer);
        MailMessage message = new MailMessage();
        System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(From);

        // setup up the host, increase the timeout to 5 minutes
        smtpClient.Host = SmtpServer;
        smtpClient.Port = 25;
        smtpClient.UseDefaultCredentials = false;
        //smtpClient.Credentials = basicCredential;
        smtpClient.UseDefaultCredentials = true;
        smtpClient.Timeout = (60 * 5 * 1000);

        message.From = fromAddress;
        message.Subject = " - " + DateTime.Now.Date.ToString().Split(' ')[0];
        message.IsBodyHtml = true;
        message.Body = " -88888888888888888888888888888 ";
        message.To.Add("recipient@gmail.com");



        smtpClient.Send(message);
    }

We use windows authentication normally in our organization. Is this the cause of the problem? if so how to use windows authentication in my code?

And thank you in advance for your help !!

jalil monagi
  • 39
  • 1
  • 2
  • 9
  • Possible duplicate of [How can I make SMTP authenticated in C#](https://stackoverflow.com/questions/298363/how-can-i-make-smtp-authenticated-in-c-sharp) – Dan Wilson Sep 07 '18 at 17:15
  • I am already authenticated, but I get in addition the message indicated above. Thank you !! – jalil monagi Sep 10 '18 at 14:05
  • Well then relaying is not currently allowed by your SMTP server. You should check with whoever manages the server. – Dan Wilson Sep 10 '18 at 14:09

0 Answers0