自動發送郵件
# -*- coding: utf-8 -*- import smtplib # 發送字符串的郵件 from email.mime.text import MIMEText # 處理多種形態的郵件主體我們需要 MIMEMultipart 類 # 設置服務器所需信息 fromaddr = '' # 郵件發送方郵箱地址 password = 'jqkjerduknvjbjbb' # 密碼(部分郵箱為授權碼) toaddrs = ['a76887800@163.com',] # 郵件接受方郵箱地址,注意需要[]包裹,這意味着你可以寫多個郵件地址群發 # 設置email信息 # ---------------------------發送字符串的郵件----------------------------- # 郵件內容設置 message = MIMEText('腳本測試郵件', 'plain', 'utf-8') # 郵件主題 message['Subject'] = 'test email' #---------------------------登錄並發送郵件------------------------------- try: server = smtplib.SMTP('smtp.qq.com') # qq郵箱服務器地址 server.login(fromaddr, password) server.sendmail(fromaddr, toaddrs, message.as_string()) print('success') server.quit() except smtplib.SMTPException as e: print('error', e)