經過郵件發短信

import smtplibfrom email.mime.text import MIMEText# 第三方 SMTP 服務mail_host = "smtp.163.com"      # SMTP服務器mail_user = ""                  # 用戶名mail_pass = ""               # 受權密碼,非登陸密碼sender = ''    # 發件人郵箱(最好寫全, 否則會失敗)receivers = ['']  # 接收郵件,可設置爲你的QQ郵箱或者其餘郵箱def sendEmail(title,content):    message = MIMEText(content, 'plain', 'utf-8')  # 內容, 格式, 編碼    message['From'] = "{}".format(sender)    message['To'] = ",".join(receivers)    message['Subject'] = title    try:        smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 啓用SSL發信, 端口通常是465        smtpObj.login(mail_user, mail_pass)  # 登陸驗證        smtpObj.sendmail(sender, receivers, message.as_string())  # 發送        print("successfully.-----------")    except smtplib.SMTPException as e:        print(e)if __name__ == '__main__':
相關文章
相關標籤/搜索