Python発QQメール(菜鳥教程より)


:パスワードはメール設定のSMTPサーバに認証コードを取得する
import smtplib
from email.mime.text import MIMEText
from email.header import Header

#     SMTP   
mail_host = "smtp.qq.com"  #      
mail_user = "[email protected]"  #    
mail_pass = "    "  #   

sender = '[email protected]'
receivers = ['[email protected]', '[email protected]']  #     ,      QQ        

message = MIMEText('Python       ...', 'plain', 'utf-8')
message['From'] = Header("   ", 'utf-8')
message['To'] = Header("    ", 'utf-8')

subject = 'Python SMTP     '
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:       ")