Outlook msg file create

by Kulin 10. August 2009 01:52

Creating a new Outlook .msg file programmatically in C#

[code:c#]

// Creates a new Outlook Application Instance
Outlook.Application objOutlook = new Outlook.Application();

// Creating a new Outlook Message from the Outlook Application Instance
Outlook.MailItem mic = (Outlook.MailItem)(objOutlook.CreateItem(Outlook.OlItemType.olMailItem));

// Assigns the "TO", "CC" and "BCC" Fields
mic.To = toTextBox.Text;
mic.CC = ccTextBox.Text;
mic.BCC = bccTextBox.Text;

// Assigns the Subject Field
mic.Subject = subjectTextBox.Text;

// Switch the Importance ComboBox to identify the Mail Message Importance Level
switch (importanceComboBox.SelectedItem.ToString())
{
        case "High":
                mic.Importance = Outlook.OlImportance.olImportanceHigh;
                break;         case "Normal":
                mic.Importance = Outlook.OlImportance.olImportanceNormal;
                break;

        case "Low":
                mic.Importance = Outlook.OlImportance.olImportanceLow;
                break;
}

// Define the Mail Message Body. In this example, you can add in HTML content to the mail message body
mic.HTMLBody = messageTextBox.Text;

// Adds Attachment to the Mail Message.
// Note: You could add more than one attachment to the mail message.
// All you need to do is to declare this relative to the number of attachments you have.
mic.Attachments.Add(attachmentOneTextBox.Text,Outlook.OlAttachmentType.olByValue,1,"Attachment Name");

// Save the message to C:\demo.msg. Alternatively you can create a SaveFileDialog to
// allow users to choose where to save the file
mic.SaveAs(@"C:\demo.msg", Outlook.OlSaveAsType.olMSG);

[/code]

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

programming

Comments are closed

Powered by BlogEngine.NET 1.4.5.0 | Theme by Mads Kristensen
Page loaded in 0.031202 seconds.

Disclaimer

The opinions reflected on this blog are entirely my own, and do not reflect the thoughts and/or opinions of my employer in any way.