none
Override image URL conversion RRS feed

  • Question

  • Just wondering if there's a way to keep an image url as is, without it resolving to a cid: value?  After execution of the following line, Outlook 2007 seems to parse the message and change all images to attachments on a REPLY email.  For NEW messages it will keep the link as is.  I would like this same behavior for REPLIES. 

    olMailItem.HTMLBody = olMailItem.HTMLBody.substring( ... &  "<img src=" & quote & "http://somesite.com/someimage.gif" & quote  ... etc.

    (Visual Studio 2008, VSTO 2008, Outlook 2007)




    • Edited by J Wagner Saturday, October 15, 2011 1:02 PM
    Saturday, October 15, 2011 5:10 AM

All replies

  • Hi J,

    Thanks for posting in the MSDN Forum.

    I think you can override it via String Regex. In you mail item the img tag will like this "<img width="262" height="262" id="_x0000_i1025" src="cid:image001.jpg@01CC8CF7.1F7D7C30" alt="Description: https://byfiles.storage.live.com/y1pW770H_hf6M__sIdIalPT72m7k96RYNdjH9gVt5xCIXV_B39wrI5bv5VQ6wx7eLjHQLWhVfOisjw/picture2.JPG?psid=1">" you will get the url form the alt property. please do replace via Regex.

    If you have any questions please feel free to let me know.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 17, 2011 10:12 AM
    Moderator
  • Maybe I'll explain what I'm trying to do in another way:

    Reply to email:  

    1. ACTION:  addin inserts img tag into current message   "<img src=" & quote & "http://somesite.com/someimage.gif" & quote  ... etc.
    2. RESULT:  Outlook creates inline image with CID value.
    3. REQUIREMENT:  Tag should stay as is and not have outlook transform it into a CID value.

    New email:

    1. ACTION:  addin inserts img tag into current message  "<img src=" & quote & "http://somesite.com/someimage.gif" & quote  ... etc.
    2. RESULT:  Outlook leaves the tag as is (no CID value)

    I would like the REPLY to be processed the same way that Outlook handles NEW Messages.  We are not concerned with users not having internet access to download the image, our requirement is for the recipient to receive the most recent image. 

    Tuesday, October 18, 2011 1:58 PM
  • Hi J,

     

    When you send the mail, the mail server while download the image file to mail as an attachment by default action. I think we are not able to block it on client side. And if you want to override it you need to modify mail item’s HTMLBody. You need replace the HTMLBody source string via Regex as I mentioned.

     

    If I have misunderstood anything please feel free to let me know.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 19, 2011 7:20 AM
    Moderator
  • Hi Tom,

    I don't think you quite understand what I am trying to do.  Moving the url into alt as a description, does not help in this situation.  I want the 'src=' to stay untouched, as it does when one creates a new email.  In fact, if you insert a picture (using the outlook ribbon) into a REPLY, it will also leave prior img tags untouched.  Why is it that if you touch HTMLBODY via code, it resorts to it's default action.  Can I not block this default action via code?

    Thanks.

    Thursday, October 20, 2011 1:44 AM
  • Hi J,

     

    I think I can catch your goal. Please try this snippet. It will approach your goal. It works fine on my side.

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    using System.Text.RegularExpressions;
    
    namespace OutlookAddIn10
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
            }
    
            void Application_NewMailEx(string EntryIDCollection)
            {
                Outlook.MailItem objMailItem = Application.Session.GetItemFromID(EntryIDCollection);
                if (objMailItem != null)
                {
                    string s = Regex.Replace(objMailItem.HTMLBody, "(src=\")+(.*?)\"", "");
                    objMailItem.HTMLBody = Regex.Replace(s, "(alt=\"Description:+)\\s+(.*?)\"", "src=\"$2\"");
                    objMailItem.Save();
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }
    

     

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 1, 2011 8:29 AM
    Moderator
  • In looking at the code, doesn't that event only fire when a message is received in Outlook?  I am looking at a Reply message into which I want to insert the image without Outlook initiating its CID conversion.  Am I misinterpreting your response?

    Reply to email:  

    1. ACTION:  addin inserts img tag into current message   "<img src=" & quote & "http://somesite.com/someimage.gif" & quote  ... etc.
    2. RESULT:  Outlook creates inline image with CID value.  ** Don't want this to happen **

    I can add a registry entry to stop this from happening as in 'Send pictures with document', however I was trying to avoid taking this step.

      

    Thursday, November 10, 2011 2:00 AM
  • Hi,

    Just wondering if you were able to find a reliable solution to this problem.  I've been stressing out for the last several days trying to solve this myself. I've searched all over, and yours is the first post that mentioned the fact that NEW messages seem to be handled correctly, while replies have the image downloaded/included as an attachment.  (or, as I've also found, they'll remove the image/link entirely if they can't resolve the image...  I was trying with an image I hadn't pushed to my live site yet and learned that little twist as well).

    Anyway, hoping you get this an update your progress!!!

    Thanks.

    Friday, May 25, 2012 3:53 AM
  • Hi,

    I ended up changing the registry entry, as nothing else seemed to work.

    Wednesday, June 13, 2012 7:57 PM
  • Ok, cool.  Looks like I'm going to have to go that way.  

    Thanks for the update!  

    One more question while I am at it though:

    I'm building an add-in that will be deployed on (hopefully) many customer machines.  If I go the registry way, I can definitely include instructions on how to set the registry value themselves, but ideally, I'd still like to avoid that.  What did you end up doing?  Was this just a problem you were solving on your local machine, or were you in the same boat?  If you were in the same boat, how are you handling it?  If you happen to have solved the registry issue programatically, would you be willing to share the code snipet?  

    I'm a web programmer mostly, trying to move to windows development, so quite honestly, I've never had to set / deal with the registry before.  Is this entry something I can attempt to set via my installer / application, or is that just another fools errand that'll leave me searching for an answer that doesn't exist.

    Thanks again.

    Saturday, July 7, 2012 4:24 AM
  • Hello

    Are you able to clarify which registry entry controls the prevention of converting the img src from http to cid please?

    Thank you

    Rick

    Tuesday, July 24, 2012 10:31 AM