views:

156

answers:

3

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?

A: 

I am pretty sure that if server rejectects the email for any reason your code would throw an exception. If it is not then that implies that the server is accepting the emails with the supplied user name and password and technically the mails are "sending" sucesfully. However this is no guarantee that anyone will receive any emails. You need to find out what the email server is doing with these emails and why.

Ben Robinson
I've asked our IT team to open a ticket with microsoftonline support. However, as a developer I still want to do any homework I can meanwhile.
BreakPhreak
I understand but unfortunately i don't think there is much you can do, if the serrver is accepting the emails but not delivering them then technically your code is working, if you are doing something wrong you will not find out anything useful until you hear back from support. If you are paying for a hosted service be prepared for them to say that sending emails programatically is not supported.
Ben Robinson
The CI (Continuous Integration server) succeeds to send mails fluently. And this way or another - I am looking for any kind of server-side validation I can (should try to) perform. Thanks anyway.
BreakPhreak
Not sure what you mean by "server side validation", which server are you refering to?
Ben Robinson
I mean the exchange server I am trying to send the mails via it. But as I've wrote above, while talking to you guys I've got that maybe the best situation would be to install some SMTP server locally, check with it and forget.
BreakPhreak
Yes that would be the best solution. You would not be able to validate anything with an SMTP server, there is no "what happened to my email" option in the SMTP protocol.
Ben Robinson
+1  A: 

The link below has an example of a very simple send email function that can be called from a console application to test. I know this code works, so it could isolate any issue with your code and maybe shed a little more light on where the issue is.

SendEmail() – Create and Send Email Messages in C#

Alex
yeah, just as my code, actually :) meanwhile got an official IT response - it was a network/security configuration issue.
BreakPhreak
A: 

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

BreakPhreak