none
Rule for Auto BCC based on Subject RRS feed

  • Question

  • Hello,

    i have the following code which i use in MVBA in Outlook 365, to automatically BCC (to my CRM) all emails that i send, however i want to be able to send without the BCC occasionally, how do i make it not add the BCC if the subject line includes for instance "PRIVATE"?

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objRecip As Recipient
        Dim strMsg As String
        Dim res As Integer
        Dim strBcc As String
        On Error Resume Next
         
        strBcc = "crm@mycrm.com"
         
        Set objRecip = Item.Recipients.Add(strBcc)
        objRecip.Type = olBCC
        If Not objRecip.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 objRecip = Nothing
    End Sub

    Look forward to any comments, and thanks in advance.

    Arne Currie



    • Edited by lazylearnerguy Thursday, September 7, 2017 9:50 PM increased clarity of question
    Thursday, September 7, 2017 9:48 PM

All replies

  • Hi lazylearnerguy,

    You could use InStr method to check if Subject contains "Private"

    Here are the example.

     Dim strSubject As String
    
        strSubject = Item.Subject
    
        If InStr(strSubject, "PRIVATE") > 0 Then
    
        Else
    
        Set objRecip = Item.Recipients.Add(strBcc)
    
        objRecip.Type = olBCC
    
             If Not objRecip.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
    
        End If

    Best Regards,

    Terry

    Friday, September 8, 2017 2:47 AM