How to send hidden web-link by e-mail via MS Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CostasM
    New Member
    • Oct 2012
    • 20

    How to send hidden web-link by e-mail via MS Access

    In my Access database I have a table with 2 fields: DOCNAME (Text) and WEBLINK (Hyperlink).

    I have a VBA code for sending any data from this table by e-mail using CDO.Message function.

    I can send web-links from WEBLINK field, but I need to hide it and instead the actual link to send the data from DOCNAME field.

    For example, I fill the DOCNAME as “Contract” and WEBLINK as “http: //DomainName.com/Contract.pdf” (actual link to the document). Using the following code (part):
    Code:
    objMessage.TextBody = objMessage.TextBody & Split(rst![WEBLINK], "#")(2)
    my recipient gets a link - http: //DomainName.com/Contract.pdf”
    but how to hide it behind the clickable link “Contract” instead, or to send clickable link with the name of document from DOCNAME field.
    Thanks
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    I think as long as your email format is HTML, you can supply an <a> Tag with a HREF Attribute:
    Code:
    <a href="url">link text</a>
    More info: http://www.w3schools.com/html/html_links.asp

    So your code could look something like:
    Code:
    objMessage.TextBody = objMessage.TextBody & "<a href=""" & Split(rst![WEBLINK], "#")(2) & """>" & Split(rst![WEBLINK], "#")(1) & "</a>"
    that is if Split(rst![WEBLINK], "#")(1) contained the text you would like to display to the recipient.

    Comment

    • CostasM
      New Member
      • Oct 2012
      • 20

      #3
      Thanks, jforbes,
      I've changed the code as per your proposal, but now get the line
      as below
      <a href="">http://DomainName.com/Contract.pdf</a>
      in plain text format, not clickable

      Comment

      • jforbes
        Recognized Expert Top Contributor
        • Aug 2014
        • 1107

        #4
        I've not developed code for emails in quite sometime, so I'm not an expert on it.

        It looks like your getting an email with plain text or the text is being added to the email body as plain text. First thing I would do is make sure you are sending an email that is HTML. On the Email as it's being sent, or if you try to forward it, click on the Options Tab and you can see what the format is currently set to (Plain Text, HTML, Rich Text). If it's not HTML, then there is something that needs to be done to create the email in HTML.

        If it is HTML, then you may want to try to use objMessage.HTML Body instead of objMessage.Text Body. I only know this by looking at:http://www.rondebruin.nl/win/s1/cdo.htm

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Keep in mind...

          My company's email policy strips out all HTML and RichText formatting from external emails - this is a common practice due to the high level of spam, phishing, and malware attacks that use concealed URL-Links.

          Personally, and for the same reason my IT-Staff does, at home I have my email client set to force to plan-text.

          In either case, the hyperlink is converted to the URL so it may be a "wasted" effort to attempt this process.

          In any case please read the following thread (and there are several more like this here at Bytes - use he search feature at the top of any page :-) )
          To put a hyperlink from access in body e-mail outlook
          Last edited by zmbd; Feb 4 '16, 10:14 PM.

          Comment

          • CostasM
            New Member
            • Oct 2012
            • 20

            #6
            zmbd, thanks for reply, I know, some times it can be considered us spam, because of hidden URL links, but in my work I need to send a 10-15 attached files (documents) abt 5Mb total.

            As a variant I think to send only links to these documents.
            Documents stored in a cloudstorage but links stored in my database. Any idea how to realize it ?

            After jforbes advice I've changed my code as follows :
            Code:
            objMessage.HTMLBody =  "<a href=" & Split(rst![WEBLINK], "#")(1) &">rst![DOCNAME]</a>"
            It works, but my recepient get get the plain text (rst![DOCNAME])instead of actual value from DOCNAME field.

            How to set value from the field to display ?

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              You should do the SPLIT() first, Follow the link in my prior post, there's a working example and explanation therein... and post#13 in that thread.
              Last edited by zmbd; Feb 5 '16, 01:00 AM.

              Comment

              • jforbes
                Recognized Expert Top Contributor
                • Aug 2014
                • 1107

                #8
                For the .HTMLBody, you just want to create a string that fits into this pattern <a href="url">link text</a>. Where url is your URL and link text is the text to display. It looks like you can use single quotes in place of double quotes, so this <a href='url'>link text</a> should work also. Given this, I think this is more likely to work for you:
                Code:
                objMessage.HTMLBody =  "<a href='" & Split(rst![WEBLINK], "#")(1) &"'>" & rst![DOCNAME] & "</a>"
                Z's suggestion of splitting the Strings first is a pretty good one, especially to debug later. In fact creating the whole string for .HTMLBody up first might be best. This example is overkill, but it might help you:
                Code:
                DIM sLink AS String
                DIM sDocName AS String
                DIM sBody AS String
                
                sBody = ""
                sBody = sBody & "Here is your list of daily reports:  " & vbCRLF
                
                ' Your OpenRecordset command
                ' Your For each OpenRecord
                    sLink = Split(rst![WEBLINK], "#")(1)
                    sDocName = NZ(rst![DOCNAME], sLink )
                
                    ' Using replace is just another way to format the url
                    sBody = sBody & "<a href=""#Link#"">#DocName#</a>" & vbCRLF
                    sBody = Replace(sBody, "#Link#", sLink )
                    sBody = Replace(sBody, "#DocName#", sDocName )
                ' Move to NextRecord
                
                sBody = sBody & "If you have any questions or wish to be " & vbCRLF
                sBody = sBody & "removed from this email blast, contact " & vbCRLF
                sBody = sBody & "CostasM at extension 1234" 
                
                Debug.Print sBody 
                objMessage.HTMLBody = sBody

                Comment

                Working...