c# - Exchange Web Services - Inline Images to outside Email Clients not rendering -


i using ews receive/send emails. sending embedded images in email navigate users page. however, when sending other emails clients gmail , yahoo, images not being set html, text. created console app below demonstrate:

static void main(string[] args)     {         var service = getexchangeservice(networkcreds.credentials);          // create html body content identifier of attachment.         string html = @"<html>                  <head>                  </head>                  <body>                     <img width=100 height=100 id=""1"" src=""cid:party.jpg"">                  </body>                  </html>";          // create email message.         emailmessage email = new emailmessage(service);         email.subject = "test email";         email.body = new messagebody(bodytype.html, html);         email.torecipients.add("test@gmail.com");          // add attachment local copy of email message.         string file = @"c:\projects\party.jpg";         email.attachments.addfileattachment("party.jpg", file);         email.attachments[0].isinline = true;         email.attachments[0].contentid = "party.jpg";          // save copy of email, add attachment, , send email. method results in 3 calls ews.         email.sendandsavecopy();     } 

when receive message in outlook works fine in gmail has following text in body: [cid:party.jpg] file attachment below. know gmail , other clients have extensive processing of images , may case of why it's not displaying correctly. my question if inline images can sent exchange web services other clients , processed correctly?

i know bit late maybe else stuck @ similar problem , solving problem.

you set image base64 encoded image.

in case wanted load preview of existing email in browser control. worked except showing images. replacing them base64 encoded strings worked perfectly.

in example following code should work described:

emailmessage email = new emailmessage(service); email.subject = "test email"; email.body = new messagebody(bodytype.html, html); email.torecipients.add("test@gmail.com"); // add attachment local copy of email message. string file = @"c:\projects\party.jpg"; memorystream stream = new memorystream(); email.attachments.addfileattachment("party.jpg", file).load(stream); byte[] imagebytes = stream.toarray(); // convert byte[] base64 string string base64string = convert.tobase64string(imagebytes); stream.close(); email.attachments[0].isinline = true; email.attachments[0].contentid = "party.jpg";  string html = @"<html>                 <head>                 </head>                 <body>                 <img width=100 height=100 id=""1"" src=""data: image/jpg;base64, " + base64string + """>                 </body>                 </html>"; 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -