将文件附加到Outlook

时间:2009-04-03 19:52:00

标签: c# .net winforms outlook

我从MSDN获得了以下代码。代码似乎最初用于Add In,因此我遇到了this.Application.CreateItem(...)部分的问题。从winform app开始,我需要做些什么呢?

private void AddAttachment(){

Outlook.MailItem mail =this.Application.CreateItem(Outlook.OlItemType.olMailItem)as Outlook.MailItem;

mail.Subject = "An attachment for you!";

OpenFileDialog attachment = new OpenFileDialog();

attachment.Title = "Select a file to send";
attachment.ShowDialog();

if (attachment.FileName.Length > 0)
{
    mail.Attachments.Add(
        attachment.FileName,
        Outlook.OlAttachmentType.olByValue,
        1,
        attachment.FileName);
    mail.Recipients.Add("Armando Pinto ");
    ((Outlook._MailItem)mail).Send();
}

1 个答案:

答案 0 :(得分:0)

确保您在VSTO项目中,以便加载Office References。如果它在那里抱怨,可能是因为它不知道你想要创建什么对象。