Compartir a través de


How to: Programmatically Create an E-Mail Item

This example creates an e-mail message in Microsoft Office Outlook.

Applies to: The information in this topic applies to application-level projects for Outlook 2013 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.

Example

Private Sub ThisAddIn_Startup() Handles Me.Startup
    CreateMailItem()
End Sub 

Private Sub CreateMailItem()
    Dim mailItem As Outlook.MailItem = _
        Me.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)
End Sub
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

Concepts

Working with Mail Items

Getting Started Programming Application-Level Add-Ins