大家好我正在创建一个Outlook 2007加载项。我的项目的资源文件夹中有一堆图像,我在资源文件夹中的图片上做了一个foreach,并创建了foreach项目的按钮,并将按钮背景设置为图像。然后在按钮上单击我想将按钮的图像添加到电子邮件正文。我在下面有这个方法,但是我无法将IMage对象传递给我需要图像完整路径的方法。
请告知如何做!
if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
{
int mailBodyLength;
if (mail.Body == null)
{
mailBodyLength = 0;
}
else
{
mailBodyLength = mail.Body.Length;
}
//Get Image + Link
Image imagePath = image;
object linkAddress = "http://www.pentavida.cl";
//CONTENT-ID
const string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
string contentID = Guid.NewGuid().ToString();
//Attach image
mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);
mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);
//Create and add banner
string banner = string.Format(@"<br/><a href=""{0}"" ><img src=""cid:{1}"" ></a></body>", linkAddress, contentID);
mail.HTMLBody = mail.HTMLBody.Replace("</body>", banner);
mail.Save();
}
提前致谢。
答案 0 :(得分:1)
为什么不将图像保存到临时文件夹,然后在将其附加到邮件对象后立即将其删除:
using System.Reflection;
using System.IO;
//Attach image
object missing = System.Reflection.Missing.Value;
Image car = OutlookAddIn1.Properties.Resources.Car;
string path = Path.Combine(Path.GetTempPath(), "Car.jpg");
car.Save(path);
if (File.Exists(path))
{
mail.Attachments.Add(path,Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,missing, missing);
File.Delete(path);
}
答案 1 :(得分:1)
mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);
到
mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperty(schemaPrAttachContentId, contentId);