The difference between sending MailMessage to an Exchange server and sending to an SMTP server

I am trying to use the MailMessage class to create email messages that are sent to an SMTP server for delivery using the SmtpClient class. My email is configured in Outlook through the exchange server. I had the following doubts about the above implementation:

1) What is the difference between an Exchange server and an SMTP server?

2) In my case, my appearance is configured on the exchange server using my credentials. How to find the SMTP address so that I can implement the MailMessage class?

3) Any ideas on sending letters through an application based on an exchange server, if the above implementation method is not possible?

I am using Visual studio 2008, framework 3.5 SP1, working on a winforms application with C # as a language. Please help me sort out my doubts.

EDIT

I am using the following code. This does not cause any error, and it does not work. I try to send and email to myself 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(
           "ben@contoso.com",
           "ben@contoso.com",
           "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();
    }
+5
source share
2 answers

1) What is the difference between an Exchange server and an SMTP server?

The Exchange server contains more information.

2) In my case, my appearance is configured on the exchange server using my credentials. How to find the SMTP address so that I can implement the MailMessage class?

Outlook → Tools → Accounts → Change Account.

, . 25 SMTP-. Exchange .

3) , ?

MailMessage, SmtpClient.

Exchange: MailMessage " "

+5

SMTP - , , . .

SMTP- - ( ), .

MS Exchange SMTP , .

+2

All Articles