Python 、Smtp 发送邮件(163邮箱)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40603236/article/details/81459357

1、环境  window  python 3

2 、使用 smtplib 库、 MIMEText 库

3、 163 邮箱开启授权设置

#!/usr/bin/python
#coding:utf-8

import  smtplib
from email.mime.text import MIMEText


def sendmail(content):

    form_adder='137***@163.com' #发送者邮箱地址
    password='*****'  #163 授权登陆密码
    to_adder='8122***@qq.com'  #接受者邮箱地址
    smtp_server=('smtp.163.com')  #smtp 服务器

    msg=MIMEText(content,'plain','utf-8')
    msg['From']=form_adder
    msg['To']=to_adder
    msg['subject']='邮件demo'  #邮件标题
    ret=True
    try:
        server=smtplib.SMTP_SSL(smtp_server,465)
        server.login(form_adder,password)
        server.sendmail(form_adder,[to_adder,],msg.as_string())
        server.quit()
    except Except:
        ret=False
    return ret

if sendmail('测试邮件发送'):
    print('发送成功')
else:
    print('发送失败')

猜你喜欢

转载自blog.csdn.net/weixin_40603236/article/details/81459357