1. 程式人生 > 實用技巧 >QQ郵箱/微信郵箱傳送郵件

QQ郵箱/微信郵箱傳送郵件

import yamail
user = '[email protected]'#我自己的郵箱
passwold = 'xbaT82SpnwyaHFdn'  #生成授權碼(登入郵箱,設定pop3/smtp 開啟,點選生成授權碼)
host ='smtp.qq.cn'
mail = yamail.SMTP(host=host,user=user,password=passwold)
mail.send(
    to=['[email protected]'],
    cc=[],
    subject='測試一下',
    contents='傳送訊息'
)##to-接收人郵箱,cc-抄送人郵箱,subect-郵件主題,contents-郵件內容,attachments-郵件附件,可通過列表傳多個附件 ,接收人,抄送人
mail.close()
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import poplib
import base64,re
from email.parser import Parser

def mail(content):
    mail_host = "smtp.exmail.qq.com"  # 設定伺服器
    mail_user = "[email protected]"  # 使用者名稱
    mail_pass = "xbaT82SpnwyaHFdn
" # 口令 sender = '[email protected]' receivers = ['[email protected]'] # 接收郵件,可設定為你的QQ郵箱或者其他郵箱 message = MIMEText(content, 'plain', 'utf-8') message['From'] = Header("[email protected]", 'utf-8') message['To'] = Header("[email protected]", 'utf-8') subject = "11.05-日報" message['Subject
'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) # 25 為 SMTP 埠號 smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print("郵件傳送成功") except smtplib.SMTPException: print("Error: 無法傳送郵件") mail('早上好,今日計劃如下:\n 1、測試大V後臺\n ')