1. 程式人生 > 資訊 >馬斯克宣佈特斯拉將總部從加州遷至得克薩斯州

馬斯克宣佈特斯拉將總部從加州遷至得克薩斯州

 1 # coding = utf-8
 2 import smtplib
 3 from email.mime.text import MIMEText
 4 from email.header import Header
 5 class SendMail:
 6     def __init__(self, mail_host):
 7         self.mail_host = mail_host
 8     def send(self, title, content, sender, auth_code, receivers):
 9         message = MIMEText(content, '
html', 'utf-8') 10 message['From'] = "{}".format(sender) 11 message['To'] = ",".join(receivers) 12 message["Subject"] = title 13 try: 14 smtp_obj = smtplib.SMTP_SSL(self.mail_host, 465) # 啟用ssl發信,埠一般是465 15 smtp_obj.login(sender, auth_code) # 登入
16 smtp_obj.sendmail(sender, receivers, message.as_string()) 17 print("Mail 傳送成功") 18 except Exception as e: 19 print(e) 20 21 if __name__ == '__main__': 22 mail = SendMail("smtp.126.com") 23 sender = "[email protected]" 24 receivers = ['[email protected]
','[email protected]'] 25 title = "你眉目如當年,流轉我心間" 26 content = """ 27 car.net 28 <a href="https://car.net">車聯網</a> 29 """ 30 # 授權碼不是郵箱登入密碼,網易郵箱可以通過 "設定"->客戶端授權祕密,自己註冊和用自己的授權碼,這個會刪除 31 auth_code = "HFGBAP" 32 mail.send(title, content, sender, auth_code, receivers)