Jsy
Jsy

Reputation: 9

How to set automatic BCC when body has specific "STRING"

How can I make a script that runs whenever I reply/forward email with specific "STRING" in body and set email address in BCC?

Thank you!

Upvotes: 0

Views: 115

Answers (1)

0m3r
0m3r

Reputation: 12499

Place the code in ThisOutlookSession module,

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim olRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim olBcc As String
    On Error Resume Next

    '// set email address here
    olBcc = "[email protected]"

    Set olRecip = Item.Recipients.Add(olBcc)
    olRecip.Type = olBcc
    If Not olRecip.Resolve Then
        strMsg = "Could not resolve the Bcc recipient. " & _
                 "Do you want still to send the message?"
        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                 "Could Not Resolve Bcc Recipient")
        If res = vbNo Then
            Cancel = True
        End If
    End If

    Set olRecip = Nothing
End Sub

for specific messages, you’ll need to use an IF statement to filter the messages. or category fields, if you need to use series of If statements, filtering by category may be the easiest.

If Item.Categories = "blabla" Then
      olBcc = "[email protected]"

     ElseIf Item.Categories = "Important" Then
      olBcc = "[email protected]"

     Else

      Exit Sub
    End If

    Set olRecip = Item.Recipients.Add(olBcc)

More here

Upvotes: 1

Related Questions