Skip to main content
Visitor III
June 25, 2026
Solved

Relaying mails from Exchange Online via Fortimail to external in a secure way

  • June 25, 2026
  • 7 replies
  • 110 views

Hello all,

we have an Exchange Hybrid setup with all our mailboxes on-prem. We need to let graph send emails via Exchange Online but we would need to relay these emails via our Fortimail appliance. So the Exchange Online environment does not send these itself without going through the Fortimail first.

 

We found this in the cookbook:

How to integrate FortiMail into Microsoft 365 | FortiMail Appliance and VM 7.4.0 | Fortinet Document Library

And this technical guideline:

Technical Tip: Office365 Secure Relay via FortiMail to avoid unauthorized email relay | Community

And it seems like we can’t let graph talk directly to our on-prem Exchange servers:

https://learn.microsoft.com/en-us/graph/hybrid-rest-support

 

So we wondered how does the Technical Tip from fortinet make sure that we are not risking the relaying of unwanted emails. The authenticated part in the technical guideline does not apply here, no? Because our user mailboxes are all on-prem?

 

And regarding the cookbook: our concern is that we might be at risk of becoming an open relay to all other Exchange Online Tenants because of the access control to allow relaying from all of the Microsoft IPs?

 

What are the necessary steps to - if possible - only let our own MS365 tennant relay emails via FML?

 

Thank you very much and best regards

Best answer by Jean-Philippe_P

Hey again :)

I found some answers to your questions:

 

Thank you for your detailed answers and concerns. Let’s address your questions and clarify how FortiMail’s Access Control works, its limitations, and what you can do to minimize the risk of unauthorized relaying—especially in the context of Microsoft 365 (Exchange Online) integration.

 

  1. How Does FortiMail’s Sender Pattern Matching Work?

Access Control Policy Matching:

  • The sender pattern in FortiMail’s Access Control Policy (e.g., *@yourdomain.com) matches the SMTP envelope sender address (the "MAIL FROM" in the SMTP transaction), not the "From:" header in the email body.
  • This means FortiMail checks the address provided during the SMTP conversation, which is more reliable than the message header but can still be spoofed if the sending system is compromised or not otherwise authenticated.
     
  1. Is This “Safe Enough”?

Potential Risks:

  • Envelope sender spoofing: Anyone with access to Microsoft 365’s infrastructure (or a compromised tenant) could potentially send emails with your domain in the envelope sender, and FortiMail would relay them if the source IP matches the allowed Microsoft IPs and the sender pattern matches.
  • Shared Microsoft IPs: Since Microsoft 365 IPs are shared among all tenants, restricting by source IP alone is not sufficient to prevent other tenants from attempting to relay as your domain.

Why This Is a Concern:

  • If a malicious actor in another tenant (or a compromised account) sends mail with your domain as the envelope sender, and it originates from Microsoft 365 IPs, FortiMail will relay it unless additional controls are in place.
  • This is why relying solely on sender pattern and source IP is not fully secure.
     
  1. How to Make It More Secure?
  1. Restrict by Source and Sender Pattern
  • Continue to use both the Microsoft 365 ISDB object (or explicit IPs) and your domain in the sender pattern.
  • This is a baseline, but not sufficient for high-security needs.
     
  1. Use SMTP Authentication (If Possible)
    Best Practice: Require SMTP authentication for relaying. This is the most secure method, but may not be feasible for Microsoft 365 to FortiMail relay scenarios.
     
  1. Restrict by Additional Headers or Custom Attributes
    If Microsoft 365 can stamp a unique header or attribute (e.g., via a transport rule), you could configure FortiMail to check for this header as an additional relay condition. However, this is not natively supported in all scenarios.
     
  1. Use SPF/DKIM/DMARC Validation
  • FortiMail can perform SPF, DKIM, and DMARC checks on incoming mail. However, these are primarily for anti-spoofing and anti-phishing, not for relay authorization.
  • They help protect your domain’s reputation but do not prevent unauthorized relaying by themselves.
     
  1. Limit Recipients
  • In your Access Control Policy, set the recipient to "External" only, so only emails to external domains are relayed.
  • For internal recipients, ensure that only your on-prem Exchange handles delivery.
     
  1. Monitor and Alert
    Enable logging and alerting for relayed messages, especially those matching your relay policy, to detect any unusual activity quickly.
     
  1. Summary Table: Security Measures

