python3 发送邮件功能

Posted Xiao|Deng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3 发送邮件功能相关的知识,希望对你有一定的参考价值。

阿-_-涵的博客

#首先写一个模块功能,发邮件功能打包起来

from
smtplib import SMTP from email.mime.text import MIMEText def send_email(SMTP_host, from_addr, password, to_addrs, subject=‘‘, content=‘‘): email_client = SMTP(host=SMTP_host) email_client.login(from_addr, password) # create msg msg = MIMEText(content, _charset=utf-8) msg[Subject] = subject email_client.sendmail(from_addr, to_addrs, msg.as_string()) email_client.quit()
# -*- coding: cp936 -*-
from my_email import send_email

 
if __name__ == __main__:
    try:
        send_email(smtp.163.com, [email protected], xxxx, [email protected], 邮件标题, 邮件内容)
        print("发送成功")
    except Exception as e:
        print(e)

 

以上是关于python3 发送邮件功能的主要内容,如果未能解决你的问题,请参考以下文章