How to add mail account to block sender O365

Today I will talk a little about O365 configuration, in this case I will explain how to add an email account to the black list in O365. All this task will be done by PowerShell, so let’s begin!

First of all, we need to connect to the O365:

$cred=Get-credential
$sesion=New-PSSession -ConfigurationName Microsoft.Exchange -connectionUri "https://ps.outlook.com/powershell" -Credential $cred -Authentication basic -Allowredirection
Import-PsSession $sesion

After typing all this parameters will be connected to the Exchange Online console, but if you want more information about how to connect, you can click on http://help.outlook.com/es-es/beta/cc952755.aspx to get more info about the process

Since we are connected, we can start doing our work, in this case we are configuring the user with email alberto@myfakedomain.com, in the trustedsendersandomains we can configure the white list for this user, while the parameter blockedsendersanddomains are the black list for this user. Let’s give an example:

Set-MailboxJunkEmailConfiguration -Identity alberto@myfakedomain.com -TrustedSendersAndDomains nofakedomain.com,user1@nofakedomain.com -BlockedSendersAndDomains userspam@spamdomain.com,spamdomain.com,microsoft.com

So, your next question will be, what If I want to check which domains and users are configured for a certain user? We can do it with the following:

Get-MailboxJunkEmailConfiguration -Identity alberto@fakedomain.com

Easy, isn’t it? But I’m sure that you’re waiting for the next level of configuration, I want to configure the black list and white list for all the users at the same time, so let’s begin:

We’re using the same parameters as before, but take into account that we are retrieving all the mailboxes of the users and we are configuring the same parameters:

Get-Mailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains nofakedomain.com,user1@nofakedomain.com -BlockedSendersAndDomains userspam@spamdomain.com,spamdomain.com,microsoft.com

Finally, and as a bonus, we have the following parameter, with this, it is possible to remove the configuration applied for one user in particular (sorry I did no test with all the users in the domain)

Set-MailboxJunkEmailConfiguration alberto@fakedomain.com -TrustedSendersAndDomains @{remove="microsoft.com","userspam@spamdomain"}

I hope this help some of you to understand how to configure the white list and black list in O365 with PowerShell. till the next time!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s