| Control | Effectiveness | Notes | |---------------------------------|--------------|------------------------------------------------------------| | Source IP (Microsoft 365) | Medium | Shared among all tenants | | Sender Pattern (*@yourdomain) | Medium | Can be spoofed in envelope sender | | SMTP Authentication | High | Not always possible with M365 relay | | Custom Header Matching | High | Only if M365 can add unique headers | | SPF/DKIM/DMARC | Medium | Helps with reputation, not relay authorization | | Recipient Restriction | Medium | Prevents internal relay, but not spoofing | | Logging/Alerting | High | Detects abuse quickly |
 

  1. Recommendations for Your Scenario
  1. Continue using sender pattern and source IP restrictions as you have, but understand their limitations.
  2. Restrict relaying to external recipients only in the Access Control Policy.
  3. Monitor logs for any suspicious relay activity.
  4. If possible, work with Microsoft 365 to add a unique header to all emails sent from your tenant, and configure FortiMail to check for this header (if supported).
  5. Regularly review and update your SPF/DKIM/DMARC records to ensure only authorized sources are allowed.
  6. Educate users and administrators about the risks of compromised accounts and monitor for signs of abuse.
     
  1. Follow-up and Clarification Questions

To further assist you, could you clarify:

  • Are you able to configure Microsoft 365 to add custom headers to outbound mail from your tenant?
  • Are there any scenarios where you must relay mail for internal recipients via FortiMail, or is all internal mail handled on-prem?
  • Would you consider using a dedicated connector or authentication mechanism between Microsoft 365 and FortiMail if available?

If you need step-by-step configuration guidance for any of the above recommendations, please specify which area you’d like more detail on.

 

References:

If you have further questions or need more technical detail, please let me know!

7 replies

Jean-Philippe_P
Staff & Editor
Staff & Editor
June 29, 2026

Hello mcakar, 

 

Thank you for using the Community Forum. I will seek to get you an answer or help. We will reply to this thread with an update as soon as possible. 

 

Regards,

Jean-Philippe - Fortinet Community Team
Jean-Philippe_P
Staff & Editor
Staff & Editor
June 30, 2026

Hello,

 

We are still looking for an answer to your question.

 

We will come back to you ASAP.

 

Regards,

Jean-Philippe - Fortinet Community Team
Jean-Philippe_P
Staff & Editor
Staff & Editor
July 1, 2026

Hello again,

 

I found this solution, can you tell us if it helps, please?

 

Let’s break down your scenario and address your concerns about securely relaying emails from Exchange Online (Microsoft 365) via FortiMail, especially in a hybrid setup.

 

  1. Understanding the Risk: Open Relay Concerns

You are correct:

  • Allowing all Microsoft 365 IPs in an Access Control List (ACL) on FortiMail could potentially allow any tenant (not just yours) to relay mail through your FortiMail, risking open relay abuse.
  • Authenticated relay is not applicable here, since your mailboxes are on-prem and Graph cannot authenticate directly to FortiMail as a user.

 

  1. How the Fortinet Technical Tip addresses this

The Technical Tip: Office365 Secure Relay via FortiMail suggests:

  • Using ISDB (Internet Service Database) objects for Microsoft 365/Google IPs in the ACL to simplify management.
  • However, this only restricts by source IP, not by tenant, so it does not prevent other tenants from relaying through your FortiMail if they can spoof sender addresses.

 

  1. How to Restrict Relay to Only Your Tenant
  1. Restrict by Source IP (Not Sufficient Alone)
    Limiting by Microsoft 365 IPs is necessary but not sufficient, as these are shared by all tenants.
  1. Restrict by Sender Pattern
    In your FortiMail Access Control Policy (Policy → Access Control):
    • Set the Sender Pattern to only allow your domain(s) (e.g., *@yourdomain.com).
    • This ensures only emails claiming to be from your domain are accepted for relay.
  1. Restrict by Recipient Pattern
    Optionally, restrict the Recipient Pattern to only allow external domains (not your own), to prevent mail loops.
  1. Use SPF/DKIM/DMARC Checks (Optional)
    While not a direct relay control, enabling these checks can help prevent spoofing.
  1. Use SMTP Authentication (If Possible)
    If you can configure Graph or Exchange Online to authenticate to FortiMail, this is the most secure, but as you noted, this may not be possible in your scenario.
     
  1. Recommended FortiMail ACL Example

| Field | Value | |-------------------|----------------------------------------| | Source | ISDB: Microsoft 365 IPs | | Sender Pattern | @yourdomain.com | | Recipient Pattern | !@yourdomain.com (external only) | | Action | RELAY |

This will only relay messages from your domain, coming from Microsoft 365 IPs, to external recipients.

 

  1. Additional Security Recommendations
  • Monitor Logs: Regularly review FortiMail logs for unusual relay activity.
  • Rate Limiting: Consider rate limiting to prevent abuse.
  • TLS Enforcement: Require TLS for relay connections from Microsoft 365.
     
  1. References
  1. Follow-up & Clarification Questions

