Share via


How to: Programmatically create an email item

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

This example creates an email message in Microsoft Office Outlook.

Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.

Example

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    CreateMailItem();
}
       
private void CreateMailItem()
{
    Outlook.MailItem mailItem = (Outlook.MailItem)
        this.Application.CreateItem(Outlook.OlItemType.olMailItem);
    mailItem.Subject = "This is the subject";
    mailItem.To = "someone@example.com";
    mailItem.Body = "This is the message.";
    mailItem.Importance = Outlook.OlImportance.olImportanceLow;
    mailItem.Display(false);
}

See also