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

使用Python smtplib发送邮件(无需应用密码)遇[Errno 11003]错误

问题解决:smtplib发送Outlook邮件出现socket.gaierror错误

错误原因

你遇到的socket.gaierror: [Errno 11003] getaddrinfo failed是因为SMTP服务器地址填错了。smtplib.SMTP()的第一个参数需要填写邮件服务商的SMTP服务器域名,而非你的邮箱地址。Outlook/Office365的官方SMTP服务器是smtp.office365.com,不是你写的blabla@outlook.com。

修正后的代码

替换正确的服务器地址,同时优化邮件格式的规范性:

import smtplib
from email.message import EmailMessage

# 基础配置
sender = "blabla@outlook.com"
receiver = "albalb@outlook.com"
password = "你的邮箱登录密码"

# 构建标准邮件内容
msg = EmailMessage()
msg["Subject"] = "Tester"
msg["From"] = sender
msg["To"] = receiver
msg.set_content("Hello")

# 发送流程
with smtplib.SMTP("smtp.office365.com", 587) as prt:
    prt.starttls()
    prt.login(sender, password)
    prt.send_message(msg)

不使用应用密码的注意事项

  • 先确认Outlook账户已开启POP/IMAP服务:登录Outlook网页版,进入「设置→邮件→同步电子邮件」,检查POP和IMAP状态为启用。
  • 若账户未开启双重验证,需在微软账户安全中心开启「允许低安全性应用访问」(部分区域或账户默认关闭该选项)。
  • 双重验证开启状态下,普通密码无法用于SMTP登录,必须使用应用密码——这是微软的强制规则,无法绕过。
  • 若仍无法连接,排查本地防火墙是否拦截了SMTP端口587。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 01:57:08