1 Star 0 Fork 16

龙在江湖/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mail.py 2.06 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2018-05-16 15:06 . no commit message
#coding=utf-8
import smtplib
from email.mime.text import MIMEText
#"wanghuangan@163.com",
to_list = ["wanghuangan@163.com"]
mail_host = "smtp.163.com"
mail_user = "wanghuangan"
mail_pass = "123456"
mail_postfix="163.com"
def send_mail(sub, context):
me = mail_user + "<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(context, 'plain', 'utf-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
send_smtp = smtplib.SMTP()
send_smtp.connect(mail_host)
send_smtp.login(mail_user, mail_pass)
send_smtp.sendmail(me, to_list, msg.as_string())
send_smtp.close()
return True
except Exception, e:
print("send mail error!"+str(e))
return False
#发送邮件
'''
def send_Mail (Message, Dist):
TODAY = datetime.date.today()
CURRENTDAY=TODAY.strftime('%Y-%m-%d')
msg = MIMEMultipart()
TODAY = datetime.date.today()
CURRENTDAY=TODAY.strftime('%Y-%m-%d')
att = MIMEText(open(Dist+CURRENTDAY+'stock.csv', 'rb').read(), 'base64', 'gb2312') #设置附件的目录
att['content-type'] = 'application/octet-stream'
att['content-disposition'] = 'attachment;filename="stock.csv"' #设置附件的名称
msg.attach(att)
content = str(Message) #正文内容
body = MIMEText(content,'plain','GBK') #设置字符编码
msg.attach(body)
msgto = ['xx@126.com'] # 收件人地址多个联系人,格式['aa@163.com'; 'bb@163.com']
msgfrom = 'xx@126.com' # 寄信人地址 ,
msg['subject'] = 'Finish at '+CURRENTDAY #主题
msg['date']=time.ctime() #时间
#msg['Cc']='bb@junbao.net' #抄送人地址 多个地址不起作用
mailuser = 'xx' # 用户名
mailpwd = 'xx' #密码
try:
smtp = smtplib.SMTP()
smtp.connect(r'smtp.126.com')# smtp设置
smtp.login(mailuser, mailpwd) #登录
smtp.sendmail(msgfrom, msgto, msg.as_string()) #发送
smtp.close()
print "success mail"
except Exception, e:
print e
'''
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yizhengsh/traderStock-gui.git
git@gitee.com:yizhengsh/traderStock-gui.git
yizhengsh
traderStock-gui
traderStock-gui
master

搜索帮助