WPF C#Outlook MailItem嵌入多个图像

WPF C#Outlook MailItem嵌入多个图像

问题描述:

我使用下面的代码在mailItem的主体上嵌入图像。WPF C#Outlook MailItem嵌入多个图像

我对“imageCid”有疑问,是否需要为每个图像创建一个?这将如何工作?

如何嵌入多个图像?此代码仅附加最后一张图片。

Microsoft.Office.Interop.Outlook.Attachment attachment = msg.Attachments.Add(@"D:\Users\chart.jpeg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
attachment = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
attachment = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
attachment = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 

string imageCid1 = "[email protected]"; 
string imageCid2 = "[email protected]"; 
string imageCid3 = "[email protected]"; 
string imageCid4 = "[email protected]"; 

attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid1); 
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid2); 
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid3); 
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid4); 

msg.HTMLBody = String.Format("<body><img src=\"cid:{0}\"><br/><img src=\"cid:{1}\"><br/><img src=\"cid:{2}\"><br/><img src=\"cid:{3}\"></body>", imageCid1, imageCid2, imageCid3, imageCid4); 

找到它。我正在覆盖附件。

Microsoft.Office.Interop.Outlook.Attachment attachment1 = msg.Attachments.Add(@"D:\Users\chart.jpeg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
Microsoft.Office.Interop.Outlook.Attachment attachment2 = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
Microsoft.Office.Interop.Outlook.Attachment attachment3 = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 
Microsoft.Office.Interop.Outlook.Attachment attachment4 = msg.Attachments.Add(@"D:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", OlAttachmentType.olEmbeddeditem, null, "Some image display name"); 

string imageCid1 = "[email protected]"; 
string imageCid2 = "[email protected]"; 
string imageCid3 = "[email protected]"; 
string imageCid4 = "[email protected]"; 

attachment1.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid1); 
attachment2.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid2); 
attachment3.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid3); 
attachment4.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid4); 

msg.HTMLBody = String.Format("<body><img src=\"cid:{0}\"><br/><img src=\"cid:{1}\"><br/><img src=\"cid:{2}\"><br/><img src=\"cid:{3}\"></body>", imageCid1, imageCid2, imageCid3, imageCid4);