1. 程式人生 > >Python:簡單的郵件傳送客戶端

Python:簡單的郵件傳送客戶端

#!/usr/bin/env python
# coding:UTF-8


"""
@version: python3.x
@author:曹新健
@contact: [email protected]
@software: PyCharm
@file: 郵件傳送.py
@time: 2018/9/10 14:09
"""
import smtplib
from email.mime.text import MIMEText

#SMTP伺服器地址
SMTPServer = "smtp.126.com"
#傳送者郵件地址
sender = "[email protected]"
#傳送者授權密碼,注意該密碼並不是郵箱登入密碼,而是smtp\pop等授權密碼
password = "xxx"

#傳送內容
mssage = "cxj is a handsome man!"
#轉換為郵件文字
mss = MIMEText(mssage)
#標題
mss['Subject'] = "來著超級大帥哥的問候"
#傳送者
mss['From'] = sender

#建立SMTP伺服器
mailServer = smtplib.SMTP(SMTPServer,25)
#登入郵箱
mailServer.login(sender,password)
#傳送郵件
mailServer.sendmail(sender,["
[email protected]
","[email protected]"],mss.as_string()) #退出郵箱 mailServer.quit()