我需要將我的影像(我之前存盤在剪貼板中)粘貼到電子郵件正文中。我該怎么做?
我SendKeys.Send("^v");在新郵件視窗打開后嘗試過,但沒有用。
有沒有辦法將影像直接放入oMailItem.Body = "";?
private void mailsenden() // Versendet die E-Mail
{
Bitmap bmp = new Bitmap(PanelErstmeldung.Width, PanelErstmeldung.Height);
PanelErstmeldung.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
Clipboard.SetDataObject(bmp);
Outlook.Application oApp = new Outlook.Application();
_MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.Subject = "Betriebsst?rung im Bereich " comboBox1.SelectedItem;
oMailItem.To = "[email protected]";
oMailItem.CC = "[email protected]";
oMailItem.Body = ""; // PASTE THE BITMAP bmp HERE in the Body
oMailItem.Display(true); // Or CTRL V it here in the opend Window
}
uj5u.com熱心網友回復:
以下代碼將影像嵌入到訊息正文中:
Attachment attachment = newMail.Attachments.Add(
@"E:\Pictures\image001.jpg", OlAttachmentType.olEmbeddeditem
, null, "Some image display name");
string imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E"
, imageCid
);
newMail.HTMLBody = String.Format("<body><img src=\"cid:{0}\"></body>", imageCid);
如果您仍然在代碼中遇到例外,我建議您使用 VBA 來檢查代碼是否正常作業。
uj5u.com熱心網友回復:
當您將影像粘貼到電子郵件中時,Outlook 會將影像作為檔案附件附加,然后將影像嵌入到正文中。您可以在代碼中執行相同的操作。但是,附加檔案的代碼僅適用于檔案系統上的檔案,因此您需要在附加之前將影像保存到檔案系統,然后才能將其洗掉。您根本不需要使用剪貼板。
它看起來像這樣:
Bitmap bmp = new Bitmap(PanelErstmeldung.Width, PanelErstmeldung.Height);
PanelErstmeldung.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
// Save image to temp file
var tempFileName = Path.GetTempFileName();
bmp.Save(tempFileName, ImageFormat.Jpeg);
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.Subject = "Betriebsst?rung im Bereich " comboBox1.SelectedItem;
oMailItem.To = "[email protected]";
oMailItem.CC = "[email protected]";
var attachment = oMailItem.Attachments.Add(tempFileName);
// Set the Content ID (CID) of the attachment, which we'll use
// in the body of the email
var imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);
// Set HTML body with an <img> using the CID we gave it
oMailItem.HTMLBody = $"<body><img src=\"cid:{imageCid}\"></body>";
oMailItem.Display(true);
File.Delete(tempFileName);
我假設您using在檔案頂部有一個指令,如下所示:
using Outlook = Microsoft.Office.Interop.Outlook;
uj5u.com熱心網友回復:
當前代碼:
using System;
using System.Drawing;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.IO;
using System.Drawing.Imaging;
private void mailsenden() // Versendet die E-Mail {
Bitmap bmp = new Bitmap(PanelErstmeldung.Width, PanelErstmeldung.Height);
PanelErstmeldung.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
// Save image to temp file
var tempFileName = Path.GetTempFileName();
bmp.Save(tempFileName, ImageFormat.Jpeg);
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.Subject = "Betriebsst?rung im Bereich " comboBox1.SelectedItem;
oMailItem.To = "[email protected]";
oMailItem.CC = "[email protected]";
var attachment = oMailItem.Attachments.Add(tempFileName);
// Set the Content ID (CID) of the attachment, which we'll use
// in the body of the email
var imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/417962.html
標籤:
下一篇:URL的標簽無效。不太清楚為什么
