python实现邮件发送功能

2020-12-13 20:21

阅读:612

标签:服务   ever   ext   utf-8   email   功能   connect   div   bsp   

 

 

import smtplib
import email.mime.multipart
import email.mime.text

def send_email(receiver,content):
    msg = email.mime.text.MIMEText(content, ‘html‘, ‘utf-8‘)
    msg[‘from‘] = ‘916457600@qq.com‘  # 从该邮箱发送
    msg[‘to‘] = receiver  # 发送到该邮箱
    msg[‘subject‘] = ‘Python自动邮件‘
    smtpSever = ‘smtp.qq.com‘  # 163邮箱的smtp Sever地址
    smtpPort = ‘25‘  # 开放的端口
    sqm = ‘acsinwaqcutkbbha‘  # 在登录smtp时需要login中的密码应当使用授权码而非账户密码

    smtp = smtplib.SMTP()
    # 服务器连接并登陆
    smtp.connect(smtpSever, smtpPort)
    smtp.login(msg[‘from‘], sqm)
    # 发邮件
    smtp.sendmail(msg[‘from‘], msg[‘to‘], str(msg))
    print(str(msg))
    smtp.quit()

content="tester"
send_email("724245745@qq.com",content)

  

python实现邮件发送功能

标签:服务   ever   ext   utf-8   email   功能   connect   div   bsp   

原文地址:https://www.cnblogs.com/ftxy/p/11728191.html


评论


亲,登录后才可以留言!