TedSch
New Member
- Outlook version
- Outlook 2016 64 bit
- Email Account
- IMAP
I am on every political email list asking for money. Even though I unsubscribed, they were still coming in different candidates. There are a few major companies (political SaaS) that swap your name around to the difference candidates even when you are not living in the same state. If you look at the email's HTML source, you'll see ActBlue, Npvan, Sendgrid as the main ones if you are a democrat. There doesn't seem to be a way to make a rule that acts on hidden HTML source test. Below you'Il see the code I assigned to a button on the quick access tool bar. It works. It is easy to expand the array for any newcomers. Let me know if there is a better way. Would there be a way to make this a custom rule that operates when new emails arrive? Thank you Slipstick for being the go-to for Outlook.
Public Function ArrayTest(strToTest As String) As Boolean
Dim strTxtArray() As Variant
Dim k As Integer
strToTest = UCase(strToTest)
strTxtArray() = Array("ACTBLUE", "SENDGRID", "ACTIONNETWORK", "NPGVAN", "ACTIONKIT", "USO.ORG", "AMERICARES.ORG", "SIERRACLUB.ORG")
For k = LBound(strTxtArray) To UBound(strTxtArray)
'Debug.Print strTxtArray(k)
'Debug.Print strToTest
If InStr(strToTest, strTxtArray(k)) > 0 Then
ArrayTest = True
Exit For
Else
ArrayTest = False
End If
Next k
End Function
Public Sub DelPoliticalSpam()
Dim oInboxFolder As MAPIFolder
Dim obj As Object
Dim olApp As Outlook.Application
Dim objExpl As Outlook.Explorer
Dim strBodyHTML As String
Dim strTypeName As String
'On Error Resume Next
Set olApp = Application
Set objExpl = olApp.ActiveExplorer
Set oInboxFolder = ReturnFolder(strInbox1, olFolderInbox)
For Each obj In oInboxFolder.Items
strTypeName = TypeName(obj)
' Debug.Print strTypeName
If strTypeName = "MailItem" Then
strBodyHTML = obj.HTMLBody
If ArrayTest(strBodyHTML) Then
'MsgBox (strBodyHTML)
obj.Delete
End If
End If
Next obj
'return to inbox
objExpl.SelectFolder ReturnFolder(strInbox1, olFolderInbox)
Set obj = Nothing
Set oInboxFolder = Nothing
End Sub
Public Function ArrayTest(strToTest As String) As Boolean
Dim strTxtArray() As Variant
Dim k As Integer
strToTest = UCase(strToTest)
strTxtArray() = Array("ACTBLUE", "SENDGRID", "ACTIONNETWORK", "NPGVAN", "ACTIONKIT", "USO.ORG", "AMERICARES.ORG", "SIERRACLUB.ORG")
For k = LBound(strTxtArray) To UBound(strTxtArray)
'Debug.Print strTxtArray(k)
'Debug.Print strToTest
If InStr(strToTest, strTxtArray(k)) > 0 Then
ArrayTest = True
Exit For
Else
ArrayTest = False
End If
Next k
End Function
Public Sub DelPoliticalSpam()
Dim oInboxFolder As MAPIFolder
Dim obj As Object
Dim olApp As Outlook.Application
Dim objExpl As Outlook.Explorer
Dim strBodyHTML As String
Dim strTypeName As String
'On Error Resume Next
Set olApp = Application
Set objExpl = olApp.ActiveExplorer
Set oInboxFolder = ReturnFolder(strInbox1, olFolderInbox)
For Each obj In oInboxFolder.Items
strTypeName = TypeName(obj)
' Debug.Print strTypeName
If strTypeName = "MailItem" Then
strBodyHTML = obj.HTMLBody
If ArrayTest(strBodyHTML) Then
'MsgBox (strBodyHTML)
obj.Delete
End If
End If
Next obj
'return to inbox
objExpl.SelectFolder ReturnFolder(strInbox1, olFolderInbox)
Set obj = Nothing
Set oInboxFolder = Nothing
End Sub