c# - 将文件附加到 Outlook

标签 c# .net winforms outlook

我从 MSDN 中获取了以下代码.该代码似乎最初是在加载项中使用的,因此我对 this.Application.CreateItem(...) 部分有疑问。要从我的 winform 应用程序执行此操作,我需要做哪些不同的事情?

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 引用。如果它在那里提示,可能是因为它不知道您要创建什么对象。

关于c# - 将文件附加到 Outlook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/715446/

相关文章:

c# - 富文本框高级编辑

c# - 在 C# 中优雅地检查 null 并退出

c# - 绑定(bind)到 TreeView 选定项

c# - 如何读取BenchmarkDotNet的结果表

c# - Azure 函数无法访问 mscorelib.dll 访问被拒绝

c# - 从 Byte[] 中查找未序列化的类型

c# - 在 Visual Studio 2013 中生成 .edmx EF6 的问题

c# - SQLite 错误没有这样的列使用 Entity Framework

c# - 检测 VisibleChanged 是真还是假

wpf - Graphics.CopyFromScreen 有时会捕获透明窗口,有时不会