1. 程式人生 > 程式設計 >python實發郵件例項詳解

python實發郵件例項詳解

yagmail 實現發郵件

yagmail 可以更簡單的來實現自動發郵件功能。

1、安裝

pip install yagmail

2、簡單舉例

import yagmail

#連結郵箱伺服器
yag = yagmail.SMTP( user="[email protected]",password="1234",host='smtp.126.com')

# 郵箱正文
contents = ['This is the body,and here is just text http://somedomain/image.png','You can find an audio file attached.','/local/path/song.mp3']

# 傳送郵件
yag.send('[email protected]','subject',contents)

3、給多個使用者傳送郵件

# 傳送郵件
yag.send(['[email protected]','[email protected]','[email protected]'],contents)

4、傳送帶附件郵件

# 傳送郵件
yag.send('[email protected]','傳送附件',contents,["d://log.txt","d://baidu_img.jpg"])

以上就是本次介紹的關於python實發郵件的全部相關內容,感謝大家的學習和對我們的支援。