Loading images from html that originates from exchange (email)

2 posts, 0 answers
  1. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 05 Mar 2013 Link to this post

    Hi

    I am using the richtextbox to display email content (html) that i have downloaded from exchange via the exchange web api.

    This fails to show images as the images are in the following format - is their anyway i can hook into the richtextbox and resolve these images (i can get them from exchange and save them to local disk or stream)



    <img width="387" height="164" id="Picture_x0020_3" src="cid:image001.png@01CE15AF.A375F5C0">
  2. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 05 Mar 2013 Link to this post

    Never mind - i wrote this method to save and replace the email images with local ones, works well.


    public string GetImageSafeMessageBody(EmailMessage message)
            {
                var ret = message.Body.Text;
                 
                foreach (var att in message.Attachments.OfType<FileAttachment>())
                {
                    if (!String.IsNullOrEmpty(att.ContentId) &&
                        att.ContentType.Contains("image", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var contentId = att.ContentId;
                        var imageType = att.ContentType.Replace("image/", String.Empty);
                        var tempFileName = String.Format("{0}.{1}", contentId, imageType);
                        var tempFile = Path.Combine(Path.GetTempPath(), tempFileName);
                        if (!File.Exists(tempFile))
                        {
                            att.Load(tempFile);
                        }
                        ret = ret.Replace(String.Concat("cid:", contentId), tempFile);
                    }
                }
                 
     
                return ret;
     
            }
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top