常用郵箱SMTP服務(wù)器地址和端口")常用郵箱SMTP服務(wù)器地址和端口
sina.com:
POP3服務(wù)器地址:pop3.sina.com.cn(端口:110)
SMTP服務(wù)器地址:smtp.sina.com.cn(端口:25)
sinaVIP:
POP3服務(wù)器:pop3.vip.sina.com (端口:110)
SMTP服務(wù)器:smtp.vip.sina.com (端口:25)
sohu.com:
POP3服務(wù)器地址:pop3.sohu.com(端口:110)
SMTP服務(wù)器地址:smtp.sohu.com(端口:25)
126郵箱:
POP3服務(wù)器地址:pop.126.com(端口:110)
SMTP服務(wù)器地址:smtp.126.com(端口:25)
139郵箱:
POP3服務(wù)器地址:POP.139.com(端口:110)
SMTP服務(wù)器地址:SMTP.139.com(端口:25)
163.com:
POP3服務(wù)器地址:pop.163.com(端口:110)
SMTP服務(wù)器地址:smtp.163.com(端口:25)
QQ郵箱
POP3服務(wù)器地址:pop.qq.com(端口:110)
SMTP服務(wù)器地址:smtp.qq.com (端口:25)
QQ企業(yè)郵箱
POP3服務(wù)器地址:pop.exmail.qq.com (SSL啟用 端口:995)
SMTP服務(wù)器地址:smtp.exmail.qq.com(SSL啟用 端口:587/465)
yahoo.com:
POP3服務(wù)器地址:pop.mail.yahoo.com
SMTP服務(wù)器地址:smtp.mail.yahoo.com
yahoo.com.cn:
POP3服務(wù)器地址:pop.mail.yahoo.com.cn(端口:995)
SMTP服務(wù)器地址:smtp.mail.yahoo.com.cn(端口:587)
HotMail
POP3服務(wù)器地址:pop3.live.com (端口:995)
SMTP服務(wù)器地址:smtp.live.com (端口:587)
gmail(google.com)
POP3服務(wù)器地址:pop.gmail.com(SSL啟用 端口:995)
SMTP服務(wù)器地址:smtp.gmail.com(SSL啟用 端口:587)
263.net:
POP3服務(wù)器地址:pop3.263.net(端口:110)
SMTP服務(wù)器地址:smtp.263.net(端口:25)
263.net.cn:
POP3服務(wù)器地址:pop.263.net.cn(端口:110)
SMTP服務(wù)器地址:smtp.263.net.cn(端口:25)
x263.net:
POP3服務(wù)器地址:pop.x263.net(端口:110)
SMTP服務(wù)器地址:smtp.x263.net(端口:25)
21cn.com:
POP3服務(wù)器地址:pop.21cn.com(端口:110)
SMTP服務(wù)器地址:smtp.21cn.com(端口:25)
Foxmail:
POP3服務(wù)器地址:POP.foxmail.com(端口:110)
SMTP服務(wù)器地址:SMTP.foxmail.com(端口:25)
china.com:
POP3服務(wù)器地址:pop.china.com(端口:110)
SMTP服務(wù)器地址:smtp.china.com(端口:25)
tom.com:
POP3服務(wù)器地址:pop.tom.com(端口:110)
SMTP服務(wù)器地址:smtp.tom.com(端口:25)
etang.com:
POP3服務(wù)器地址:pop.etang.com
SMTP服務(wù)器地址:smtp.etang.com
一. yagmail郵件發(fā)送庫(kù)使用詳解
使用python標(biāo)準(zhǔn)庫(kù)進(jìn)行郵件的處理比較復(fù)雜,所以產(chǎn)生了yagmail,但是yagmail目前只能用SMTP協(xié)議進(jìn)行郵件發(fā)送锰悼,并不能讀取郵件情连,也不支持其他的郵件相關(guān)協(xié)議幔嗦,但是對(duì)于一般使用完全夠了锋恬。
1. 連接郵箱服務(wù)器
yag = yagmail.SMTP( user="from_user@126.com", password="1234", host='smtp.126.com')
如果不想將我們的密碼暴露下腳本文件中桶蝎,yagmail使用keyring模塊將密碼存放在系統(tǒng)keyring服務(wù)中声邦。關(guān)于keyring是什么乏奥,請(qǐng)看:What does a Keyring do?
官方文檔中,
yagmail.register('mygmailusername', 'mygmailpassword')
實(shí)際上是對(duì)keyring.set_password('yagmail', 'mygmailusername', 'mygmailpassword')
的封裝翔忽。
SMTP()
方法會(huì)去用戶(hù)主文件夾讀取.yagmail
文件英融,但是以上操作并不會(huì)生成這個(gè)文件,所以需要自己創(chuàng)建歇式,并將自己的郵箱寫(xiě)入文件中驶悟。
例如,我測(cè)試過(guò)程中寫(xiě)入.yagmail
文件中的內(nèi)容為:cbj_love@126.com
而之前我已經(jīng)通過(guò)register()
方法將該郵箱的密碼保存到了系統(tǒng)keyring中材失,所以接下來(lái)就可以初始化一個(gè)SMTP客戶(hù)端痕鳍。
另外還需要注意的是,經(jīng)過(guò)測(cè)試龙巨,163郵箱很容易將郵件識(shí)別為垃圾郵件笼呆,導(dǎo)致郵件發(fā)送錯(cuò)誤,而qq郵箱需要關(guān)閉郵件保護(hù)旨别,其他郵箱沒(méi)有測(cè)試诗赌,這里推薦使用qq郵箱。
yagmail.SMTP()
默認(rèn)使用的gmail的SMTP服務(wù)秸弛,所以我們?nèi)绻褂胵q郵箱铭若,則使用如下代碼初始化一個(gè)SMTP客戶(hù)端
2. 發(fā)送郵件
yag.send('to_user@163.com', '郵件主題', '這是郵件內(nèi)容')
# 發(fā)給多個(gè)用戶(hù)
yag.send(['aa@126.com','bb@qq.com','cc@gmail.com'], 'subject', contents)
# 發(fā)送附件郵件
yag.send('aaaa@126.com', '發(fā)送附件', contents, ["d://log.txt","d://baidu_img.jpg"])
注意send()
方法的定義:
如果不指定to
參數(shù)洪碳,則發(fā)送給自己,如果to
參數(shù)是一個(gè)列表,則將該郵件發(fā)送給列表中的所有用戶(hù)叼屠,attachments
表示附件瞳腌,該參數(shù)可以是列表,表示發(fā)送多個(gè)附件
對(duì)于contents
參數(shù)镜雨,官方說(shuō)明如下:
- If it is a dictionary it will assume the key is the content and the value is an alias (only for images currently!) e.g. {‘/path/to/image.png’ : ‘MyPicture’}
- It will try to see if the content (string) can be read as a file locally, e.g. ‘/path/to/image.png’
- if impossible, it will check if the string is valid html e.g.
This is a big title
- if not, it must be text. e.g. ‘Hi Dorika!’