首页 > 编程语言 > 详细

【学习笔记】python-配置文件和发送邮件

时间:2018-06-25 16:38:06      阅读:216      评论:0      收藏:0      [点我收藏+]
一、配置文件(标签、数据项)
配置文件db.conf
[DATEBASE]
config={
‘host‘:‘xxx‘,
‘user‘:‘xxx‘,
‘password‘:‘xxx‘,
‘port‘:3306,
‘database‘:‘test‘,
}

读取配置文件
import configparser
cf=configparser.ConfigParser()
cf.read(‘db.conf‘)
config=cf.get(‘DATEBASE‘,‘config‘)
print config

二、发送邮件
1、组装内容 email.mime.text
2、发送邮件 smtplib
from email.mime.text import MIMEText
import smtplib

msg_from=‘xxx@qq.com‘
passwd=‘xxx‘
msg_to=‘xxx@qq.com‘

subject=‘zhuti‘
content=‘666‘

msg=MIMEText(content)
msg[‘Subject‘]=subject
msg[‘From‘]=msg_from
msg[‘To‘]=msg_to

s=smtplib.SMTP_SSL("smtp.qq.com",465)
s.login(msg_from,passwd)
s.sendmail(msg_from,msg_from,msg.as_string())
s.quit()

【学习笔记】python-配置文件和发送邮件

原文:http://blog.51cto.com/11926720/2132459

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!