简体   繁体   English

互操作 Outlook - 如何将 bitmap 添加到邮件正文/附件中

[英]Interop Outlook - How to add bitmap into mail body/attachment

I have a button in my application which takes a screenshot of the current window and I try to add the bitmap result into an Outlook mail.我的应用程序中有一个按钮,用于截取当前 window 的屏幕截图,然后我尝试将 bitmap 结果添加到 Outlook 邮件中。

I have created the bitmap of my application with:我创建了我的应用程序的 bitmap:

    FrameworkElement element = (FrameworkElement)o;
    double width = element.ActualWidth;
    double height = element.ActualHeight;
    RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
    DrawingVisual dv = new DrawingVisual();
    using (DrawingContext dc = dv.RenderOpen())
    {
        VisualBrush vb = new VisualBrush(element);
        dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
    }
    bmpCopied.Render(dv);
    Clipboard.SetImage(bmpCopied);

For create the mail, I use the dll Interop.Outlook where I manage my new mail:为了创建邮件,我使用 dll Interop.Outlook 来管理我的新邮件:

    Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
    Microsoft.Office.Interop.Outlook._MailItem mailItem = (Microsoft.Office.Interop.Outlook._MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
    mailItem.Attachments.Add(Clipboard.GetImage());

    mailItem.Display(true);

However, the Attachements.Add() doesn't work with the bitmap and the command crashed without any explanation...但是,Attachements.Add() 不适用于 bitmap 并且命令在没有任何解释的情况下崩溃......

Is there a way to do it without create a temporary file on the computer to attach it to the mail?有没有办法做到这一点,而不在计算机上创建一个临时文件将其附加到邮件?

From the documentation , for the parameter Source when adding Attachments:文档中,对于添加附件时的参数Source

The source of the attachment.附件的来源。 This can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment.这可以是一个文件(由带有文件名的完整文件系统路径表示)或构成附件的 Outlook 项目。

It would appear this isn't possible without saving the image as a file.如果不将图像保存为文件,这似乎是不可能的。

There is a similar question ( Embedding picture to outlook email body ) which provides a method for attaching an image inline from a file which should help you if saving the image to disk is an option.有一个类似的问题( Embedding picture to outlook email body )提供了一种从文件内联附加图像的方法,如果将图像保存到磁盘是一个选项,它应该可以帮助您。

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

相关问题 如何将资源文件夹中的图像作为附件添加并嵌入到 C# 中的 Outlook 邮件正文中 - How to add images from resources folder as attachment and embed into outlook mail body in C# Outlook 互操作添加正文 - Outlook Interop add body text 在C#中将Microsoft.Office.Interop.Outlook.Attachment转换为System.Net.Mail.Attachment - Converting an Microsoft.Office.Interop.Outlook.Attachment to System.Net.Mail.Attachment in c# Outlook Interop,邮件格式 - Outlook Interop, Mail Formatting 如何从内存中制作Outlook邮件附件? - How to make outlook mail attachment from memory? Outlook附件.Add()未显示在邮件正文中 - Outlook attachments.Add() is not showing in mail body 如果附件本身是邮件,如何在 Outlook 中以编程方式访问附件数据 - How to access attachment data programmatically in outlook if attachment is itself a mail C#:将资源添加为Outlook邮件项的附件 - C#: add a resource as an attachment to an Outlook mail item 如何以编程方式在Outlook邮件正文中创建表 - How to create a table in outlook mail body programmatically Outlook AppointmentItem-单击“发送”时如何将一些数据添加到RTF邮件正文中 - Outlook AppointmentItem— how do I add some data into the RTF mail body when “send” is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM