Link to home
Start Free TrialLog in
Avatar of deshaw
deshawFlag for India

asked on

Hyperlinks is becoming non-clickable in RTFBody format

Hi,

I have written one add-in which replaces [a-zA-z]#[0-9] or [a-zA-z]#[0-9]#[0-9] with the hyperlinks. It is working fine(attached portion of code). I found the two problems.
 
   1. The hyperlink (in format of "http://mylink/Q/") is getting converted into clickable link if I use objSafeMail.Body instead of objSafeMail.RTFBody in my code but usage of objSafeMail.Body converts mail format to plain text.

   2. If I use objSafeMail.RTFBody then hyperlink is becoming non-clickable.

Could any one suggest me if in Option#1 (while using objSafeMail.Body) it is possible to persist email format as it is OR in Option#2 is it possible to make replaced hyperlink to clickable,

Thanks.
Private Sub objMailItem_Send(Cancel As Boolean)
    Const Link = "http://mylink/Q/"
    Const REQUEST_PATTERN = "([a-zA-Z]+)(\#[0-9]+){1,2}(?!\#)\b"
    Set oRE = CreateObject("VBScript.Regexp")
    With oRE
        .IgnoreCase = True
        .Global = True
        .MultiLine = True
        .Pattern = REQUEST_PATTERN
    End With
        objMailItem.BodyFormat = olFormatHTML
        objMailItem.Save
        Dim objSafeMail As Redemption.SafeMailItem
        Set objSafeMail = CreateObject("DescoRedemption.SafeMailItem")
        objSafeMail.Item = objMailItem
           Set oMatches = oRE.Execute(objSafeMail.Body)
            objSafeMail.RTFBody = oRE.Replace(objSafeMail.RTFBody, Link & "$1/$&")
            objSafeMail.Save
            
            For Each omatch In oMatches
                objSafeMail.RTFBody = Replace(objSafeMail.RTFBody, "/" & omatch.SubMatches(0) & "#", "/")
                objSafeMail.Save
            Next
End Sub

Open in new window

Avatar of deshaw
deshaw
Flag of India image

ASKER

BlueDavilFan, Could you please help me here. :-)
Thanks.
Avatar of David Lee
I'll see what I can do.  It may be a day or two until I get to this.
Avatar of deshaw

ASKER

Its fine no problems.  Whenver I see your update, the hope for solution get birth. :-)
Thanks for being there.
How about using HTMLBody?
Avatar of deshaw

ASKER

I cannot use HTMLBody with Redemption library. It is read only property.
Thanks.
Yes, you can.  You just don't do it through the SafeMailItem.  Redemption allows you to work around Outlook's built-in security.  Outlook security only comes into play if your code READS the HTMLbody.  You can add to the item's HTMLBody directly without triggering security.  So instead of a line like this

    objSafeMail.RTFBody = oRE.Replace(objSafeMail.RTFBody, Link & "$1/$&")

use something like this

    objMailItem.HTMLBody = oRE.Replace(objSafeMail.HTMLBody, Link & "$1/$&")


Avatar of deshaw

ASKER

BlueDavilFan, I am getting attached error message if I use HTMLBody.
But I could get rid of error message by declaring  "Dim objSafeMail As Redemption.SafeMailItem" statement as  "Dim objSafeMail As Object" but still the behaviour is same it is not conversting links to clickable links.
It seems Outlook doesn't recognize that http://mylink/... formate is hyper link. Is there any explicit way by which we can specify that particular string is hyper link?
Thanks.


err.JPG
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deshaw

ASKER

It has started working in Outlook 2007 fabulously.
Thanks.
Avatar of deshaw

ASKER

thanks
You're welcome.