如何自动选择签名?

时间:2019-05-15 15:16:36

标签: outlook-vba

我有几个html格式的签名。我需要根据To:和CC:标签中包含的域选择签名之一。

下面的代码将一个文件的内容合并到邮件正文中。

签名文件中有一些图像。

当我使用

Set xTextStream = xFSO.OpenTextFile(xSignatureFile)
xSignature = xTextStream.ReadAll

图像不包含在邮件中。

我可以用来在邮件中包含图像吗?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim xMailItem As MailItem
Dim xRecipients As Recipients
Dim xRecipient As Recipient
Dim xRcpAddress As String
Dim xSignatureFile, xSignaturePath As String
Dim xFSO As Scripting.FileSystemObject
Dim xTextStream As Scripting.TextStream
Dim xSignature As String
On Error Resume Next
Set xFSO = New Scripting.FileSystemObject
If Item.Class <> olMail Then Exit Sub
Set xMailItem = Item
Set xRecipients = xMailItem.Recipients
xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
For Each xRecipient In xRecipients
    xRcpAddress = xRecipient.Address
    Select Case xRcpAddress
        Case "Email Address 1"
            xSignatureFile = xSignaturePath & "aaa.htm"
            Exit For
        Case "Email Address 2", "Email Address 3"
            xSignatureFile = xSignaturePath & "bbb.htm"
            Exit For
        Case "Email Address 4"
            xSignatureFile = xSignaturePath & "ccc.htm"
            Exit For
    End Select
Next
Set xTextStream = xFSO.OpenTextFile(xSignatureFile)
xSignature = xTextStream.ReadAll
xMailItem.HTMLBody = xMailItem.HTMLBody & "" & xSignature & ""
End Sub

1 个答案:

答案 0 :(得分:1)

签名根本不在Outlook对象模型中公开-解析HTML签名,找出使用的图像,将它们添加为附件,在附件上设置content-id,然后修改签名的标志是您的责任。 HTML通过内容ID引用那些附件图像。您还需要合并现有消息正文和签名的HTML样式。

如果选择使用Redemption,它将公开RDOSignatureApplyTo,这会将给定的签名插入消息中。