a_sue’s diary

a_sue の日記 はてなブログ版

Outlook 2007 の送信メールをアカウント別にそのアカウントに自動でBCCする(解決編)

仕分けルールで自動転送するのがエンドレスになるんじゃないか問題は、AutoForwarded をチェックすることで解決。
さっきのコードはその後上手くいかなくなっちゃったので、調べた結果、決定版はこちら。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMe As Recipient
    Set objMe = Item.Recipients.Add("xxxx@m.evernote.com")
    objMe.Type = olBCC
    objMe.Resolve
    Set objMe = Nothing

' ↓ここから追加    
    ' 自動転送の場合は抜ける
    If Item.AutoForwarded Then
        Exit Sub
    End If
    
    Dim MyAddress As String
    
    MyAddress = "yyyy@yyyy.com"
'    If Item.SenderEmailAddress = MyAddress Then
    If Item.SendUsingAccount.SmtpAddress = MyAddress Then
        Set objMe = Item.Recipients.Add(MyAddress)
        objMe.Type = olBCC
        objMe.Resolve
        Set objMe = Nothing
        Exit Sub
    End If
    MyAddress = "zzzz@zzzz.com"
    If Item.SendUsingAccount.SmtpAddress = MyAddress Then
        Set objMe = Item.Recipients.Add(MyAddress)
        objMe.Type = olBCC
        objMe.Resolve
        Set objMe = Nothing
        Exit Sub
    End If
' ↑ここまで
End Sub

今のところ上手くいってるようです。