You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel生产环境(AWS)Office365 SMTP突然连接超时求助

Troubleshooting Sudden SMTP Connection Timeout to smtp.office365.com on AWS Production

Hey there, sorry to hear you're stuck with this unexpected SMTP issue—let's walk through the most likely fixes based on common pitfalls for Laravel + Office 365 + AWS setups:

1. Check AWS Network Restrictions (Most Common Culprit)

AWS has strict outbound limits on port 25 to combat spam, and even if it worked before, temporary restrictions or accidental security group changes can break it. Try these steps:

  • Switch to an allowed port: Office 365 supports port 587 (TLS) and 465 (SSL) which AWS doesn't restrict. Update your .env config:
    MAIL_PORT=587
    MAIL_ENCRYPTION=tls
    
  • Verify Security Group/NACL Rules: Ensure your EC2 instance's security group allows outbound traffic on port 587 (or 465) to any destination (or specifically to smtp.office365.com). Double-check your VPC's Network Access Control Lists (NACLs) for any outbound blocks.

2. Office 365 Tenant/Account Security Checks

Office 365's security systems can lock down access without warning:

  • Check for account restrictions: Log into the Office 365 Admin Center, navigate to the nao_responda@primorossi.com mailbox, and confirm it hasn't been restricted from sending emails or flagged for suspicious activity.
  • Resolve security prompts: Try logging into the mailbox via Outlook Web App—if there's a pending two-factor authentication prompt or a request to approve the AWS server's location, complete those steps.
  • Verify send limits: Ensure the account hasn't hit Office 365's daily email sending quota.

3. Laravel & Server-Level Debugging

  • Clear config cache: Old cached config can cause unexpected behavior. Run this on your production server:
    php artisan config:clear
    
  • Test raw connection: Bypass Laravel to confirm the network issue directly. On your AWS server, run:
    telnet smtp.office365.com 587
    # Or using netcat if telnet isn't installed
    nc -zv smtp.office365.com 587
    
    If this times out, the problem is definitely network-related (not Laravel/SwiftMailer).
  • Check server firewall: Ensure iptables, ufw, or any security tools like fail2ban aren't blocking outbound SMTP traffic to Office 365's IPs.

4. DNS Resolution Issues

  • Test DNS lookup: On your AWS server, run:
    nslookup smtp.office365.com
    dig smtp.office365.com
    
    Confirm the resolved IPs are reachable. If you see invalid or unreachable IPs, try flushing the server's DNS cache or switching to AWS Route 53/Google DNS (8.8.8.8) for more reliable resolution.

5. Alternative: Use AWS SES as a Relay

If all else fails, consider using AWS SES to handle your email delivery—AWS integrates seamlessly with SES, avoiding port 25 restrictions. You can either:

  • Switch Laravel's mail driver to ses (requires configuring AWS credentials)
  • Set up SES as an SMTP relay to forward emails to Office 365.

内容的提问来源于stack exchange,提问作者Marcello Pato

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 09:12:28