以程式設計方式建立電子郵件項目

本範例會在 Microsoft Office Outlook 中建立電子郵件訊息。

適用對象: 本主題資訊適用於 Outlook 的 VSTO 增益集專案。 如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能

範例

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);
}