python实现邮件发送功能

 

 

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‘] = ‘[email protected]‘  # 从该邮箱发送
    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("[email protected]",content)
相关文章
相关标签/搜索