zoukankan      html  css  js  c++  java
  • 关于Flask 邮件发送,支持多人发送

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header


    class SendEmail(object):
        def __init__(self, mailserver, username_send, password, port, server_type):
            self.mailserver = mailserver     # 邮箱服务器地址
            self.username_send = username_send     # 邮箱用户名
            self.password = password     # 邮箱密码:需要使用授权码
            self.port = port
            self.server_type = server_type


        def make_mail(self):
            self.mail = MIMEText(self.content, 'plain', 'utf-8')
            self.mail['Subject'] = Header(self.header, 'utf-8')
            self.mail['From'] = self.username_send    # 发件人
            self.mail['To'] = ",".join(self.msg_to)       # 收件人;[]里的三个是固定写法,别问为什么,我只是代码的搬运工

        def send_email(self,username_recv, content, header):
            self.msg_to = username_recv.split(",")
            # print self.msg_to
            self.content = content
            self.header = header
            self.username_recv = username_recv     # 收件人,多个收件人用逗号隔开
            self.make_mail()

            try:
                 smtp = smtplib.SMTP(self.mailserver, self.port)    # 连接邮箱服务器,smtp的端口号是25
                 smtp.login(self.username_send, self.password)     # 登录邮箱
                 smtp.sendmail(self.username_send, self.msg_to,
                 self.mail.as_string())     # 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
                 smtp.quit()
                 return True
            except smtplib.SMTPException:
                 return False


    if __name__ == '__main__':
        a = SendEmail( "smtp.163.com", "xxxxxxxx@163.com", "******* ", 25, "SMTP")
        print a.send_email("xxxxxxx@qq.com",".这是测试内容","邮件标题")

    # print "success..."

  • 相关阅读:
    Raknet是一个基于UDP网络传输协议的C++网络库(还有一些其它库,比如nanomsg,fastsocket等等)
    Arch Linux 是个 针对 i686 优化的 Linux 发行版(通过可以轻松使用的二进制包系统
    使用网盘(Dropbox/Google Drive)同步Git仓库
    百度网盘web端项目总结
    国内的网盘一个个倒下,这里有一份能让你用到老的存储指南(有好多评论)
    单元测试
    C# Closure
    gulp
    Net Memory Profiler 分析.Net程序内存泄露
    Net内存泄露原因及解决办法
  • 原文地址:https://www.cnblogs.com/Adalia-Ting/p/11428487.html
Copyright © 2011-2022 走看看