【问题标题】:Using Python I can't send email using gmail smtp server from within my Corporate LAN. Why使用 Python,我无法使用公司局域网内的 gmail smtp 服务器发送电子邮件。为什么
【发布时间】:2017-10-07 12:27:33
【问题描述】:

我在这里搜索了许多与 python 电子邮件相关的帖子,但我似乎无法使用 python 发送一封电子邮件。我在公司局域网内工作。但是如果我使用我公司的 smtp 中继服务器,我可以将电子邮件发送到 gmail,或者我的公司 ID 或其他电子邮件。这很奇怪,还是应该是这样?如何使用gmail smtp服务器向外发送邮件?

这是我尝试过的几个脚本。 =====================================1==

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("xyz@gmail.com", "myPasswd")

msg = "YOUR MESSAGE!"
server.sendmail("xyz@gmail.com", "xyz@gmail.com", msg)
server.quit()

====================================2==

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

msg = MIMEMultipart()
msg['From'] = 'sender@gmail.com'
msg['To'] = 'recvr@gmail.com'
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))

mailserver = smtplib.SMTP('smtp.gmail.com',587)
# identify ourselves to smtp gmail client
mailserver.ehlo()
# secure our email with tls encryption
mailserver.starttls()
# re-identify ourselves as an encrypted connection
mailserver.ehlo()
mailserver.login('sender@gmail.com', 'pswd')

mailserver.sendmail('sender@gmail.com','rcvr@gmail.com',msg.as_string())

mailserver.quit()

========================================

我确信这与代码无关,而是我缺少的其他东西。

【问题讨论】:

  • "无法发送" -> 你得到什么错误?你遇到了什么问题?
  • 使用上面的python脚本什么都没有发生意味着没有错误消息。它只是停留,没有输出。所以几分钟后我检查是否发送了电子邮件 - 什么都没有。我必须手动停止运行时。

标签: python email server smtp send


【解决方案1】:

我遇到了同样的问题

Google 似乎发现您的应用程序不安全。你可以:

【讨论】:

  • 我在启用不太安全的选项后尝试了这个。好像也不行。
猜你喜欢
  • 2016-09-07
  • 2012-10-20
  • 1970-01-01
  • 2015-05-10
  • 2021-07-06
  • 2011-08-14
  • 2022-01-09
  • 2014-10-15
相关资源
最近更新 更多