欢迎来到Louis的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。
扩大
缩小

使用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()

 

posted on 2018-08-27 20:40  Louiszj  阅读(2067)  评论(0编辑  收藏  举报

导航