'How to choose the signature automaticaly?
I have several signatures in html format. I need to choose one of the signatures according to the domain included in To: and CC: label.
The code below merges the content of one file to the body of the mail.
There are some images in the signature file .
When I use
Set xTextStream = xFSO.OpenTextFile(xSignatureFile)
xSignature = xTextStream.ReadAll
the images aren't included in the mail.
What can I use to include images in the mail?
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
Solution 1:[1]
Signatures are not exposed in the Outlook Object Model at all - it would be your responsibility to parse the HTML signature, figure out the images used, add them as attachments, set the content-id on the attachments, then modify the signature's HTML to refer to those attachment images through the content ids. You would also need to merge the HTML styles of the existing message body and the signature.
If using Redemption is an option (I am its author), it exposes the RDOSignature.ApplyTo
, which would insert the given signature into a message.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |