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

 

posted @ 2016-04-03 00:57  Xiao|Deng  阅读(294)  评论(0编辑  收藏  举报