[英]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.