温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-19 12:57:48 来源:网络 阅读:446 作者:wx57a1620925627 栏目:编程语言

一、配置文件(标签、数据项)
配置文件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()

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI