⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mimemail.py

📁 python写的 发送mime邮件的模块
💻 PY
📖 第 1 页 / 共 2 页
字号:
"""
 +-------------------------------------------------------------------+
 |                     M I M E M A I L   (v2.1.1)                    |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: Nov. 2, 2004                Last modified: Mar. 21, 2008 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

==========================================================================================================

 This script can send MIME mails with attachments.

 EXAMPLE:

 import mimemail
 mail = mimemail.MimeMail("HTML")

 mail.senderName = "sender name"
 mail.senderMail = "sender@email"
 mail.bcc = "bcc@email"

 mail.subject = "This is the subject line"

 mail.body = "Hello! This is a message for you."   # OR: mail.body = "path/to/file"

 mail.attachments.append("path/to/file1")
 mail.attachments.append("path/to/file2")
 ...

 mail.create()

 recipients = 'recipient1@email,recipient2@email,recipient3@email'
 if not mail.send(recipients): print mail.error

==========================================================================================================
"""

import smtplib, os, re, time, base64

class MimeMail:
    """creates e-mails in MIME format and sends them"""
    def __init__(self, type = None):
#---------------------------------------------------------------------------------------------------------
# Configuration
#---------------------------------------------------------------------------------------------------------
        self.type = 'Text'            # default e-mail type ("HTML" or "Text")
        self.senderName = ''          # default sender name
        self.senderMail = ''          # default sender e-mail address
        self.cc = ''                  # default cc (e-mail address)
        self.bcc = ''                 # default bcc (e-mail address)
        self.replyTo = ''             # default reply-to (e-mail address)
        self.subject = ''             # default subject line
        self.priority = 'normal'      # default priority ("high", "normal", "low")

        self.documentRoot = ''        # document root (path to images, stylesheets, etc.)
        self.saveDir = ''             # save e-mail to this directory instead of sending it => just for testing :)
        self.charSet = 'ISO-8859-1'   # character set (ISO)
        self.smtpHost = 'localhost'   # SMTP host (mail server)

