Search code examples
c#smtpexchange-server-2003

Exchange 2003 with C# smtpclient


I am currently trying to use SmtpClient to send an email with exchange 2003. Using the code below it will not send an email, but it does not throw an exception which i assume means it is making a connection to the exchange server because. Also for the server setting I tried mail.server.com as well as the IP address and it still does not throw an exception.

        public static void emailTest()
    {
        string fromEmail = @"me@me.com";
        string ToEmail = @"me@me.com";          
        string body = "C Stuck Batches"; 
        string subject = "C Stuck Batches"; 

        try
        {
            SmtpClient MyMail = new SmtpClient("x.x.x.x");
            MyMail.DeliveryMethod = SmtpDeliveryMethod.Network;
            MyMail.UseDefaultCredentials = false;
            MyMail.Credentials = new NetworkCredential(@"domain\user", "password"); 

            MyMail.Send(fromEmail, ToEmail, subject, body);
            MessageBox.Show("Sent", "SENT", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Exception", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        } 
    }

I have read through several other problems, but as far as I could tell most others were getting some sort of exception or timeout. Since this appears as though it connects I am not sure what the issue is. Would it throw an exception if it were unable to access the server? If I throw a different IP into the server it will throw an exception.

Also I have tried both the IP of the server and mail.xx.com and it will not throw an exception with either but if I put any other addresses it will fail.

Thanks in advance for anyhelp!


Solution

  • The issues i had was that even the domain admins did not have access to the SMTP relay. I had to make sure the user was authenticated in the SMTP relay. Regardless of the fact the authenicating user was the same as the email adress used, that user did not have access. Once corrected it was able to send without issue.