zoukankan      html  css  js  c++  java
  • 发邮件的模块调用练习

     只适用于本机向外发送邮件(前提是本机已经配置好邮箱设置,能正常收发邮件)

    1、写一个通用的发送邮件的调用模块的脚本。

    EmailCommon.py
    #!/usr/bin/env python
    # -*- coding:UTF-8 -*-

    import os class EmailCommon: def __init__(self, debug=False): self.debug = debug def email(self, from_address, to_addresses, subject, body, server='localhost', mimetext='plain'): if type(to_addresses) != list: to_addresses = [to_addresses] import smtplib from email.mime.text import MIMEText msg = MIMEText(body, mimetext, 'utf-8') msg['Subject'] = subject msg['From'] = from_address msg['To'] = ','.join(to_addresses) msg['Accept-Language'] = "zh-CN" msg['Accept-Charset'] = "ISO-8859-1,utf-8" s = smtplib.SMTP(server) s.sendmail(from_address, to_addresses, msg.as_string()) s.quit()

    2、发送邮件的脚本。

    email_server.py
    from email_server import EmailCommon     #从 email_server 文件导入 EmailCommon 类模块
    emailServer = EmailCommon()              #实例化
    
    address = 'test@163.com'
    to_address = 'test2@163.com'
    subject = "Welocom..." body = """ Just only test mail. """ emailServer.email(address,[to_address,'12345@qq.com'],subject,body)
  • 相关阅读:
    清华大学2015年自主招生暨领军计划试题
    高斯取整函数专题
    国际上的数学比赛
    清华大学数学系本科用什么教材?
    数学人眼中的湖北
    北京十一学校潘国双:激发学习的内在动力
    数学家Erdos的故事
    CentOS7关于网络的设置
    MySQL表连接
    MySQL的sql解析
  • 原文地址:https://www.cnblogs.com/luck123/p/8891673.html
Copyright © 2011-2022 走看看