none
Genrate popup message when clicking on URL in a email message RRS feed

  • Question

  • Hi All,

    I developing an outlook add in in which I wand achieve the functionality given:

    When user click on URL contained in an email message the add in check presence of the url in access database. Then popup a message either to continue to navigate to the URL or cancel navigation. How i can achive this. Which EventHandler to be catched.

    Regards,

    Asif Aziz.

    Sunday, January 19, 2014 3:56 PM

All replies

  • Hi All,<o:p></o:p>

    I developing an outlook add in in VB.net in which I wand achieve the functionality given:<o:p></o:p>

    When user click on URL contained in an email message the add in check presence of the url in access database. Then popup a message either to continue to navigate to the URL or cancel navigation. How i can achive this. Which EventHandler to be catched.<o:p></o:p>

    Regards,<o:p></o:p>

    Asif Aziz.<o:p></o:p>

    Sunday, January 19, 2014 4:05 PM
  • Hi Asif_Aziz,

    Firstly url hyperlinks in outlook dispose no events for developers. We cannot handle the url click event with managed code. Maybe you could make it work with some windows API, but managed code is not responsible for that. You could ask some WinAPI experts for help I think.

    But maybe you could try another way, to check all the url links in the mail’s HTMLBody when a user opens it. Use Regular Expression to find all the url links, and determine if they exist in the database. If you don’t want the user to navigate to the url, you could do something do disable it. Example code:

    Outlook.Inspectors inspectors;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                inspectors = this.Application.Inspectors;
                inspectors.NewInspector += inspectors_NewInspector;
            }
    
            void inspectors_NewInspector(Outlook.Inspector Inspector)
            {
                Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
                if (mailItem != null)
                {
                    if (mailItem.EntryID == null)
                    {
                        //When create a new mail.
                    }
                    else
                    {
                        //When open a received mail.
                        string htmlBody = mailItem.HTMLBody;
                        Regex regex = new Regex(@"href=\""(.*?)\""", RegexOptions.Singleline);
                        MatchCollection mc = regex.Matches(htmlBody);
                        foreach (Match m in mc)
                        {
                            string url = m.Groups[1].Value;
                            //Determine if the url exists in the database, if doesn't, you could just remove it
                            //then update the HTMLBody property of MailItem object.
                        }
                    }
                }
    
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }

    Please give it a shot. Thanks.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 20, 2014 10:39 AM
    Moderator
  • @Asif,

    There is no any trivial way for handling hyperlinks. The Outlook object model doesn't provide any Click or Navigate event for hyperlinks.

    @Caillen,

    The NewInspector event is not a suitable place for accessing an Outlook item. I'd suggest using the Activate event handler instead.


    Monday, January 20, 2014 11:47 AM
  • In most cases for an email WordMail will be used, in that case in the Inspector.Activate() event (as Eugene noted NewInspector is not a good event to try to work with any strong object references) the Word.Document.Hyperlinks collection can be used to easily find all the hyperlinks.

    There is no event for a click on a hyperlink in either Word or Outlook, but using Inspector.WordEditor returns a Word.Document, and from there the Document.Hyperlinks collection can be parsed to at least find all the hyperlinks and verify them against the database.


    Ken Slovak MVP - Outlook

    Monday, January 20, 2014 3:30 PM
    Moderator
  • Ken,

    The Word Object Model is useless in this case.

    Neither Hyperlinks nor Hyperlink can help. They don't provide any event for handling hyperlinks.

    The simplest solution is to parse a raw html markup. For example, regular expressions can be used. Moreover, an inspector window should be opened for getting access to the WordEditor property.


    Monday, January 20, 2014 3:42 PM
  • I said there was no click event in either the Word or Outlook object models, please read what I said.

    The Word object model is a very useful way to parse and examine hyperlinks in a WordMail object, that's hardly useless. It's at least as useful as regex parsing methods of the markup.


    Ken Slovak MVP - Outlook

    Monday, January 20, 2014 3:53 PM
    Moderator
  • The fact is that an inspector window should be opened for getting access to the WordEditor property. That's what makes the solution useless. Parsing the HTMLBody is more reliable solution.

    Monday, January 20, 2014 4:05 PM
  • Nonsense. If you have a handle to the email item and use GetInspector to get an Inspector you then have access to the Document and its Hyperlinks collection. You get an Inspector but you don't have to display it.

    There is no empirical justification for saying that parsing HTMLBody is more or less reliable than other methods. Both that and Hyperlinks are valid methods.


    Ken Slovak MVP - Outlook

    Monday, January 20, 2014 4:18 PM
    Moderator
  • Okay, I will argue.

    Let's imagine a situation when we need to run another thread(s) for processing the body content. How should we parse the message content from secondary threads? Use the Word object model or just work with a regular text. Do you see anything strange in using the Office object from another threads? ;)

    Moreover, parsing a raw html markup can remove unwanted dependencies (reduce the number of files that should be distributed to users PCs) and avoid issues with threads.

    But sometimes the Word object model can help in customizing the body and reduce the number of code. But not in that case.

    Finally, both approaches are not a panacea.

    Monday, January 20, 2014 4:42 PM
  • As you well know neither the Outlook nor Word object models are suitable for running in a background thread. If a background thread is being used, which was never stated by the poster, then obviously the Word object model can't be used.

    In that case I'd get the content in the foreground thread as a string and parse the string in the background thread.

    Deployment is another problem you mention, but if the PIA's are embedded no additional dependencies need to be deployed. Whether the user has standalone Outlook or the complete Office suite the deployment would be the same and the subset of the Word object model used for WordMail would still be available.

    Nothing I know of with Outlook is foolproof or a panacea for everything. No one ever said that. I mentioned Hyperlinks as a valid alternative to using regex methods, and it is valid for what was proposed, whether you like it or not.

    I have no interest in arguing with you, so I'm done.


    Ken Slovak MVP - Outlook

    Monday, January 20, 2014 5:08 PM
    Moderator