How to create Outlook email item using C# and vb.net

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.

create Outlook email item using C-sharp

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.

[VB.net]

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 protected]"
        mailItem.CC = "[email protected]"
        mailItem.Body = "This is the test message"
        mailItem.Importance = Outlook.OlImportance.olImportanceNormal
        mailItem.Display(False)
        mailItem = Nothing
        oApp = Nothing
    End Sub

 
[C#]

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 protected]";
	mailItem.CC = "[email protected]";
	mailItem.Body = "This is the test message";
	mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
	mailItem.Display(false);
	mailItem = null;
	oApp = null;
}

2 thoughts on “How to create Outlook email item using C# and vb.net”

  1. This code is Good To work on the local system. But If the code is deployed on the server. The client system not access the outlook message.
    If u have a solution for that Plsease suggest me.

  2. Hi Sumit..

    This code will run on any machines that contains Outlook locally, so You need to install outlook on  each machine from where you want to open outlook message window.

    thanks

     

     

Comments are closed.