使用163smtp发送邮件


import smtplib
from email.mime.text import MIMEText

mail_host = 'smtp.163.com'
mail_user = '发件人邮箱'
mail_pwd = '授权码'

sender = '发件人邮箱'
receivers = ['收件人邮箱']

content = 'python使用163smtp发送邮件'
title = '人生苦短'


def sendmail():
    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_pwd)  # 登陆验证
        smtpobj.sendmail(sender, receivers, message.as_string())
        print('mail has been send successfully')
    except Exception as e:
        print(e)


sendmail()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM