#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018-01-15 20:40
# @Author : hhj
# @Site :
# import collections
#
import smtplib
from email.mime.text import MIMEText
# from email.utils import formataddr
import sys
def mail(cont):
ret = True
try:
msg = MIMEText(cont, ‘plain‘, ‘utf-8‘)
msg[‘From‘] = "1@qq.com"
msg[‘To‘] = "2@qq.com"
msg[‘Subject‘] = "主题"
server = smtplib.SMTP_SSL("smtp.qq.com",465)
server.login("1@qq.com", "授权码***")
server.sendmail(‘1@qq.com‘, [‘2@qq.com‘, ], msg.as_string())
server.quit()
except Exception:
ret = False
return ret
def main():
cont =""
while cont=="":
cont = input("请输入邮件内容:")
else:
ret=mail(cont)
if ret==False:
print("邮件发送失败!")
else:
print("邮件发送成功!")
if __name__==‘__main__‘:
main()