码迷,mamicode.com
首页 > 编程语言 > 详细

python3 发送邮件功能

时间:2016-04-03 01:38:39      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

阿-_-涵的博客

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

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‘, ‘xxxx@163.com‘, ‘xxxx‘, ‘xxxx@163.com‘, ‘邮件标题‘, ‘邮件内容‘)
        print("发送成功")
    except Exception as e:
        print(e)

 

python3 发送邮件功能

标签:

原文地址:http://www.cnblogs.com/dengyg200891/p/5348763.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!