How to Route SMTP Traffic from Azure Container Apps with Restricted Outbound Access
Question details
The user needs to connect Azure Container Apps to smtp.office365.com under restricted outbound access rules without opening traffic to the 0.0.0.0/0 destination.

- Product
- Azure Container Apps
- Device & OS
- not provided
- Scenario
- Routing outbound email traffic from containerized applications to Office 365 SMTP servers in a highly restricted network environment.
- Observed behavior
- Outbound traffic is currently blocked by a subnet-level network security group, preventing direct connection to the SMTP server without allowing all outbound internet traffic.
Ensure you have the necessary Azure Role-Based Access Control (RBAC) permissions to create and manage Route Tables and configure your Network Virtual Appliance.
Configure a User-Defined Route via Network Virtual Appliance
Use a User-Defined Route (UDR) to securely direct outbound SMTP traffic through a Network Virtual Appliance (NVA) or Virtual Network Gateway instead of allowing unrestricted 0.0.0.0/0 outbound traffic.
By configuring a UDR, you can control the exact flow of outbound traffic from your Container Apps subnet. The NVA or Virtual Network Gateway will then act as a firewall or proxy, allowing you to explicitly permit traffic only to smtp.office365.com on the required ports.
Log in to the Azure Portal, search for 'Route Tables' in the global search bar, and click 'Create' to provision a new route table in your resource group.
Open your new Route Table, select 'Routes' from the left navigation pane, and click 'Add'. Specify the destination type as 'IP Addresses' or 'Service Tag' (if applicable), and set the next hop type to 'Virtual Appliance'.
Navigate to the 'Subnets' section under the Route Table menu, click 'Associate', and select the specific Virtual Network and Subnet hosting your Azure Container Apps.
Access the management interface of your Network Virtual Appliance or Gateway. Add an outbound firewall rule that explicitly permits TCP traffic on port 587 (or port 25) to the destination address of smtp.office365.com.

Looking for a Lightweight Alternative to Microsoft Office?
While resolving complex enterprise network configurations for Microsoft 365 services, you might be seeking a simpler, cost-effective office suite for daily document workflows. WPS Office provides a powerful, locally installable alternative with robust compatibility and zero complex cloud administration required.

Frequently Asked Questions
Why shouldn't I just allow 0.0.0.0/0 for outbound traffic in Azure?
Allowing 0.0.0.0/0 opens all outbound internet traffic from your subnet. This violates the principle of least privilege and introduces severe security risks, such as data exfiltration or malware communicating with external command servers.
Which port does smtp.office365.com require for outbound emails?
For secure email transmission, smtp.office365.com typically requires port 587 using STARTTLS encryption. Port 25 may also be used in specific enterprise relay configurations, but port 587 is the standard for client submissions.
Can I use an Azure NAT Gateway instead of a Network Virtual Appliance?
An Azure NAT Gateway provides general outbound internet connectivity but lacks Layer 7 firewall capabilities. It cannot filter outbound traffic specifically by domain (like smtp.office365.com) or port, making an NVA necessary for granular outbound restrictions.




