none
HTMLBody executing HTTPRequest RRS feed

  • Question

  • Hello all, 

    I am implementing a web-beacon for some Outlook code that is still being developed. 

    I am successfully able to generate my web-beacon http link, however when I want to send the MailItem out, each time I assign the <img src="link...gif"> to the HTMLBody it attempts to access the server (behavior which I don't want). 

    I want the beacon to fire only when the email arrives as the receiver's end (not in my ItemSend or SentItems). 

    Any suggestions? 

    Friday, March 6, 2015 7:52 AM

Answers

  • Dmitry, Eugene

    Thanks for all the help, got this sorted out via a Cookie that I save. Still downloads the image, but now I'm able to handle the false open on the server end. 

    Thanks once again. 

    • Marked as answer by L.HlModerator Friday, March 27, 2015 2:27 AM
    Wednesday, March 11, 2015 7:46 AM

All replies

  • Hello Rahul,

    What code do you use? And when and where do you run it? Could you please be more specific?

    Friday, March 6, 2015 8:08 AM
  • Hello Eugene (if you want I can post code) but let me explain a bit first. 

    I use the Item's HTMLBody property. 

    What I do is create my beacon (by a web server obviously and return back an image). 

    So essentially what I do is create an img tag..and set the src to my newly created image (so to speak). 

    I run this code in ItemSend. 

    Friday, March 6, 2015 8:11 AM
  • Rahul,

    The forum is for developers. It is expected to see the exact code, not just a description.

    Friday, March 6, 2015 8:26 AM
  • Here you go Eugene (if you want anything else..let me know): 

    Dim strFullPathToGetResponse As String = ""
                    Dim strOldGuidFoundInEmail As String = ""
    				Dim SERVERTRACKINGPATHONLY As String = "myPath"
     
                    strFullPathToGetResponse = SERVERTRACKINGPATHONLY & strGuidCreated 
    				'Extract number from response
                    strItemHTMLBody = oItem.HTMLBody.ToString ' oItemCopy.HTMLBody.ToString
     
                    If strItemHTMLBody.Contains(SERVERTRACKINGPATHONLY) = True Then
                        Dim intSearchLength As Integer = SERVERTRACKINGPATHONLY.Length
     
                        intBodyLength = strItemHTMLBody.IndexOf(SERVERTRACKINGPATHONLY)
     
                        strOldGuidFoundInEmail = strItemHTMLBody.Substring(intBodyLength + intSearchLength, MAX_GUID_LENGTH)
     
                        strTempHtmlBody = strItemHTMLBody.Replace(strOldGuidFoundInEmail, objclsAPIResponse.NewGUID)  'strTempHtmlBody = strItemHTMLBody.Replace(strOldGuidFoundInEmail, strNewGUID)
                    Else
                        intBodyLength = strItemHTMLBody.IndexOf("</body>")
                        strTempHtmlBody = strItemHTMLBody.Substring(0, intBodyLength)
                        strTempHtmlBody = strTempHtmlBody & "<img src=" & """" & strFullPathToGetResponse & """" & " " & "alt=" & """ """ & " " & "height=" & """1""" & " " & "width=" & """1""" & ">" & strItemHTMLBody.Substring(intBodyLength, strItemHTMLBody.Length - intBodyLength)
    					'Setting the img src here..
                   End If
     
                    oItem.HTMLBody = strTempHtmlBody 'Error occurs here
    				'Eugene...error occurs here, it tries to download the image right inside here
    				'which I don't want...
     

    Friday, March 6, 2015 9:02 AM
  • What exactly do you change in the HTML markup? What image reference do you change?
    Friday, March 6, 2015 9:12 AM
  • It's in this line here: 

     intBodyLength = strItemHTMLBody.IndexOf("</body>")
                        strTempHtmlBody = strItemHTMLBody.Substring(0, intBodyLength)
                        strTempHtmlBody = strTempHtmlBody & "<img src=" & """" & strFullPathToGetResponse & """" & " " & "alt=" & """ """ & " " & "height=" & """1""" & " " & "width=" & """1""" & ">" & strItemHTMLBody.Substring(intBodyLength, strItemHTMLBody.Length - intBodyLength)
    					'Setting the img src here..

    The "src" is what I set my beacon to. So essentially when the so-called image gets downloaded, the server is called. However, if I step through this in ItemSend it still contacts the server which then calls the code on the server for the beacon processing. This is what I don't want. 

    Is there a way for the src to suppress the HttpRequest in ItemSend? 

    Friday, March 6, 2015 9:45 AM
  • strFullPathToGetResponse ?
    Friday, March 6, 2015 11:32 AM
  • You cannot do that in HTML body alone without having client side code (COM addin).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, March 6, 2015 2:57 PM
  • Have you tried to reference any simple image? Is it downloaded in the ItemSend event also?
    Friday, March 6, 2015 3:29 PM
  • Eugene and Dmitry, thank you for your replies. 

    Eugene, yes I have tried to reference an image..still gets downloaded. Yes, "strFullPathToGetResponse" is the link to my server (the beacon code)..as soon as this is downloaded, the server is contacted and then my beacon gets prematurely downloaded!

    Dmitry, this is an add-in. Are you saying I need to have extra code to handle this on the add-in side? 

    Friday, March 6, 2015 8:11 PM
  • If this is a COM addin, you can set an extra MIME header when the message is sent. When the message is received, your addin can use Application.NewMailEx event to open the message, read the header, then hit the server.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, March 6, 2015 8:17 PM
  • Thank you for your reply Dmitry, I will keep this in mind. 

    However, what do I do about ItemSend? If I step through the code..and create my <img src="..."> point to my server, it will create a false "Open" on the server (since the code has already been run). 

    Is there anyway to solve this? 

    Friday, March 6, 2015 8:26 PM
  • Why would you need to create an <img> element at all? That was my point - hit the server explicitly from your code instead of leaving it up to the user (when he or she opens the email).

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, March 6, 2015 8:31 PM
  • Oh I see what you mean now Dmitry.

    However, that may not be possible since all users won't have this add-in installed. It would work if all users would have the add-in, but there may be a case where say a user wants to track an email and he/she sends that email..and the client doesn't have the add-in installed. It is because of this the <img> element was needed. 

    Friday, March 6, 2015 8:39 PM
  • Then it won't work. Firstly, Outlook won't show external images at all until the user click on the "download image" dropdown on top of the message. And once image download for that particular message is enabled the image will be retrieved every time the user looks at the message  by opening it in the preview pane, inspector, or when replying/forwarding.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, March 6, 2015 8:43 PM
  • Outlook shouldn't download images right after you changed the HTMLBody property. It tries to download images before displaying the message in the UI. Do you check out the sent email?

    Make sure that you don't open the mail item after you changed the body.

    Have you tried to use any other web server for hosting images? May be the issue comes from the web-beacon? Does it make any sense?

    Friday, March 6, 2015 8:52 PM
  • Dmitry, Eugene

    Thanks for all the help, got this sorted out via a Cookie that I save. Still downloads the image, but now I'm able to handle the false open on the server end. 

    Thanks once again. 

    • Marked as answer by L.HlModerator Friday, March 27, 2015 2:27 AM
    Wednesday, March 11, 2015 7:46 AM