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!
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!
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 = "Address@domain.com"
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 = "address@domain.com"
ElseIf Item.Categories = "Important" Then
olBcc = "new@address.com"
Else
Exit Sub
End If
Set olRecip = Item.Recipients.Add(olBcc)