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开发者_Python百科 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?
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
精彩评论