简体   繁体   English

使用tls / ssl使用python发送Office365的SMTP电子邮件

[英]send SMTP email for office365 with python using tls/ssl

i'm trying to create a python script that sends emails with some messages. 我正在尝试创建一个Python脚本来发送带有某些消息的电子邮件。 my setup is based on a smtp.office365.com. 我的设置基于smtp.office365.com。 i created some script to do the job. 我创建了一些脚本来完成这项工作。

#!/usr/bin/python

print ("HI! let's start")  
import smtplib  
import getpass

port=587                                                                                                                    
smtp_server="smtp.office365.com"  
sender_email='mymail@something.com'  
receiver_email='mymail@something.com'  
print ("defining server")  
server = smtplib.SMTP(smtp_server,port)

password=getpass.getpass("enter password")

message='''
Hi,
THIS IS A TEST MESSAGE.
'''

print ("logging in")  
server.login(sender_email,password)  
print ("sending mail now")  
server_sendmail(sender_email,receiver_email,message)  
print ("all must be done by now")

But due to some reasons, it gets stuck after printing "defining server". 但是由于某些原因,它在打印“定义服务器”后卡住了。 and never reaches to asking for password. 永远不会要求输入密码。 apparently the smtplib.SMTP command hangs. 显然smtplib.SMTP命令挂起。 can you tell why this happens and how to get rid of it? 你能告诉我为什么会发生这种情况以及如何消除它吗? my setup is as following : 我的设置如下:

Server: smtp.office365.com
/sjmail.com
security : STARTTLS
Port : 587

Vishesh Arya! Vishesh Arya!

SMTP AUTH extension not supported by Office 365 account. Office 365帐户不支持SMTP AUTH扩展名。 Search for Microsoft Graph to do this. 搜索Microsoft Graph为此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM