Outlook Addin - Blocked Senders List

Add-in Express™ Support Service
That's what is more important than anything else

Outlook Addin - Blocked Senders List
How to add an entry to blocked senders list 
David Wisniewski




Posts: 39
Joined: 2015-11-20
How can I add an entry to the built in blocked senders list in outlook using code in the addin? Is this directly accessible without executing a ribbon command? To see the list I'm talking about, you must click the Home ribbon, then click on the Junk button then click the Junk Email Options option. In the popup that appears, click the tab called Blocked Senders. I would also like to know how to add to the list on the tab called Safe Senders. I can't seem to figure out how to access this via code.
Posted 08 Dec, 2021 02:29:48 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello David,

The Outlook object model doesn't provide a way to access these lists.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Dec, 2021 04:35:55 Top
David Wisniewski




Posts: 39
Joined: 2015-11-20
This is what I got working, including when multiple items are selected in explorer. Note there are some custom helper functions that I call, as well as an enumerator that I created. They are included in case it helps anyone.

    Private Sub ksMoveToJunk_Action(sender As Object) Handles ksMoveToJunk.Action
        Select Case GetActiveWindowType()
            Case WindowType.Explorer
                Dim comExplorer As Outlook.Explorer = OutlookApp.ActiveExplorer
                Dim comExplorerCommandbars As Microsoft.Office.Core.CommandBars = comExplorer.CommandBars
                'check if there is more than one item selected
                Dim comSelection As Outlook.Selection = comExplorer.Selection
                If comSelection.Count = 1 Then
                    comExplorerCommandbars.ExecuteMso("JunkEmailAddToBlockedSendersList")
                Else
                    Dim comMailItem As Outlook.MailItem
                    Dim comInspector As Outlook.Inspector
                    Dim comInspectorCommandbars As Microsoft.Office.Core.CommandBars
                    'loop through each selected item, display it, handle the inspector, and junk it
                    For intCounter As Integer = comSelection.Count To 1 Step -1
                        comMailItem = comSelection(intCounter)
                        comMailItem.Display()
                        comInspector = comMailItem.GetInspector
                        comInspectorCommandbars = comInspector.CommandBars
                        comInspectorCommandbars.ExecuteMso("JunkEmailAddToBlockedSendersList")
                        ReleaseCOM(comInspectorCommandbars)
                        ReleaseCOM(comInspector)
                        ReleaseCOM(comMailItem)
                    Next
                End If
                ReleaseCOM(comSelection)
                ReleaseCOM(comExplorerCommandbars)
                ReleaseCOM(comExplorer)
            Case WindowType.Reader 'user is reading an email in an inspector
                Dim comInspector As Outlook.Inspector = OutlookApp.ActiveInspector
                Dim comCommandbars As Microsoft.Office.Core.CommandBars = comInspector.CommandBars
                comCommandbars.ExecuteMso("JunkEmailAddToBlockedSendersList")
                ReleaseCOM(comCommandbars)
                ReleaseCOM(comInspector)
        End Select
    End Sub

    Public Function GetActiveWindowType() As WindowType
        Dim result As WindowType
        Dim comActiveWindow As Object = OutlookApp.ActiveWindow
        If TypeOf comActiveWindow Is Outlook.Explorer Then
            result = WindowType.Explorer
        ElseIf TypeOf comActiveWindow Is Outlook.Inspector Then
            Dim comActiveInspector As Outlook.Inspector = OutlookApp.ActiveInspector
            Dim comDoc As Word.Document = comActiveInspector.WordEditor
            Select Case comDoc.ProtectionType
                Case Word.WdProtectionType.wdAllowOnlyReading
                    result = WindowType.Reader
                Case Word.WdProtectionType.wdNoProtection
                    result = WindowType.Composer
                Case Else
                    result = WindowType.Inspector_Error
            End Select
            ReleaseCOM(comDoc)
            ReleaseCOM(comActiveInspector)
        Else
            result = WindowType.Explorer_Error
        End If
        ReleaseCOM(comActiveWindow)
        Return result
    End Function

    Public Enum WindowType As Integer
        Explorer = 0
        Reader = 1
        Composer = 2
        Inspector_Error = 3
        Explorer_Error = 4
    End Enum

    Private Sub ReleaseCOM(ByRef comObject As Object)
        If Not IsNothing(comObject) Then
            Marshal.ReleaseComObject(comObject)
            comObject = Nothing
        End If
    End Sub
Posted 08 Dec, 2021 12:21:40 Top
David Wisniewski




Posts: 39
Joined: 2015-11-20
I updated my response above to include the working code I created, in case anyone else wanted to do something like this.
Posted 08 Dec, 2021 13:54:36 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Thank you, David!

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Dec, 2021 02:27:12 Top