用Python單發/羣發郵件

import smtplib
from email.mime.text import MIMEText  # 創建郵件

# 郵箱,郵件

# smtp服務器:smtp.163.com
# 端口: 25
# 郵箱賬號:[email protected]
# 授權碼:password


smtp_server = 'smtp.163.com'
smtp_port = 25
from_email = '[email protected]'
auth_code = 'password'

to_email = '[email protected]'

# 創建郵箱對象
smtp = smtplib.SMTP(smtp_server, smtp_port)
smtp.login(from_email, auth_code)

# 創建郵件
msg = MIMEText('這是一個測試郵件')
msg['Subject'] = '【測試】'
msg['From'] = from_email
msg['To'] = to_email

# 發送
# smtp.sendmail(from_email, ['[email protected]','[email protected]'], msg.as_string())

smtp.sendmail(from_email, to_email, msg.as_string())

# 關閉
smtp.close()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章