EDIT: apparently I have a problem with invoking ItemSend as breakpoint don't break when e-mail is sent
Code is in ThisOutlookSession in Application Object window
====
We started using different signatures for internal only e-mails and for e-mails with at least one external user. It is not much suitable to select proper signature every time manually, so I tried to use Outlook Macro for this
I used this ExtendOffice setup and tried to combine this with array from answer of this post on stackoverflow. My result code is below:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim pa As PropertyAccessor
Dim prompt As String
Dim rAddress As String
Dim lLen As Long
Dim Str1 As String
Dim arrayDomains() As Variant
Dim i As Long
Dim internalFlag As Boolean
Dim externalFlag As Boolean
Dim strExtAdd As String
Dim xMailItem As MailItem
Dim xFSO As Scripting.FileSystemObject
Dim xSignatureFile, xSignaturePath As String
Dim xDoc As Document
Set xMailItem = Item
arrayDomains = Array("internal.com", "subsidiary.com")
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
xSignaturePath = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\" 'CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
rAddress = LCase(pa.GetProperty(PR_SMTP_ADDRESS))
lLen = Len(rAddress) - InStrRev(rAddress, "@")
Str1 = Right(rAddress, lLen)
internalFlag = False
For i = LBound(arrayDomains) To UBound(arrayDomains)
If Str1 = arrayDomains(i) Then
internalFlag = True
Exit For
End If
Next
If internalFlag = False Then
externalFlag = True
End If
Next
If externalFlag = True Then
xSignatureFile = xSignaturePath & "ext.htm"
Else
xSignatureFile = xSignaturePath & "int.htm"
End If
VBA.DoEvents
Set xDoc = xMailItem.GetInspector.WordEditor
xDoc.Application.Selection.EndKey
xDoc.Application.Selection.InsertParagraphAfter
xDoc.Application.Selection.MoveDown Unit:=wdLine, Count:=1
xDoc.Application.Selection.InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
End Sub
The result is that it is not working, I cannot get the signature to the e-mail. The working solution should be, that everyone from parent company and subsidiaries should receive signature with some internal links, and if in the recipients is someone who is not from parent company or subsidiary, the links in signature should be removed.