Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Outlook email with an @Mention for a contact in the body

I'm generating an Outlook email, which has an HTML body, via Excel VBA.

I would like to @ a contact in my organisation in the body. e.g. @Bloggs, Joe

Mention is a functionality added to Outlook in the last few years and it seems it's an HTML link. How do I ensure Outlook formats this mention correctly?

Would the below suffice for Outlook to recognise this as a mention?

<a href="mailto:[email protected]">
<span style='font-family:"Arial",sans-serif;mso-no-proof:yes;text-decoration:none; text-underline:none'>@Bloggs, Joe</span>
like image 869
EC99 Avatar asked Oct 03 '19 07:10

EC99


1 Answers

The trick seems to be in the id of the anchor tag:

  • Each ID needs to start with OWAAM (I suspect it stands for "Outlook Web Access At Mention", as that's where the feature originated), followed by a 32 character hex value, followed by Z.
  • Each ID needs to be unique in the document, but doesn't have to be unique for the mention, so you can just generate a new one for each mention.

For instance:

<a id="OWAAM954ABFF4E42A42989C2192D3F93BB32DZ" 
   href="mailto:[email protected]">Immo Landwerth</a>

This code works for me (C#):

static string GetMentionHtml(string email, string name)
{
    var guid = Guid.NewGuid().ToString("N").ToUpper();
    var id = $"OWAAM{guid}Z";
    return = $"<a id=\"{id}\" href=\"mailto:{email}\">@{name}</a>";
}

And in case you need it in VBA:

Function GetMentionHtml(email As String, name As String) As String
    Dim id As String
    Dim html As String    
    id = "OWAAM" & NewGuid() & "Z"
    html = "<a id=""" & id & """ href=""mailto:" & email & """>@" & name & "</a>"
    GetMentionHtml = html
End Function

' Sadly there is no "get me a GUID" in VBA, but this is good enough.
' Source: https://www.codegrepper.com/code-examples/vb/excel+vba+generate+guid+uuid
Function NewGuid() As String
    Dim k&, h$
    NewGuid = Space(36)
    For k = 1 To Len(NewGuid)
        Randomize
        Select Case k
            Case 9, 14, 19, 24: h = "-"
            Case 15:            h = "4"
            Case 20:            h = Hex(Rnd * 3 + 8)
            Case Else:          h = Hex(Rnd * 15)
        End Select
        Mid$(NewGuid, k, 1) = h
    Next
    NewGuid = Replace(NewGuid, "-", vbNullString, Compare:=vbTextCompare)
End Function
like image 172
Immo Landwerth Avatar answered Sep 21 '22 23:09

Immo Landwerth