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

Python 邮件发送消息

时间:2017-12-28 17:16:26      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:format   end   bsp   utf-8   author   imp   post   server   ini   

# 代码

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:supery

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr


class BaseMessage(object):
    def send(self, subject, body, to, name):
        raise NotImplementedError(未实现send方法)

class Email(BaseMessage):
    def __init__(self):
        self.email=1xx@163.com
        self.user = Supery
        self.pwd = xxx

    def send(self, subject, body, to, name):
        msg = MIMEText(body,plain,utf-8)
        msg[Form] = formataddr([self.user,self.email])
        msg[To] = formataddr([name,to])
        msg[Subject] = subject

        server = smtplib.SMTP(smtp.163.com,25)
        server.login(self.email,self.pwd)
        server.sendmail(self.email,[to,],msg.as_string())
        server.quit()

#  使用

Email(90xxx9@qq.com,liu,你别走了,xxx太多了)

 

Python 邮件发送消息

标签:format   end   bsp   utf-8   author   imp   post   server   ini   

原文地址:https://www.cnblogs.com/supery007/p/8136279.html

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