开发者

Outlook 2007: How to programmatically select signature based on email recipient (To: CC: BCC:, etc)

The method does not concern me. Whether it is a macro, or somehow automatically fires as the email is sent.

I want to know if there is a way for outlook to automatically assign开发者_运维知识库 a signature based on the recipient.

  • Must work with Outlook 2007. If alternate methods exist, they can be added, referencing which version it works on. A lot of my macros had to be rewritten for 2007.
  • Method is not important, as long as it doesn't involve user interaction other than regular UI usage to send an email.

Thanks.


Based on code from here http://www.rondebruin.nl/win/s1/outlook/signature.htm

You can set it up to be called from Application_ItemSend but that is probably asking for trouble.

Sub With_Variable_Signature()
Dim itm As mailItem
Dim StrSignature As String
Dim sPath As String
Dim recip As Recipient

Set itm = ActiveInspector.currentItem

sPath = Environ("appdata") & "\Microsoft\Signatures\defaultSig.htm"

For Each recip In itm.Recipients
    Debug.Print recip.name
    If recip.name = "somebody"  And recip.type = olTo Then ' or = olcc or = olbcc
        sPath = Environ("appdata") & "\Microsoft\Signatures\customizedSig.htm"
        Exit For
    End If
Next

If Dir(sPath) <> "" Then
    StrSignature = GetBoiler(sPath)
Else
    StrSignature = ""
End If

With itm
    .HTMLBody = .HTMLBody & vbNewLine & vbNewLine & StrSignature
End With  

Set itm = Nothing

End Sub

Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