I am trying to use the MailMessage class to construct e-mail messages that are transmitted to an SMTP server for delivery using the SmtpClient class. My email is configured on outlook through an exchange server. I had the following doubts with regards to the above implementation:
1) What is the difference between an Exchange Server and a SMTP server?
2) In my case, my outlook is configured on an exchange server using my credentials.How do I find the SMTP address so that i am able to implement the MailMessage Class?
3) Any ideas of sending emails through the application based on the exchange server if the above implementation technique is not feasible?
I am using Visual studio 2008, framework 3.5 SP1, working on winforms application with C# as the language. Please help me clear my doubts.
EDIT
I am using the following code. It doesn't throw any error, neither does it work. I am trying to send and email to myself bu to no avail
public static void CreateMessageWithAttachment(string server) { // Specify the file to be attached and sent. // This example assumes that a file named Data.xls exists in the // current working directory. string file = "data.xls"; // Create a message and set up the recipients. MailMessage message = new MailMessage( "[email protected]", "[email protected]", "Quarterly data report.", "See the attached spreadsheet."); // Create the file attachment for this e-mail message. Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(file); disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); disposition.ReadDate = System.IO.File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. message.Attachments.Add(data); //Send the message. SmtpClient client = new SmtpClient(server); // Add credentials if the SMTP server requires them. client.Credentials = CredentialCache.DefaultNetworkCredentials; try { client.Send(message); } catch (Exception ex) { Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}", ex.ToString() ); } data.Dispose(); }