0

Estou utilizando o código abaixo e consigo inserir uma imagem no corpo do email. Como faria para adicionar mais imagens? É necessário criar multiplos "imageCid"? O código abaixo só mostra a última imagem.

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 = "image001.jpg@123";
string imageCid2 = "image002.jpg@123";
string imageCid3 = "image003.jpg@123";
string imageCid4 = "image004.jpg@123";

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);

1 Resposta 1

0

Eu estava sobrescrevendo o arquivo.

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 = "image001.jpg@123";
string imageCid2 = "image002.jpg@123";
string imageCid3 = "image003.jpg@123";
string imageCid4 = "image004.jpg@123";

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);

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .