none
Connecting to exchange server using C# to send an email.

    Question

  • Hello,
    My company is using Microsoft Exchange server 2003 and outlook to send emails.  I am put in charge of creating a C# windows form application program to connect to our exchange server and send an email using my credentials.  I'm having a hard time connecting to the exchange server.. I don't really know how to do this.  We want the email set up sort of like:

    Username: "entry"  Password: "entry"
    To: "entry"
    Subject: "entry"
    Body: "Message"

    Send(button)

    I have the basic form made.. And I'm able to send an email over smtp server but I don't think I am doing it through our exchange server.  Any help is appreciated. Thank you.



    Tuesday, February 17, 2009 9:33 PM

All replies

  • There are a few valid ways to send email via exchange the first is using SMTP which is what it sounds like your doing this will work fine the only issue you may have is that if you are sending to external addressees the IP Address your sending from would need to be give relay rights.

    The other method of sending is to send via an Exchange mailbox for this would you need to use one of the Exchange API's for 2003 from .NET the best method is to use WebDAV see http://support.microsoft.com/kb/313128 for a sample. The difference here is that the message your sending will be saved to the sent items folder of the mailbox your sending from and because your using the same method of sending as a normal Exchange user would you don't need to worry about tripping over SPAM filters etc.

    Cheers
    Glen
    Tuesday, February 17, 2009 11:17 PM
  • Okay so,
    Say I wanted to go the SMTP route.  I want to set it up so I can send an email from my email address in the exchange server.. so basically all I would have to do is type in my user name and password for the exchange server and then I can send an email FROM ME without even putting my email address in a "from" line.  What I'm having trouble with is getting this to work.  I have code, it sends an email... but I don't have the username and password part down correct.  I know this because the email will still send, even if I type in a different user name or password.  Is there a way to connect to the exchange server to pull this information from it?  I don't know how to code that part.


    Wednesday, February 18, 2009 4:28 PM
  • i have tried but no success

    server error is

    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

    my exchange server is 2010

    can u help me

     


    ibm@cd
    Tuesday, January 10, 2012 11:32 AM
  • You need to provide more information about what your doing and a code sample of what is failing.

    Cheers
    Glen

    Wednesday, January 11, 2012 7:25 AM
  • I am using SmtpClient

                MailMessage message = new MailMessage();
                SmtpClient smtpClient = new SmtpClient();
                string msg = string.Empty;
                try
                {
                    MailAddress fromAddress = new MailAddress(from);
                    message.From = fromAddress;
                    message.To.Add(toList);

                  
                    message.Subject = subject;

                    message.IsBodyHtml = true;
                    message.Body = body;
                    smtpClient.Timeout = 50000;
                    smtpClient.Host = host; //exchange server name
                    smtpClient.Port = port;

                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = new System.Net.NetworkCredential("myid@exchange.com", "password");
                    smtpClient.EnableSsl = true;
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                    smtpClient.Send(message);
                    message.Dispose();


    ibm@cd
    Wednesday, January 11, 2012 11:29 AM
  • What version of Exchange ? if its 2007 or 2010 make sure your sending via a Hub Server other server roles won't accept SMTP traffic

    Also if your going to send authenticated emails than i would suggest you try to use client port 589

    To see if your connecting enable verbose logging on the Hub Server for SMTP http://technet.microsoft.com/en-us/library/bb124531(EXCHG.80).aspx

    The error you getting is basically saying you can't connect to the Port 25 on the server your trying to send through this maybe caused be a few things a lot of AV program (and ISP's) block outgoing port 25 so try testing this first from Telnet program http://support.microsoft.com/kb/153119

    Also refer to http://www.systemnetmail.com/

    Cheers
    Glen

    Thursday, January 12, 2012 5:51 AM