python - 无法使用 smtplib 在 Outlook 上的 python 中发送邮件
问题描述
我尝试通过 Outlook 帐户发送电子邮件,但我不能。我使用 Gmail 成功发送了电子邮件,但无法使用 Outlook。
我试图在 SMTP.office365.com 端口:587 和..之间更改主机和端口
smtp-mail.outlook.com 端口:587 不工作。同样的错误。
Gmail 发送:
def sendmail(from_email, password, to_email, subject, message):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465) #Info pour send depuis une addresse courriel
server.ehlo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close
return True
except Exception as e:
print ("Something went wrong :", str(e))
return False
sendmail('email@gmail.com', 'password', 'email1@gmail.com', 'subject', 'this is message body ; so hot ! ')
展望“发送”:
def sendmail(from_email, password, to_email, subject, message):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP_SSL('SMTP.office365.com', 587) #Info pour send depuis une addresse courriel
server.ehlo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close
return True
except Exception as e:
print ("Something went wrong :", str(e))
return False
sendmail('email@outlook.com', 'password', 'email1@gmail.com', 'subject', 'this is message body ; so hot ! ')
例外:通过 email1@gmail.com 发送邮件
错误:出了点问题:[SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1056)
当我删除 _SSL 时,发生错误;
出了点问题:服务器不支持 SMTP AUTH 扩展
解决方案
推荐阅读
- node.js - 如何在 Azure 应用服务应用中查看 console.log() 输出
- artifactory - JFrog REST api 客户端应用程序无法构建缺少 org.apache.commons.* 包
- javascript - Javascript 如何从 HTML 表格中生成的单元格中获取值?
- ruby - 仅当我的 jar 文件在厨师中更新时如何解压文件?
- python - 将值列表转换为数据框时结果不正确
- javascript - 父窗口未从 Microsoft Edge 中的子窗口更新
- c - 插入节点时返回 void 与返回链表有什么区别或权衡?
- c# - 使用 asmx 的简单 helloworld WebService 在 Windows 2008 R2 IIS 7.5 上发布时不起作用
- testing - JMeter - 测试从 CSV 文件中获取的唯一链接
- arrays - 按多个属性对包含字符串和整数的数组进行排序