溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

【學(xué)習(xí)筆記】python-配置文件和發(fā)送郵件

發(fā)布時間:2020-07-19 12:57:48 來源:網(wǎng)絡(luò) 閱讀:453 作者:wx57a1620925627 欄目:編程語言

一、配置文件(標(biāo)簽、數(shù)據(jù)項)
配置文件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

二、發(fā)送郵件
1、組裝內(nèi)容 email.mime.text
2、發(fā)送郵件 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問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI