How to Protect Your Microsoft 365 Domain from Spam with FortiMail

This article presents the basic configuration to protect a Microsoft (Office) 365 tenant with FortiMail and perform inbound and outbound email inspection. The configuration is the same for both the on-premises and cloud solutions.
CONFIGURE YOUR MICROSOFT 365 DOMAIN
We assume that your Microsoft 365 tenant is operational with your own domain and is sending and receiving email normally.
Remember that the changes being made have an impact on services, so they should be executed during a maintenance window.
The next step is to modify your domain’s MX records so they point to your FortiMail instance, whether cloud or on-premises. You must do this in the management console of the provider where you purchased the domain.
It is recommended that the FortiMail instance be pointed to by an A record and that the MX record point to the FQDN of the FortiMail instance.
As an example, review the following:
Registro MX original: ejemplo-com.mail.protection.outlook.com
Registro MX nuevo: mifortimail.ejemplo.com

As an additional step, make sure to add your FortiMail hostname to the SPF record to allow proper email delivery from FortiMail.
CONFIGURE INBOUND MAIL IN FORTIMAIL
- Add the protected Microsoft 365 domain to FortiMail under Domain & User > Domain. As the SMTP server, enter the address of your tenant provided by Microsoft 365. Example: ejemplo-com.mail.protection.outlook.com.

- Make sure to enable Recipient Address Verification and Automatic Removal of Invalid Quarantine Accounts to prevent the creation of fraudulent quarantine accounts and the delivery of email to non-existent accounts.
- Add the Microsoft 365 tenant SMTP server as a trusted relay under System > Mail Setting > Relay Host List.

CONFIGURE INBOUND MAIL IN MS365
The following configuration will allow inbound mail from FortiMail into MS365 once it has been scanned.
Configure an Inbound Transport Rule in MS365
-
Sign in to the Exchange Admin Center.
-
Select Mail Flow > Rules.
-
Click the (+) sign and select Create a new rule from the drop-down menu.
-
Enter a name for the rule.
-
Configure the options as shown in the example. In the Except If section, enter the public IP of your FortiMail.

-
Select the newly created rule and activate it by clicking the Enable button.

CONFIGURE OUTBOUND MAIL IN FORTIMAIL
Now that you have configured inbound mail in both MS365 and FortiMail, you will need to configure the access rules in FortiMail. The “allow” relay rules will let MS365 sources send outbound messages to external domains via FortiMail.
-
Create an IP group containing all the pools used by MS365; go to Profile > Group and create a new group. Add all the MS365 pools. You can get the updated list here: https://learn.microsoft.com/en-us/microsoft-365/enterprise/urls-and-ip-address-ranges?view=o365-worldwide#exchange-online
-
Go to Policy > Access Control > Receiving and create a new access policy like the following example where the IP group created is named “Office365”.

CONFIGURE OUTBOUND MAIL IN MS365
With outbound mail configured in FortiMail, you must configure MS365 so that it delivers outbound mail to FortiMail to be scanned before being delivered to the final recipients.
Create an Outbound Connector in MS365
Outbound connectors are used to route outbound mail to a specific MTA instead of using the MX records configured for the domain.
-
Go to Exchange Admin Center > Mail Flow > Connectors > Add a connector.
-
Select under “Connection from”: Office 365, and under “Connection to”: Partner organization.

-
Enter a name and description, then click Next.
-
Select “Only when I have a transport rule set up that redirects messages to this connector”, then click Next.

-
Select “Route email through these smart hosts”, then enter the hostname of your FortiMail—or an IP address otherwise—and click Next.

-
Select “Any digital certificate, including self-signed certificates” and click Next.

-
During validation, you must enter an email address from the protected domain and verify proper communication with FortiMail.

-
Review the configuration and click “Create connector”.
Create an Outbound Transport Rule
- Go to Mail Flow.
- Click the (+) sign and select “Create a new rule” from the menu.
- In the “Apply this rule if” section, select that the sender is located inside the organization and the recipient is located outside the organization.
- In the “Do the following” section, select redirect the message to a connector and choose the newly created connector.
- In the “Except if” section, select if the headers contain the
'Received'header with value'fortimail'or if the message type is Auto-reply.
The options should look like this:

- Finally, click Next twice and then Finish.
Once this is done, inbound and outbound emails for MS365 will now be protected by FortiMail. You can now apply whichever antivirus and antispam profiles are needed.