#/usr/bin/env python
#-*- coding:utf-8 -*-
from email.mime.text import MIMEText
from email.header import Header
import smtplib
message ='''
故障故障,快檢查下。。
'''
msg = MIMEText(message,'plain','utf-8')
msg['Subject'] = Header("來之服務器的報警",'utf-8')
msg['From'] = Header('warning@xxx.net')
msg['To'] = Header('receiver','utf-8')
from_addr = 'fuchang.chen@ssssss' #發件郵箱
password = 'xxxxxxxx' #郵箱密碼(或者客戶端受權碼)
to_addr = 'yinghao.li@westwell-lab.com' #收件郵箱
smtp_server = 'smtp.exmail.qq.com' #企業郵箱地址,如果我的郵箱地址爲:smtp.163.com
try:
server = smtplib.SMTP_SSL(smtp_server,465) #第二個參數爲默認端口爲25,這裏使用ssl,端口爲994
print('開始登陸')
server.login(from_addr,password) #登陸郵箱
print('登陸成功')
print("郵件開始發送")
server.sendmail(from_addr,to_addr,msg.as_string()) #將msg轉化成string發出
server.quit()
print("郵件發送成功")
except smtplib.SMTPException as e:
print("郵件發送失敗",e)python