python——SMTP发送简单邮件

[root@localhost python]# cat smtp.py 
import smtplib
import string
from email.mime.text import MIMEText
HOST = "smtp-mail.outlook.com"
FROM = "bp1260647530@outlook.com"
SUBJECT = "this is a test"
TO = "1260647530@qq.com"
TEXT = "good to see you"
BODY = string.join((
"from: %s" % FROM,
"to: %s" % TO,
"Subject: %s" % SUBJECT, 
"",TEXT
),"\r\n")
server=smtplib.SMTP()
server.connect(HOST,"25")    #这个端口貌似不对,不过好像没影响
server.starttls()
server.login("bp1260647530@outlook.com","我的密码")
server.sendmail(FROM,TO,BODY)
server.close()
[root@localhost python]# 

查看邮箱,接受正常  

 

本来想用QQ邮箱做实验,结果发现需要万恶的授权码,果断弃用,改用outlook邮箱,这个邮箱就没有这么流氓

 

posted on 2018-02-24 15:53  标配的小号  阅读(984)  评论(0编辑  收藏  举报

导航