html - 为正文中的联系人创建带有@Mention 的 Outlook 电子邮件
问题描述
我正在通过 Excel VBA 生成具有 HTML 正文的 Outlook 电子邮件。
我想@我组织中的一个联系人。例如@Bloggs,乔
Mention
是最近几年添加到 Outlook 的一项功能,它似乎是一个 HTML 链接。如何确保 Outlook 的格式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
推荐阅读
- ios - 前导约束缺少警告
- templates - 多语言 JOOMLA 网站上的默认语言和模板样式
- javascript - Instafeed / html 响应部分
- r - 我可以操作一定数量的行而不在 data.table 上添加额外的索引列吗?
- android - 如何在 Koin 空运行测试中提供参数?
- matlab - 如果我们取单个正弦曲线的 STFT,并在实虚平面上绘制对应于载波频率的值,它应该是多少个点?
- android - 为什么 Android Studio 不安装它的所有组件?
- python - 如何在此类实例方法的单元测试中模拟类实例
- ios - Xcode模拟App错误
- javascript - C# 到 Javascript:相当于 `new MultipartFormDataContent();`