To ensure the best solution, please clarify:

  • Are you using FortiMail in Gateway or Transparent mode?
  • Will all relay traffic from Microsoft 365 originate from your tenant’s domain only, or are there exceptions?
  • Do you require relaying for any other internal applications or services?
  • Are you able to configure custom connectors in Microsoft 365 to further restrict relay to your FortiMail’s public IP?

Let us know if you need step-by-step configuration guidance or have additional requirements!

Jean-Philippe - Fortinet Community Team
mcakarAuthor
Visitor III
July 1, 2026

Hello Jean-Philippe,

wow I didn’t expect such a through and on-point response! Thank you very much!

I did glance over your response and it looks very promising.

I will try to check and read it carefully and thoroughly over the next days and will get back to you here.

Again tyvm and have nice day!

Best regards!

Jean-Philippe_P
Staff & Editor
Staff & Editor
July 2, 2026

Hello mcakar! :) 

Glad that it could help you!! Please let us know if it works or not so everybody can enjoy your feedbacks ;) 

Have a good day!

Jean-Philippe - Fortinet Community Team
mcakarAuthor
Visitor III
July 3, 2026

Hello Jean-Philippe,

again, tyvm. Regarding these questions, please see inline for my answers.

  • Are you using FortiMail in Gateway or Transparent mode?
    → in gateway mode.
  • Will all relay traffic from Microsoft 365 originate from your tenant’s domain only, or are there exceptions?
    → only from our own tennant.
  • Do you require relaying for any other internal applications or services?
    → internal relaying, from internal sources are handled by the exchange DAG on-premises which forwards (if allowed via connectors on-prem) these like any other email to its smarthost. In this case the fortimail on-prem.
  • Are you able to configure custom connectors in Microsoft 365 to further restrict relay to your FortiMail’s public IP?
    → the hybrid connection of Exchange Online did create a outbound and inbound connector in EXO for which wie did restrict the source IP to the fortimail public IP but this is not the direction we have concerns with. We will not need to relay mails from our on-prem through the fortimail onto the EXO mailserver. All outbound emails are and should be handled and go through the Fortimail.
    Our concern is , like described in this scenario and llike you pointed out in your response, the relaying of messages coming from the M365/EXO cloud IP addresses onto the Fortimail on-prem.

I have question regarding the proposed measures with the sender address control:

  1. Restrict by Sender Pattern
    In your FortiMail Access Control Policy (Policy → Access Control):
    • Set the Sender Pattern to only allow your domain(s) (e.g., *@yourdomain.com).
    • This ensures only emails claiming to be from your domain are accepted for relay.

How does this work exactly. Is this scanning the header of the actual smtp traffic or the “from:” header? My question here would be: how is this “safe” or “safe enough”? Couldn’t just anyone put that in the from: field? And as long as it comes from the MS365 infrastructure it will pass the Fortimail access control? I am not sure about any safety measures Microsoft does on their side but I think I’ve seen some taken over hacked email servers from where these spoofed “from:” addresses are sent out. In our case the SPF amd DKIM/DMARC did protect us but we will need to have the EXO infrastructure in our spf records, too, because of some MS Teams notification emails and such. But these go through the mentioned connectors to internal on-prem mailboxes only (we have mail flow rules in place in EXO).

So our first concern is with internal recipients which would not have (possibly) any protection from impersonation out of the MS365/EXO environment with these loosened access control rules in place. The second more critical concern is when we will need to relay to external recipients for invoices and such from dynamics and graph. There it gets business critical too ensure that there is no possible attack surface and this is what we did not understand how to do it “safe without any room for concern”.

Best regards!

Jean-Philippe_P
Staff & Editor
Staff & Editor
July 3, 2026

Hey again :)

I found some answers to your questions:

 

Thank you for your detailed answers and concerns. Let’s address your questions and clarify how FortiMail’s Access Control works, its limitations, and what you can do to minimize the risk of unauthorized relaying—especially in the context of Microsoft 365 (Exchange Online) integration.

 

  1. How Does FortiMail’s Sender Pattern Matching Work?

Access Control Policy Matching:

  • The sender pattern in FortiMail’s Access Control Policy (e.g., *@yourdomain.com) matches the SMTP envelope sender address (the "MAIL FROM" in the SMTP transaction), not the "From:" header in the email body.
  • This means FortiMail checks the address provided during the SMTP conversation, which is more reliable than the message header but can still be spoofed if the sending system is compromised or not otherwise authenticated.
     
  1. Is This “Safe Enough”?

