簡體   English   中英

創建 Outlook email 並在正文中添加@Mention

[英]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.

我想@我組織中的一個聯系人。 例如@Bloggs,喬

Mention是在過去幾年中添加到 Outlook 的功能,它似乎是 HTML 鏈接。 如何確保mention格式正確?

以下內容是否足以讓 Outlook 將其識別為提及?

<a href="mailto:Joe.Bloggs@MyOrg.com">
<span style='font-family:"Arial",sans-serif;mso-no-proof:yes;text-decoration:none; text-underline:none'>@Bloggs, Joe</span>

訣竅似乎在錨標簽的id中:

  • 每個 ID 都需要以OWAAM (我懷疑它代表“Outlook Web Access At Mention”,因為這就是該功能的起源),然后是 32 個字符的十六進制值,然后是Z
  • 每個 ID 在文檔中都必須是唯一的,但對於提及而言不必是唯一的,因此您可以為每次提及生成一個新 ID。

例如:

<a id="OWAAM954ABFF4E42A42989C2192D3F93BB32DZ" 
   href="mailto:immo@example.com">Immo Landwerth</a>

此代碼適用於我(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>";
}

如果您在 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM