Outlook连接Gmail不成功可以试试以下方法

本文提供了一种结合使用hosts文件和代理服务器的方法,帮助解决Outlook无法成功连接Gmail的问题。通过设置Gmail的IMAP功能并配置Outlook中的hosts文件指向代理地址,可以稳定地实现邮件的收发。

Outlook连接Gmail不成功可以试试以下方法

首先,我已经尝试过网络上能搜索到的大部分方法了
除了使用某些软件强行代理整个系统的网络连接这个方法


首先准备
打开Gmail,打开里面的IMAP功能,否则不能使用IMAP来收发邮件

  • 如果你使用了2次验证
    • 请使用你的电脑登陆一次Gmail,让Gmail记录你的电脑为常用电脑
  • 如果你没有使用2次验证
    • 需要打打允许使用低安全程序功能

如果你已经尝试过使用以下方法还连接不上Gmail的话

  1. 修改hosts,把imap和smtp的gmail地址设置
  2. 全局代理
  3. 设置window的internet setting里面的代理

修改hosts的方法时好时坏,应该是因为firewall对imap和pop是时好时坏的原因,所以1不行,我们需要一个稳定的收发.
网上查了一下,说是IMAP不是http方法,即使你打开了全局代理,他也不会走代理,所以2也不行
3和2其实没有什么大区别,所以也是不行

如果你也已经使用过以上方法,并且没有解决到连接邮件问题,那么你可以尝试使用一下我的这个方法
把方法1和方法2结合
即是hosts里面修改imap和smtp的ip为你的代理地址和端口

DOWNLOAD_DIR = r"D:\Firmware\DailyBuilds" attachments = [ os.path.join(DOWNLOAD_DIR, f) for f in os.listdir(DOWNLOAD_DIR) if f.endswith(".txt") and os.path.isfile(os.path.join(DOWNLOAD_DIR, f)) ] 发送邮件 send_email_with_attachments( sender_email=SENDER_EMAIL, app_password=APP_PASSWORD, recipient_emails=RECIPIENTS, subject=SUBJECT, body=BODY, attachment_paths=attachments )def send_email_with_attachments( sender_email, app_password, recipient_emails, # 可以是字符串或列表 subject, body, attachment_paths, smtp_server="smtp-mail.outlook.com", smtp_port=587 ): """ 发送带附件的邮件(支持多个收件人和多个附件) :param sender_email: 发件人邮箱(Outlook) :param app_password: 应用专用密码 :param recipient_emails: 单个或多个收件人邮箱(list 或 str) :param subject: 邮件主题 :param body: 邮件正文(支持 HTML 或纯文本) :param attachment_paths: 要附加的本地文件路径列表 :param smtp_server: SMTP 服务器地址 :param smtp_port: SMTP 端口(STARTTLS) """ # 创建 MIMEMultipart 消息对象 msg = MIMEMultipart() msg["From"] = sender_email msg["To"] = ", ".join(recipient_emails) if isinstance(recipient_emails, list) else recipient_emails msg["Subject"] = subject # 添加正文 msg.attach(MIMEText(body, "plain")) # 添加附件 for file_path in attachment_paths: if not os.path.isfile(file_path): print(f"附件存在,跳过: {file_path}") continue with open(file_path, "rb") as attachment: part = MIMEBase("application", "octet-stream") part.set_payload(attachment.read()) encoders.encode_base64(part) filename = os.path.basename(file_path) part.add_header( "Content-Disposition", f"attachment; filename= {filename}", ) msg.attach(part) # 连接Outlook SMTP 服务器并发送邮件 try: server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() # 启用加密 server.login(sender_email, app_password) text = msg.as_string() server.sendmail(sender_email, recipient_emails, text) server.quit() print(f"✅ 邮件已成功发送!共附加 {len([f for f in attachment_paths if os.path.exists(f)])} 个文件") return True except Exception as e: print(f"❌ 发送邮件时发生错误: {e}") return False这是我发邮件的函数,但是知道为什么,从outlook登陆上,现在能能用qq邮箱给outlook邮箱发邮件啊
最新发布
12-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yi高人胆大

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值