# coding:utf-8
import smtplib
from email.mime.text import MIMEText as mtext
from email.header import Header

mail_host = "smtp.sohu.com"
host_user = "[email protected]"
host_password = "************"

form_address = host_user#( 发件人地址)
email_subject = "test"#(主题,相当于title)
address = "[email protected]" #(收件人地址)
massage = "新年好" #(内容,支持富文本)

def sendTo(address, message):
    msg = mtext(message, _subtype='plain')
    msg['Subject'] = email_subject
    msg['Form'] = Header(host_user)
    msg['To'] = address
    try:
        server = smtplib.SMTP()
        server.connect(mail_host)
        server.login(host_user, host_password)
        server.sendmail(host_user, address, msg.as_string())
        server.close()
        return True
    except Exception as e:
        print(str(e))
        return False


if __name__ == '__main__':
    sendTo(address, massage)

点击运行
smtp+ mail写邮件(爬虫准备)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-09-05
  • 2022-01-18
  • 2022-01-11
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案