Try creating an exception-based rule.
In Outlook on the web, go to Settings, then Mail, then Rules, and select Add new rule. Give the rule a name such as Delete Unknown Senders. Under Add a condition, choose Apply to all messages. Under Add an action, choose Delete. Then select Add an exception and choose Sender is in my Contacts. Add another exception and choose Sender is in Safe Senders list. Save the rule. This will delete any incoming message unless the sender is in your Contacts or Safe Senders list.
In Outlook 365 desktop, go to File, then Manage Rules & Alerts, and click New Rule. Choose Apply rule on messages I receive under Start from a blank rule. Click Next without selecting conditions and confirm to apply to all messages. Click Next and do not select any conditions. Under What do you want to do with the message, choose delete it. Click Next, then under Are there any exceptions, select except if the sender is in the specified Address Book and choose Contacts. Also select except if the sender is in the Safe Senders List. Finish the rule and ensure it is enabled.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin