htmlvbahtml-emailapple-mail

Apple Mail Client - Breaks HTML <a href> tag


I am using VBA to loop through a range, populate a email body & dynamic link, then send to the rows email.

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .SentOnBehalfOfName = "fake_email@fake.com"
        .to = Target
        .Subject = "HALP ME PLZ :)"
        .HTMLBody = "<font size=3>" _
                    & "Hello " & Application.WorksheetFunction.Proper(Split(Target.Offset(, 3), " ")(0)) & ", " _
                    & "<br><br>" _
                    & "<A href= google.com/" & Target.Offset(, 6) & "> CLICK HERE</A>"   '<--- PROBLEM LINE

        .Send
        Target.Offset(, -1) = "Sent"

    End With

The link in the email works fine on Windows & Mac when using Outlook (web or desktop). I am using the a href tag to create the link. However, when the end users are using the Apple Native Email application, the links are broken. What ends up happening is the links are prefixed with text that appear to be in the format x-webdoc://[Random Key][desired link per macro]

x-webdoc://EADECCCC-5736-4513-B65E-B560FCBC32D8www.google.com/test_input

The user is not able to clink the link right from email to complete the workflow so I am wondering:

Is there anyway to modify the code to ensure the link is rendered properly on Outlook and Apple Mail?


Solution

  • Include scheme/protocol in the link, and as TimWilliams pointed out quote the href attribute valve:

    .HTMLBody = "<font size=3>" & "Hello " & Application.WorksheetFunction.Proper(Split(Target.Offset(, 3), " ")(0)) & ", " _
                        & "<br><br>" _
                        & "<a href='https://www.google.com/" & Target.Offset(, 6) & "'> CLICK HERE</a>"