将文件附加到Outlook [英] Attach file to Outlook

查看:131
本文介绍了将文件附加到Outlook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码是从 MSDN 中收集的.该代码似乎最初是在外接程序中使用的,因此我在this.Application.CreateItem(...)部分遇到了问题.要从我的winform应用程序中执行此操作,我需要做些什么?

I have the below code that I harvested from MSDN. The code seems to have been originally used in an Add In and as such I am having a problem with the this.Application.CreateItem(...) portion. What do I need to do differently to do this from my 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();
}

推荐答案

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

Make sure you're in a VSTO project so you get the Office References loaded. If it's complaining up there, it's probably because it doesn't know what object you're trying to create.

这篇关于将文件附加到Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