The following code example demonstrates how to create a new Outlook e-mail item with the specified information such as To, subject or body.
In this example we will create a new Outlook email item and display. The following code sample requires a reference of ‘Microsoft.Office.Interop.Outlook’ library in your project.
You can also Specify the level of importance for a created mail item by setting the mailItem.Importance property. You can set the following enum values to the mailItem.
olImportanceLow Item is marked as low importance.
olImportanceNormal Item is marked as medium importance.
olImportanceHigh Item is marked as high importance.
- Private Sub CreateMailItem()
- Dim oApp As Outlook.Application = New Outlook.Application
- Dim mailItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
- mailItem.Subject = "This is the test message"
- mailItem.To = "email@example.com"
- mailItem.CC = "firstname.lastname@example.org"
- mailItem.Body = "This is the test message"
- mailItem.Importance = Outlook.OlImportance.olImportanceNormal
- mailItem = Nothing
- oApp = Nothing
- End Sub
- private void CreateMailItem()
- Outlook.Application oApp = new Outlook.Application();
- Outlook.MailItem mailItem =(Outlook.MailItem) oApp.CreateItem(Outlook.OlItemType.olMailItem);
- mailItem.Subject = "This is the test message";
- mailItem.To = "email@example.com";
- mailItem.CC = "firstname.lastname@example.org";
- mailItem.Body = "This is the test message";
- mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
- mailItem = null;
- oApp = null;