#---------------------------------------------------------------------------------------------------------
# Don't change from here unless you know what you're doing:
#---------------------------------------------------------------------------------------------------------
        self.attachments = []
        self.body = ''
        self.error = ''
        if type: self.type = str(type)

    __cnt = 0
    __header = ''
    __footer = ''
    __subjectLine = ''
    __bodyText = ''
    __uid1 = ''
    __uid2 = ''
    __uid3 = ''
    __created = False
    __inline = {}
    __exclude = ('htm', 'php', 'pl', 'prl', 'cgi', 'py', 'asp')
    __mimeTypes = {'dwg'    : 'application/acad',
                   'asd'    : 'application/astound',
                   'tsp'    : 'application/dsptype',
                   'dxf'    : 'application/dxf',
                   'spl'    : 'application/futuresplash',
                   'gz'     : 'application/gzip',
                   'ptlk'   : 'application/listenup',
                   'hqx'    : 'application/mac-binhex40',
                   'mbd'    : 'application/mbedlet',
                   'mif'    : 'application/mif',
                   'xls'    : 'application/msexcel',
                   'xla'    : 'application/msexcel',
                   'hlp'    : 'application/mshelp',
                   'chm'    : 'application/mshelp',
                   'ppt'    : 'application/mspowerpoint',
                   'ppz'    : 'application/mspowerpoint',
                   'pps'    : 'application/mspowerpoint',
                   'pot'    : 'application/mspowerpoint',
                   'doc'    : 'application/msword',
                   'dot'    : 'application/msword',
                   'bin'    : 'application/octet-stream',
                   'oda'    : 'application/oda',
                   'pdf'    : 'application/pdf',
                   'ai'     : 'application/postscript',
                   'eps'    : 'application/postscript',
                   'ps'     : 'application/postscript',
                   'rtc'    : 'application/rtc',
                   'smp'    : 'application/studiom',
                   'tbk'    : 'application/toolbook',
                   'vmd'    : 'application/vocaltec-media-desc',
                   'vmf'    : 'application/vocaltec-media-file',
                   'xhtml'  : 'application/xhtml+xml',
                   'bcpio'  : 'application/x-bcpio',
                   'z'      : 'application/x-compress',
                   'cpio'   : 'application/x-cpio',
                   'csh'    : 'application/x-csh',
                   'dcr'    : 'application/x-director',
                   'dir'    : 'application/x-director',
                   'dxr'    : 'application/x-director',
                   'dvi'    : 'application/x-dvi',
                   'evy'    : 'application/x-envoy',
                   'gtar'   : 'application/x-gtar',
                   'hdf'    : 'application/x-hdf',
                   'php'    : 'application/x-httpd-php',
                   'phtml'  : 'application/x-httpd-php',
                   'latex'  : 'application/x-latex',
                   'mif'    : 'application/x-mif',
                   'nc'     : 'application/x-netcdf',
                   'cdf'    : 'application/x-netcdf',
                   'nsc'    : 'application/x-nschat',
                   'sh'     : 'application/x-sh',
                   'shar'   : 'application/x-shar',
                   'swf'    : 'application/x-shockwave-flash',
                   'cab'    : 'application/x-shockwave-flash',
                   'spr'    : 'application/x-sprite',
                   'sprite' : 'application/x-sprite',
                   'sit'    : 'application/x-stuffit',
                   'sca'    : 'application/x-supercard',
                   'sv4cpio': 'application/x-sv4cpio',
                   'sv4crc' : 'application/x-sv4crc',
                   'tar'    : 'application/x-tar',
                   'tcl'    : 'application/x-tcl',
                   'tex'    : 'application/x-tex',
                   'texinfo': 'application/x-texinfo',
                   'texi'   : 'application/x-texinfo',
                   't'      : 'application/x-troff',
                   'tr'     : 'application/x-troff',
                   'roff'   : 'application/x-troff',
                   'troff'  : 'application/x-troff',
                   'ustar'  : 'application/x-ustar',
                   'src'    : 'application/x-wais-source',
                   'zip'    : 'application/zip',
                   'au'     : 'audio/basic',
                   'snd'    : 'audio/basic',
                   'es'     : 'audio/echospeech',
                   'tsi'    : 'audio/tsplayer',
                   'vox'    : 'audio/voxware',
                   'aif'    : 'audio/x-aiff',
                   'aiff'   : 'audio/x-aiff',
                   'aifc'   : 'audio/x-aiff',
                   'dus'    : 'audio/x-dspeeh',
                   'cht'    : 'audio/x-dspeeh',
                   'mid'    : 'audio/x-midi',
                   'midi'   : 'audio/x-midi',
                   'mp2'    : 'audio/x-mpeg',
                   'ram'    : 'audio/x-pn-realaudio',
                   'ra'     : 'audio/x-pn-realaudio',
                   'rpm'    : 'audio/x-pn-realaudio-plugin',
                   'stream' : 'audio/x-qt-stream',
                   'wav'    : 'audio/x-wav',
                   'dwf'    : 'drawing/x-dwf',
                   'cod'    : 'image/cis-cod',
                   'ras'    : 'image/cmu-raster',
                   'fif'    : 'image/fif',
                   'gif'    : 'image/gif',
                   'ief'    : 'image/ief',
                   'jpeg'   : 'image/jpeg',
                   'jpg'    : 'image/jpeg',
                   'jpe'    : 'image/jpeg',
                   'tiff'   : 'image/tiff',
                   'tif'    : 'image/tiff',
                   'mcf'    : 'image/vasa',
                   'wbmp'   : 'image/vnd.wap.wbmp',
                   'fh4'    : 'image/x-freehand',
                   'fh5'    : 'image/x-freehand',
                   'fhc'    : 'image/x-freehand',
                   'pnm'    : 'image/x-portable-anymap',
                   'pbm'    : 'image/x-portable-bitmap',
                   'pgm'    : 'image/x-portable-graymap',
                   'ppm'    : 'image/x-portable-pixmap',
                   'rgb'    : 'image/x-rgb',
                   'xwd'    : 'image/x-windowdump',
                   'xbm'    : 'image/x-xbitmap',
                   'xpm'    : 'image/x-xpixmap',
                   'csv'    : 'text/comma-separated-values',
                   'css'    : 'text/css',
                   'htm'    : 'text/html',
                   'html'   : 'text/html',
                   'shtml'  : 'text/html',
                   'js'     : 'text/javascript',
                   'txt'    : 'text/plain',
                   'rtx'    : 'text/richtext',
                   'rtf'    : 'text/rtf',
                   'tsv'    : 'text/tab-separated-values',
                   'wml'    : 'text/vnd.wap.wml',
                   'wmlc'   : 'application/vnd.wap.wmlc',
                   'wmls'   : 'text/vnd.wap.wmlscript',
                   'wmlsc'  : 'application/vnd.wap.wmlscriptc',
                   'xml'    : 'text/xml',
                   'etx'    : 'text/x-setext',
                   'sgm'    : 'text/x-sgml',
                   'sgml'   : 'text/x-sgml',
                   'talk'   : 'text/x-speech',
                   'spc'    : 'text/x-speech',
                   'mpeg'   : 'video/mpeg',
                   'mpg'    : 'video/mpeg',
                   'mpe'    : 'video/mpeg',
                   'qt'     : 'video/quicktime',
                   'mov'    : 'video/quicktime',
                   'viv'    : 'video/vnd.vivo',
                   'vivo'   : 'video/vnd.vivo',
                   'avi'    : 'video/x-msvideo',
                   'movie'  : 'video/x-sgi-movie',
                   'vts'    : 'workbook/formulaone',
                   'vtts'   : 'workbook/formulaone',
                   '3dmf'   : 'x-world/x-3dmf',
                   '3dm'    : 'x-world/x-3dmf',
                   'qd3d'   : 'x-world/x-3dmf',
                   'qd3'    : 'x-world/x-3dmf',

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -