'Relay access denied on sending email

I want to send email via my desktop app
Here is my code

        MailMessage m = new MailMessage("[email protected]", "[email protected]", "subject", "body");
        m.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("out.tedata.net.eg");
        smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
        smtp.UseDefaultCredentials = true;
        smtp.Send(m);

My problem is: this code throw an exception

Transaction failed. The server response was: 5.7.1 <[email protected]>: Relay access denied

I think because my internet provider need outgoing server (SMTP) authentication I config it in Outlook as below enter image description here
Now, How can I config it in my code

Thanks



Solution 1:[1]

I found this question because I have the same problem. I solved it using the myNetworks entry in /etc/postfix/main.cf Add the IP from which your sending to the myNetworks line, I think PostFix expects a space to separate IP adresses, for my eyes it's better to use a comma, but if I use both it works.

This solution is not ideal, so I'll be gratefull for a better one!

Rob

Solution 2:[2]

It can be various issues:

  1. are you able to send mail to Yahoo mail from your outlook? check this link If yes
  2. Check IIS SMTP Virtual Server Relay Restrictions

Hope this help you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RobRdam
Solution 2 Zain Shaikh