AWS中Port 25是否封禁?部署Flask应用通过企业SMTP中继发邮件咨询
Hey there! As someone who’s worked through AWS email setup hurdles before, let’s break down your question clearly:
AWS对Port 25的默认限制
First off, yes—AWS blocks outbound traffic on Port 25 by default for all EC2 instances (and most other compute services like ECS/EKS containers). This is a core security measure to cut down on spam and malicious email activity across their network. Important note: this restriction only applies to traffic destined for public IP addresses; it doesn’t affect internal VPC traffic or traffic to your corporate network via VPN/Direct Connect.
你的场景是否可行?
Whether you can use Port 25 here depends entirely on where your company’s SMTP relay is hosted:
If the relay is on your company’s on-premises network (connected to AWS via VPN/Direct Connect or VPC peering):
You’re in the clear! AWS’s Port 25 restriction doesn’t apply to traffic between your AWS resources and your internal corporate network. As long as your Flask app can reach the relay’s internal IP on Port 25 (test connectivity with tools liketelnet [relay-ip] 25ornc -zv [relay-ip] 25), you can configure your Flask SMTP client to use this relay without issues sending emails to Outlook.If the relay is hosted on a public IP address:
AWS will block your app’s outbound traffic to that public IP on Port 25. To fix this, you’ll need to request AWS to lift the Port 25 restriction for your EC2 instance (or your entire account). When submitting the request, be explicit about your use case: you’re using a trusted corporate relay for legitimate business emails, not sending unsolicited spam. AWS typically approves these requests for valid, legitimate use cases.
快速测试建议
Before configuring your Flask app, do a quick connectivity check from your AWS instance:
- Run
telnet [relay-server-ip] 25ornc -zv [relay-server-ip] 25- If the connection succeeds: you’re ready to set up your Flask SMTP client.
- If it times out or gets rejected: you’re hitting the Port 25 public outbound restriction (if the relay is public) or need to fix network routing (if the relay is on-prem).
内容的提问来源于stack exchange,提问作者Debartha Mitra

