简体   繁体   English

使用C#以编程方式将OLE对象插入Outlook电子邮件

[英]Programmatically insert OLE object into Outlook email with C#

I am trying to embed an Excel file into an Outlook email message. 我正在尝试将Excel文件嵌入到Outlook电子邮件中。 I am setting the attachment type to "OlAttachmentType.olOLE", however when the message is created, the Excel document arrives as an attachment. 我将附件类型设置为“ OlAttachmentType.olOLE”,但是,在创建消息时,Excel文档作为附件到达。

Below is my code. 下面是我的代码。 It seems pretty straightforward, but it does not work as expected. 看起来很简单,但是却无法正常工作。

        var application = new Microsoft.Office.Interop.Outlook.Application();
        var message = (MailItem)application.CreateItem(OlItemType.olMailItem);
        var path = @"C:\Excel\Workbook.xlsx";
        var missing = System.Type.Missing;

        message.Attachments.Add(path, OlAttachmentType.olOLE, 1, missing);
        message.SaveAs(@"C:\Excel\Workbook.msg", OlSaveAsType.olMSG);

        application.Quit();

Outlook Object Model would not let you insert embedded OLE objects - the best you can do is access existing ones. Outlook对象模型不允许您插入嵌入式OLE对象-最好的办法是访问现有的对象。 Inserting OLE attachments is non-trivial even on the Extended MAPI level - you will need to create a specially formatted IStorage for the attachment, then populate its data in the format that only the host that will handle it later can understand. 即使在扩展MAPI级别上,插入OLE附件也不是一件容易的事-您将需要为附件创建特殊格式的IStorage,然后以只有稍后处理它的主机才能理解的格式填充其数据。 You will also need to provide the bitmap with the preview and insert the appropriate placeholder in the RTF body. 您还需要为位图提供预览,然后在RTF主体中插入适当的占位符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM