0
votes

I am trying to send an email via Outlook from within a VB6 program. Everything is working fine so far, and my emails get sent successfully. I would like to send the recipient a link in the body of the email, however, that sends them to a network directory. I can't seem to get a hyperlink in the body of the email.

My code for sending the email thus far looks like this:

Dim outlookApp As Outlook.Application
Dim resultsEmail As Outlook.MailItem

Set outlookApp = CreateObject("Outlook.Application")
Set resultsEmail = Outlook.CreateItem(olMailItem)

    With resultsEmail
        .To = addressee
        .Subject = emailSubject
        .Body = "Results are available here: " & 'somehow put in a hyperlink
        .Send
    End With

addressee and emailSubject are just strings created earlier in the code.

I tried inserting an HTML link using VB6's horrific quote escapes, hoping Outlook would magically sort it out:

"<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"

But it doesn't create the hyperlink, it just puts the resulting text in the body of the email:

<a href="url">Link text</a>

How can I get a link in the generated email?

1
The resulting message in Outlook is HTML right? Not plain text? Because that'll happen if it's plain text. - Mark Allen
Can you show us more of your code, what type is resultsEmail ? - rlb.usa
resultsEmail is an olMailItem. I expanded the code above. Mark - I'm not sure how to set and email to be HTML or plain text via the methods I'm using. - Michael
Thought about your comment Mark and looked a little better at the olmailitem object. Answer posted below. Thanks! Is it a SO faux pas to accept my own answer? - Michael
Oh hey awesome! I didn't think that'd be the answer so I replied via a comment in the first place. :) - Mark Allen

1 Answers

1
votes

Looks like I found the answer and it was deceptively simple. Instead of using .body, I needed to insert the HTML link as I posted and use .HTMLBody instead:

With resultsEmail
    .To = addressee
    .Subject = emailSubject
    .HTMLBody = "Results are available here: " & _
        "<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"
    .Send
End With