Potential Risks:

  • Envelope sender spoofing: Anyone with access to Microsoft 365’s infrastructure (or a compromised tenant) could potentially send emails with your domain in the envelope sender, and FortiMail would relay them if the source IP matches the allowed Microsoft IPs and the sender pattern matches.
  • Shared Microsoft IPs: Since Microsoft 365 IPs are shared among all tenants, restricting by source IP alone is not sufficient to prevent other tenants from attempting to relay as your domain.

Why This Is a Concern:

  • If a malicious actor in another tenant (or a compromised account) sends mail with your domain as the envelope sender, and it originates from Microsoft 365 IPs, FortiMail will relay it unless additional controls are in place.
  • This is why relying solely on sender pattern and source IP is not fully secure.
     
  1. How to Make It More Secure?
  1. Restrict by Source and Sender Pattern
  • Continue to use both the Microsoft 365 ISDB object (or explicit IPs) and your domain in the sender pattern.
  • This is a baseline, but not sufficient for high-security needs.
     
  1. Use SMTP Authentication (If Possible)
    Best Practice: Require SMTP authentication for relaying. This is the most secure method, but may not be feasible for Microsoft 365 to FortiMail relay scenarios.
     
  1. Restrict by Additional Headers or Custom Attributes
    If Microsoft 365 can stamp a unique header or attribute (e.g., via a transport rule), you could configure FortiMail to check for this header as an additional relay condition. However, this is not natively supported in all scenarios.
     
  1. Use SPF/DKIM/DMARC Validation
  • FortiMail can perform SPF, DKIM, and DMARC checks on incoming mail. However, these are primarily for anti-spoofing and anti-phishing, not for relay authorization.
  • They help protect your domain’s reputation but do not prevent unauthorized relaying by themselves.
     
  1. Limit Recipients
  • In your Access Control Policy, set the recipient to "External" only, so only emails to external domains are relayed.
  • For internal recipients, ensure that only your on-prem Exchange handles delivery.
     
  1. Monitor and Alert
    Enable logging and alerting for relayed messages, especially those matching your relay policy, to detect any unusual activity quickly.
     
  1. Summary Table: Security Measures

| Control | Effectiveness | Notes | |---------------------------------|--------------|------------------------------------------------------------| | Source IP (Microsoft 365) | Medium | Shared among all tenants | | Sender Pattern (*@yourdomain) | Medium | Can be spoofed in envelope sender | | SMTP Authentication | High | Not always possible with M365 relay | | Custom Header Matching | High | Only if M365 can add unique headers | | SPF/DKIM/DMARC | Medium | Helps with reputation, not relay authorization | | Recipient Restriction | Medium | Prevents internal relay, but not spoofing | | Logging/Alerting | High | Detects abuse quickly |
 

  1. Recommendations for Your Scenario
  1. Continue using sender pattern and source IP restrictions as you have, but understand their limitations.
  2. Restrict relaying to external recipients only in the Access Control Policy.
  3. Monitor logs for any suspicious relay activity.
  4. If possible, work with Microsoft 365 to add a unique header to all emails sent from your tenant, and configure FortiMail to check for this header (if supported).
  5. Regularly review and update your SPF/DKIM/DMARC records to ensure only authorized sources are allowed.
  6. Educate users and administrators about the risks of compromised accounts and monitor for signs of abuse.
     
  1. Follow-up and Clarification Questions

To further assist you, could you clarify:

  • Are you able to configure Microsoft 365 to add custom headers to outbound mail from your tenant?
  • Are there any scenarios where you must relay mail for internal recipients via FortiMail, or is all internal mail handled on-prem?
  • Would you consider using a dedicated connector or authentication mechanism between Microsoft 365 and FortiMail if available?

If you need step-by-step configuration guidance for any of the above recommendations, please specify which area you’d like more detail on.

 

References:

If you have further questions or need more technical detail, please let me know!

Jean-Philippe - Fortinet Community Team
mcakarAuthor
Visitor III
July 9, 2026

Hello Jean-Philippe,

thanks again for your helpful and through write-up.

We did implement it with your guidance and rationale on why and how.

As of right now we are “tunneling” all outbound mails from graph and dynamics through one EXO mailbox so we were able to restrict the access policy to this one sender.

Regarding custom headers from MS365/EXO: I asked my colleague who is in charge and he will get back to us internally if this is possible and we will then decide if we will implement it.

But as of right now we are now OK with the current setup. As we see it the whole problem will vanish if we make the shift to full EXO in the near future. Then all mail flow would be internal in our tennant anyway.

From my side this thread and our question has been resolved. Thank you and best regards.

Jean-Philippe_P
Staff & Editor
Staff & Editor
July 9, 2026

Hello mcakar,

I am glad I could help, and hope you can implement it!

Have a good day, do not hesitate if you need further helps :)

Jean-Philippe - Fortinet Community Team