Search code examples
c#smtpemailsmtpclientemail-client

Can't send mail with SmtpClient


Can't send mail. Here is my C# source:

  var to = "[email protected]";
  var subject = "test";
  var body = "test mail";
  var message = new MailMessage(from, to, subject, body);
  var client = new SmtpClient { Credentials = new NetworkCredential("[email protected]", "mypassword") };
  client.Send(message);

here is the App.config:

  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network
          host="mail.mycompany.com"
          port="25"
          userName="[email protected]"
          password="mypassword"
        />
      </smtp>
    </mailSettings>
  </system.net>

So far, if the host/port in App.config are wrong an exception is thrown, but not if user/pass are wrong (obvious security reasons). However, I've succeeded to log-in from Microsof Outlook with just the same user/pass as in the source.

The email is not received, nor in Inbox, neither in Junk folder. How can I validate the server-side (considering it's a part of microsoftonline.com)? What am I missing? What am I doing wrong, please?


Solution

  • Got an answer from the IT team - it was a configuration/security issue. Solved with IT. Thanks a lot, everyone.