├── .gitignore ├── CHANGES ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README ├── docs ├── Makefile ├── _static │ └── sender.png ├── _themes │ ├── LICENSE │ ├── README │ ├── flask │ │ ├── layout.html │ │ ├── relations.html │ │ ├── static │ │ │ └── flasky.css_t │ │ └── theme.conf │ ├── flask_small │ │ ├── layout.html │ │ ├── static │ │ │ └── flasky.css_t │ │ └── theme.conf │ └── flask_theme_support.py ├── conf.py ├── index.rst └── make.bat ├── examples ├── example.py └── test.txt ├── logo └── logo.psd ├── sender.py ├── setup.cfg ├── setup.py ├── test_sender.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.pyc 3 | *.pyo 4 | *.egg-info 5 | dist 6 | build 7 | docs/_build 8 | .tox/* 9 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | 5 | Version 0.1 6 | ``````````` 7 | 8 | First public preview release. 9 | 10 | 11 | Version 0.2 12 | ``````````` 13 | 14 | Released on Sep 18th 2014 15 | 16 | - Do message validation on all recipients instead of to 17 | 18 | 19 | Version 0.3 20 | ``````````` 21 | 22 | Released on May 11th 2016 23 | 24 | - Added Python 3.x support 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 by Shipeng Feng. 2 | 3 | Some rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | 17 | * The names of the contributors may not be used to endorse or 18 | promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE CHANGES *.py 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: clean-pyc test 2 | 3 | test: 4 | python test_sender.py 5 | 6 | tox-test: 7 | tox 8 | 9 | clean-pyc: 10 | find . -name '*.pyc' -exec rm -f {} + 11 | find . -name '*.pyo' -exec rm -f {} + 12 | find . -name '*~' -exec rm -f {} + 13 | 14 | lines: 15 | find . -name "*.py"|xargs cat|wc -l 16 | 17 | release: 18 | python setup.py register 19 | python setup.py sdist upload 20 | python setup.py bdist_wheel upload 21 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Sender 2 | 3 | Sender is a tiny module for SMTP mail sending, inspired by Flask-Mail. 4 | 5 | The purpose is making sending SMTP mail simple and easy. Using builtin 6 | module to send mail is a little verbose, things shouldn't be that way. 7 | 8 | Read the docs at http://sender.readthedocs.org/ 9 | 10 | If you feel anything wrong, feedbacks or pull requests are welcome. 11 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Sender.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Sender.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/Sender" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Sender" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/_static/sender.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengsp/sender/26f052ea7bd07ece5d20b3e731b086c91a2e0cc3/docs/_static/sender.png -------------------------------------------------------------------------------- /docs/_themes/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 by Armin Ronacher. 2 | 3 | Some rights reserved. 4 | 5 | Redistribution and use in source and binary forms of the theme, with or 6 | without modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials provided 15 | with the distribution. 16 | 17 | * The names of the contributors may not be used to endorse or 18 | promote products derived from this software without specific 19 | prior written permission. 20 | 21 | We kindly ask you to only use these themes in an unmodified manner just 22 | for Flask and Flask-related products, not for unrelated projects. If you 23 | like the visual style and want to use it for your own projects, please 24 | consider making some larger changes to the themes (such as changing 25 | font faces, sizes, colors or margins). 26 | 27 | THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 | ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE 37 | POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /docs/_themes/README: -------------------------------------------------------------------------------- 1 | Flask Sphinx Styles 2 | =================== 3 | 4 | This repository contains sphinx styles for Flask and Flask related 5 | projects. To use this style in your Sphinx documentation, follow 6 | this guide: 7 | 8 | 1. put this folder as _themes into your docs folder. Alternatively 9 | you can also use git submodules to check out the contents there. 10 | 2. add this to your conf.py: 11 | 12 | sys.path.append(os.path.abspath('_themes')) 13 | html_theme_path = ['_themes'] 14 | html_theme = 'flask' 15 | 16 | The following themes exist: 17 | 18 | - 'flask' - the standard flask documentation theme for large 19 | projects 20 | - 'flask_small' - small one-page theme. Intended to be used by 21 | very small addon libraries for flask. 22 | 23 | The following options exist for the flask_small theme: 24 | 25 | [options] 26 | index_logo = '' filename of a picture in _static 27 | to be used as replacement for the 28 | h1 in the index.rst file. 29 | index_logo_height = 120px height of the index logo 30 | github_fork = '' repository name on github for the 31 | "fork me" badge 32 | -------------------------------------------------------------------------------- /docs/_themes/flask/layout.html: -------------------------------------------------------------------------------- 1 | {%- extends "basic/layout.html" %} 2 | {%- block extrahead %} 3 | {{ super() }} 4 | {% if theme_touch_icon %} 5 | 6 | {% endif %} 7 | 8 | {% endblock %} 9 | {%- block relbar2 %}{% endblock %} 10 | {% block header %} 11 | {{ super() }} 12 | {% if pagename == 'index' %} 13 |
14 | {% endif %} 15 | {% endblock %} 16 | {%- block footer %} 17 | 21 | {% if pagename == 'index' %} 22 |
23 | {% endif %} 24 | {%- endblock %} 25 | -------------------------------------------------------------------------------- /docs/_themes/flask/relations.html: -------------------------------------------------------------------------------- 1 |

Related Topics

2 | 20 | -------------------------------------------------------------------------------- /docs/_themes/flask/static/flasky.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * flasky.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * :copyright: Copyright 2010 by Armin Ronacher. 6 | * :license: Flask Design License, see LICENSE for details. 7 | */ 8 | 9 | {% set page_width = '940px' %} 10 | {% set sidebar_width = '220px' %} 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: 'Georgia', serif; 18 | font-size: 17px; 19 | background-color: white; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | width: {{ page_width }}; 27 | margin: 30px auto 0 auto; 28 | } 29 | 30 | div.documentwrapper { 31 | float: left; 32 | width: 100%; 33 | } 34 | 35 | div.bodywrapper { 36 | margin: 0 0 0 {{ sidebar_width }}; 37 | } 38 | 39 | div.sphinxsidebar { 40 | width: {{ sidebar_width }}; 41 | } 42 | 43 | hr { 44 | border: 1px solid #B1B4B6; 45 | } 46 | 47 | div.body { 48 | background-color: #ffffff; 49 | color: #3E4349; 50 | padding: 0 30px 0 30px; 51 | } 52 | 53 | img.floatingflask { 54 | padding: 0 0 10px 10px; 55 | float: right; 56 | } 57 | 58 | div.footer { 59 | width: {{ page_width }}; 60 | margin: 20px auto 30px auto; 61 | font-size: 14px; 62 | color: #888; 63 | text-align: right; 64 | } 65 | 66 | div.footer a { 67 | color: #888; 68 | } 69 | 70 | div.related { 71 | display: none; 72 | } 73 | 74 | div.sphinxsidebar a { 75 | color: #444; 76 | text-decoration: none; 77 | border-bottom: 1px dotted #999; 78 | } 79 | 80 | div.sphinxsidebar a:hover { 81 | border-bottom: 1px solid #999; 82 | } 83 | 84 | div.sphinxsidebar { 85 | font-size: 14px; 86 | line-height: 1.5; 87 | } 88 | 89 | div.sphinxsidebarwrapper { 90 | padding: 18px 10px; 91 | } 92 | 93 | div.sphinxsidebarwrapper p.logo { 94 | padding: 0 0 20px 0; 95 | margin: 0; 96 | text-align: center; 97 | } 98 | 99 | div.sphinxsidebar h3, 100 | div.sphinxsidebar h4 { 101 | font-family: 'Garamond', 'Georgia', serif; 102 | color: #444; 103 | font-size: 24px; 104 | font-weight: normal; 105 | margin: 0 0 5px 0; 106 | padding: 0; 107 | } 108 | 109 | div.sphinxsidebar h4 { 110 | font-size: 20px; 111 | } 112 | 113 | div.sphinxsidebar h3 a { 114 | color: #444; 115 | } 116 | 117 | div.sphinxsidebar p.logo a, 118 | div.sphinxsidebar h3 a, 119 | div.sphinxsidebar p.logo a:hover, 120 | div.sphinxsidebar h3 a:hover { 121 | border: none; 122 | } 123 | 124 | div.sphinxsidebar p { 125 | color: #555; 126 | margin: 10px 0; 127 | } 128 | 129 | div.sphinxsidebar ul { 130 | margin: 10px 0; 131 | padding: 0; 132 | color: #000; 133 | } 134 | 135 | div.sphinxsidebar input { 136 | border: 1px solid #ccc; 137 | font-family: 'Georgia', serif; 138 | font-size: 1em; 139 | } 140 | 141 | /* -- body styles ----------------------------------------------------------- */ 142 | 143 | a { 144 | color: #004B6B; 145 | text-decoration: underline; 146 | } 147 | 148 | a:hover { 149 | color: #6D4100; 150 | text-decoration: underline; 151 | } 152 | 153 | div.body h1, 154 | div.body h2, 155 | div.body h3, 156 | div.body h4, 157 | div.body h5, 158 | div.body h6 { 159 | font-family: 'Garamond', 'Georgia', serif; 160 | font-weight: normal; 161 | margin: 30px 0px 10px 0px; 162 | padding: 0; 163 | } 164 | 165 | {% if theme_index_logo %} 166 | div.indexwrapper h1 { 167 | text-indent: -999999px; 168 | background: url({{ theme_index_logo }}) no-repeat center center; 169 | height: {{ theme_index_logo_height }}; 170 | } 171 | {% endif %} 172 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 173 | div.body h2 { font-size: 180%; } 174 | div.body h3 { font-size: 150%; } 175 | div.body h4 { font-size: 130%; } 176 | div.body h5 { font-size: 100%; } 177 | div.body h6 { font-size: 100%; } 178 | 179 | a.headerlink { 180 | color: #ddd; 181 | padding: 0 4px; 182 | text-decoration: none; 183 | } 184 | 185 | a.headerlink:hover { 186 | color: #444; 187 | background: #eaeaea; 188 | } 189 | 190 | div.body p, div.body dd, div.body li { 191 | line-height: 1.4em; 192 | } 193 | 194 | div.admonition { 195 | background: #fafafa; 196 | margin: 20px -30px; 197 | padding: 10px 30px; 198 | border-top: 1px solid #ccc; 199 | border-bottom: 1px solid #ccc; 200 | } 201 | 202 | div.admonition tt.xref, div.admonition a tt { 203 | border-bottom: 1px solid #fafafa; 204 | } 205 | 206 | dd div.admonition { 207 | margin-left: -60px; 208 | padding-left: 60px; 209 | } 210 | 211 | div.admonition p.admonition-title { 212 | font-family: 'Garamond', 'Georgia', serif; 213 | font-weight: normal; 214 | font-size: 24px; 215 | margin: 0 0 10px 0; 216 | padding: 0; 217 | line-height: 1; 218 | } 219 | 220 | div.admonition p.last { 221 | margin-bottom: 0; 222 | } 223 | 224 | div.highlight { 225 | background-color: white; 226 | } 227 | 228 | dt:target, .highlight { 229 | background: #FAF3E8; 230 | } 231 | 232 | div.note { 233 | background-color: #eee; 234 | border: 1px solid #ccc; 235 | } 236 | 237 | div.seealso { 238 | background-color: #ffc; 239 | border: 1px solid #ff6; 240 | } 241 | 242 | div.topic { 243 | background-color: #eee; 244 | } 245 | 246 | p.admonition-title { 247 | display: inline; 248 | } 249 | 250 | p.admonition-title:after { 251 | content: ":"; 252 | } 253 | 254 | pre, tt { 255 | font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 256 | font-size: 0.9em; 257 | } 258 | 259 | img.screenshot { 260 | } 261 | 262 | tt.descname, tt.descclassname { 263 | font-size: 0.95em; 264 | } 265 | 266 | tt.descname { 267 | padding-right: 0.08em; 268 | } 269 | 270 | img.screenshot { 271 | -moz-box-shadow: 2px 2px 4px #eee; 272 | -webkit-box-shadow: 2px 2px 4px #eee; 273 | box-shadow: 2px 2px 4px #eee; 274 | } 275 | 276 | table.docutils { 277 | border: 1px solid #888; 278 | -moz-box-shadow: 2px 2px 4px #eee; 279 | -webkit-box-shadow: 2px 2px 4px #eee; 280 | box-shadow: 2px 2px 4px #eee; 281 | } 282 | 283 | table.docutils td, table.docutils th { 284 | border: 1px solid #888; 285 | padding: 0.25em 0.7em; 286 | } 287 | 288 | table.field-list, table.footnote { 289 | border: none; 290 | -moz-box-shadow: none; 291 | -webkit-box-shadow: none; 292 | box-shadow: none; 293 | } 294 | 295 | table.footnote { 296 | margin: 15px 0; 297 | width: 100%; 298 | border: 1px solid #eee; 299 | background: #fdfdfd; 300 | font-size: 0.9em; 301 | } 302 | 303 | table.footnote + table.footnote { 304 | margin-top: -15px; 305 | border-top: none; 306 | } 307 | 308 | table.field-list th { 309 | padding: 0 0.8em 0 0; 310 | } 311 | 312 | table.field-list td { 313 | padding: 0; 314 | } 315 | 316 | table.footnote td.label { 317 | width: 0px; 318 | padding: 0.3em 0 0.3em 0.5em; 319 | } 320 | 321 | table.footnote td { 322 | padding: 0.3em 0.5em; 323 | } 324 | 325 | dl { 326 | margin: 0; 327 | padding: 0; 328 | } 329 | 330 | dl dd { 331 | margin-left: 30px; 332 | } 333 | 334 | blockquote { 335 | margin: 0 0 0 30px; 336 | padding: 0; 337 | } 338 | 339 | ul, ol { 340 | margin: 10px 0 10px 30px; 341 | padding: 0; 342 | } 343 | 344 | pre { 345 | background: #eee; 346 | padding: 7px 30px; 347 | margin: 15px -30px; 348 | line-height: 1.3em; 349 | } 350 | 351 | dl pre, blockquote pre, li pre { 352 | margin-left: -60px; 353 | padding-left: 60px; 354 | } 355 | 356 | dl dl pre { 357 | margin-left: -90px; 358 | padding-left: 90px; 359 | } 360 | 361 | tt { 362 | background-color: #ecf0f3; 363 | color: #222; 364 | /* padding: 1px 2px; */ 365 | } 366 | 367 | tt.xref, a tt { 368 | background-color: #FBFBFB; 369 | border-bottom: 1px solid white; 370 | } 371 | 372 | a.reference { 373 | text-decoration: none; 374 | border-bottom: 1px dotted #004B6B; 375 | } 376 | 377 | a.reference:hover { 378 | border-bottom: 1px solid #6D4100; 379 | } 380 | 381 | a.footnote-reference { 382 | text-decoration: none; 383 | font-size: 0.7em; 384 | vertical-align: top; 385 | border-bottom: 1px dotted #004B6B; 386 | } 387 | 388 | a.footnote-reference:hover { 389 | border-bottom: 1px solid #6D4100; 390 | } 391 | 392 | a:hover tt { 393 | background: #EEE; 394 | } 395 | 396 | 397 | @media screen and (max-width: 870px) { 398 | 399 | div.sphinxsidebar { 400 | display: none; 401 | } 402 | 403 | div.document { 404 | width: 100%; 405 | 406 | } 407 | 408 | div.documentwrapper { 409 | margin-left: 0; 410 | margin-top: 0; 411 | margin-right: 0; 412 | margin-bottom: 0; 413 | } 414 | 415 | div.bodywrapper { 416 | margin-top: 0; 417 | margin-right: 0; 418 | margin-bottom: 0; 419 | margin-left: 0; 420 | } 421 | 422 | ul { 423 | margin-left: 0; 424 | } 425 | 426 | .document { 427 | width: auto; 428 | } 429 | 430 | .footer { 431 | width: auto; 432 | } 433 | 434 | .bodywrapper { 435 | margin: 0; 436 | } 437 | 438 | .footer { 439 | width: auto; 440 | } 441 | 442 | .github { 443 | display: none; 444 | } 445 | 446 | 447 | 448 | } 449 | 450 | 451 | 452 | @media screen and (max-width: 875px) { 453 | 454 | body { 455 | margin: 0; 456 | padding: 20px 30px; 457 | } 458 | 459 | div.documentwrapper { 460 | float: none; 461 | background: white; 462 | } 463 | 464 | div.sphinxsidebar { 465 | display: block; 466 | float: none; 467 | width: 102.5%; 468 | margin: 50px -30px -20px -30px; 469 | padding: 10px 20px; 470 | background: #333; 471 | color: white; 472 | } 473 | 474 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 475 | div.sphinxsidebar h3 a { 476 | color: white; 477 | } 478 | 479 | div.sphinxsidebar a { 480 | color: #aaa; 481 | } 482 | 483 | div.sphinxsidebar p.logo { 484 | display: none; 485 | } 486 | 487 | div.document { 488 | width: 100%; 489 | margin: 0; 490 | } 491 | 492 | div.related { 493 | display: block; 494 | margin: 0; 495 | padding: 10px 0 20px 0; 496 | } 497 | 498 | div.related ul, 499 | div.related ul li { 500 | margin: 0; 501 | padding: 0; 502 | } 503 | 504 | div.footer { 505 | display: none; 506 | } 507 | 508 | div.bodywrapper { 509 | margin: 0; 510 | } 511 | 512 | div.body { 513 | min-height: 0; 514 | padding: 0; 515 | } 516 | 517 | .rtd_doc_footer { 518 | display: none; 519 | } 520 | 521 | .document { 522 | width: auto; 523 | } 524 | 525 | .footer { 526 | width: auto; 527 | } 528 | 529 | .footer { 530 | width: auto; 531 | } 532 | 533 | .github { 534 | display: none; 535 | } 536 | } 537 | 538 | 539 | /* scrollbars */ 540 | 541 | ::-webkit-scrollbar { 542 | width: 6px; 543 | height: 6px; 544 | } 545 | 546 | ::-webkit-scrollbar-button:start:decrement, 547 | ::-webkit-scrollbar-button:end:increment { 548 | display: block; 549 | height: 10px; 550 | } 551 | 552 | ::-webkit-scrollbar-button:vertical:increment { 553 | background-color: #fff; 554 | } 555 | 556 | ::-webkit-scrollbar-track-piece { 557 | background-color: #eee; 558 | -webkit-border-radius: 3px; 559 | } 560 | 561 | ::-webkit-scrollbar-thumb:vertical { 562 | height: 50px; 563 | background-color: #ccc; 564 | -webkit-border-radius: 3px; 565 | } 566 | 567 | ::-webkit-scrollbar-thumb:horizontal { 568 | width: 50px; 569 | background-color: #ccc; 570 | -webkit-border-radius: 3px; 571 | } 572 | 573 | /* misc. */ 574 | 575 | .revsys-inline { 576 | display: none!important; 577 | } -------------------------------------------------------------------------------- /docs/_themes/flask/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = flasky.css 4 | pygments_style = flask_theme_support.FlaskyStyle 5 | 6 | [options] 7 | index_logo = '' 8 | index_logo_height = 120px 9 | touch_icon = 10 | -------------------------------------------------------------------------------- /docs/_themes/flask_small/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "basic/layout.html" %} 2 | {% block header %} 3 | {{ super() }} 4 | {% if pagename == 'index' %} 5 |
6 | {% endif %} 7 | {% endblock %} 8 | {% block footer %} 9 | {% if pagename == 'index' %} 10 |
11 | {% endif %} 12 | {% endblock %} 13 | {# do not display relbars #} 14 | {% block relbar1 %}{% endblock %} 15 | {% block relbar2 %} 16 | {% if theme_github_fork %} 17 | Fork me on GitHub 19 | {% endif %} 20 | {% endblock %} 21 | {% block sidebar1 %}{% endblock %} 22 | {% block sidebar2 %}{% endblock %} 23 | -------------------------------------------------------------------------------- /docs/_themes/flask_small/static/flasky.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * flasky.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- flasky theme based on nature theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: 'Georgia', serif; 18 | font-size: 17px; 19 | color: #000; 20 | background: white; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.documentwrapper { 26 | float: left; 27 | width: 100%; 28 | } 29 | 30 | div.bodywrapper { 31 | margin: 40px auto 0 auto; 32 | width: 700px; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #ffffff; 41 | color: #3E4349; 42 | padding: 0 30px 30px 30px; 43 | } 44 | 45 | img.floatingflask { 46 | padding: 0 0 10px 10px; 47 | float: right; 48 | } 49 | 50 | div.footer { 51 | text-align: right; 52 | color: #888; 53 | padding: 10px; 54 | font-size: 14px; 55 | width: 650px; 56 | margin: 0 auto 40px auto; 57 | } 58 | 59 | div.footer a { 60 | color: #888; 61 | text-decoration: underline; 62 | } 63 | 64 | div.related { 65 | line-height: 32px; 66 | color: #888; 67 | } 68 | 69 | div.related ul { 70 | padding: 0 0 0 10px; 71 | } 72 | 73 | div.related a { 74 | color: #444; 75 | } 76 | 77 | /* -- body styles ----------------------------------------------------------- */ 78 | 79 | a { 80 | color: #004B6B; 81 | text-decoration: underline; 82 | } 83 | 84 | a:hover { 85 | color: #6D4100; 86 | text-decoration: underline; 87 | } 88 | 89 | div.body { 90 | padding-bottom: 40px; /* saved for footer */ 91 | } 92 | 93 | div.body h1, 94 | div.body h2, 95 | div.body h3, 96 | div.body h4, 97 | div.body h5, 98 | div.body h6 { 99 | font-family: 'Garamond', 'Georgia', serif; 100 | font-weight: normal; 101 | margin: 30px 0px 10px 0px; 102 | padding: 0; 103 | } 104 | 105 | {% if theme_index_logo %} 106 | div.indexwrapper h1 { 107 | text-indent: -999999px; 108 | background: url({{ theme_index_logo }}) no-repeat center center; 109 | height: {{ theme_index_logo_height }}; 110 | } 111 | {% endif %} 112 | 113 | div.body h2 { font-size: 180%; } 114 | div.body h3 { font-size: 150%; } 115 | div.body h4 { font-size: 130%; } 116 | div.body h5 { font-size: 100%; } 117 | div.body h6 { font-size: 100%; } 118 | 119 | a.headerlink { 120 | color: white; 121 | padding: 0 4px; 122 | text-decoration: none; 123 | } 124 | 125 | a.headerlink:hover { 126 | color: #444; 127 | background: #eaeaea; 128 | } 129 | 130 | div.body p, div.body dd, div.body li { 131 | line-height: 1.4em; 132 | } 133 | 134 | div.admonition { 135 | background: #fafafa; 136 | margin: 20px -30px; 137 | padding: 10px 30px; 138 | border-top: 1px solid #ccc; 139 | border-bottom: 1px solid #ccc; 140 | } 141 | 142 | div.admonition p.admonition-title { 143 | font-family: 'Garamond', 'Georgia', serif; 144 | font-weight: normal; 145 | font-size: 24px; 146 | margin: 0 0 10px 0; 147 | padding: 0; 148 | line-height: 1; 149 | } 150 | 151 | div.admonition p.last { 152 | margin-bottom: 0; 153 | } 154 | 155 | div.highlight{ 156 | background-color: white; 157 | } 158 | 159 | dt:target, .highlight { 160 | background: #FAF3E8; 161 | } 162 | 163 | div.note { 164 | background-color: #eee; 165 | border: 1px solid #ccc; 166 | } 167 | 168 | div.seealso { 169 | background-color: #ffc; 170 | border: 1px solid #ff6; 171 | } 172 | 173 | div.topic { 174 | background-color: #eee; 175 | } 176 | 177 | div.warning { 178 | background-color: #ffe4e4; 179 | border: 1px solid #f66; 180 | } 181 | 182 | p.admonition-title { 183 | display: inline; 184 | } 185 | 186 | p.admonition-title:after { 187 | content: ":"; 188 | } 189 | 190 | pre, tt { 191 | font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 192 | font-size: 0.85em; 193 | } 194 | 195 | img.screenshot { 196 | } 197 | 198 | tt.descname, tt.descclassname { 199 | font-size: 0.95em; 200 | } 201 | 202 | tt.descname { 203 | padding-right: 0.08em; 204 | } 205 | 206 | img.screenshot { 207 | -moz-box-shadow: 2px 2px 4px #eee; 208 | -webkit-box-shadow: 2px 2px 4px #eee; 209 | box-shadow: 2px 2px 4px #eee; 210 | } 211 | 212 | table.docutils { 213 | border: 1px solid #888; 214 | -moz-box-shadow: 2px 2px 4px #eee; 215 | -webkit-box-shadow: 2px 2px 4px #eee; 216 | box-shadow: 2px 2px 4px #eee; 217 | } 218 | 219 | table.docutils td, table.docutils th { 220 | border: 1px solid #888; 221 | padding: 0.25em 0.7em; 222 | } 223 | 224 | table.field-list, table.footnote { 225 | border: none; 226 | -moz-box-shadow: none; 227 | -webkit-box-shadow: none; 228 | box-shadow: none; 229 | } 230 | 231 | table.footnote { 232 | margin: 15px 0; 233 | width: 100%; 234 | border: 1px solid #eee; 235 | } 236 | 237 | table.field-list th { 238 | padding: 0 0.8em 0 0; 239 | } 240 | 241 | table.field-list td { 242 | padding: 0; 243 | } 244 | 245 | table.footnote td { 246 | padding: 0.5em; 247 | } 248 | 249 | dl { 250 | margin: 0; 251 | padding: 0; 252 | } 253 | 254 | dl dd { 255 | margin-left: 30px; 256 | } 257 | 258 | pre { 259 | padding: 0; 260 | margin: 15px -30px; 261 | padding: 8px; 262 | line-height: 1.3em; 263 | padding: 7px 30px; 264 | background: #eee; 265 | border-radius: 2px; 266 | -moz-border-radius: 2px; 267 | -webkit-border-radius: 2px; 268 | } 269 | 270 | dl pre { 271 | margin-left: -60px; 272 | padding-left: 60px; 273 | } 274 | 275 | tt { 276 | background-color: #ecf0f3; 277 | color: #222; 278 | /* padding: 1px 2px; */ 279 | } 280 | 281 | tt.xref, a tt { 282 | background-color: #FBFBFB; 283 | } 284 | 285 | a:hover tt { 286 | background: #EEE; 287 | } 288 | -------------------------------------------------------------------------------- /docs/_themes/flask_small/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = flasky.css 4 | nosidebar = true 5 | pygments_style = flask_theme_support.FlaskyStyle 6 | 7 | [options] 8 | index_logo = '' 9 | index_logo_height = 120px 10 | github_fork = '' 11 | -------------------------------------------------------------------------------- /docs/_themes/flask_theme_support.py: -------------------------------------------------------------------------------- 1 | # flasky extensions. flasky pygments style based on tango style 2 | from pygments.style import Style 3 | from pygments.token import Keyword, Name, Comment, String, Error, \ 4 | Number, Operator, Generic, Whitespace, Punctuation, Other, Literal 5 | 6 | 7 | class FlaskyStyle(Style): 8 | background_color = "#f8f8f8" 9 | default_style = "" 10 | 11 | styles = { 12 | # No corresponding class for the following: 13 | #Text: "", # class: '' 14 | Whitespace: "underline #f8f8f8", # class: 'w' 15 | Error: "#a40000 border:#ef2929", # class: 'err' 16 | Other: "#000000", # class 'x' 17 | 18 | Comment: "italic #8f5902", # class: 'c' 19 | Comment.Preproc: "noitalic", # class: 'cp' 20 | 21 | Keyword: "bold #004461", # class: 'k' 22 | Keyword.Constant: "bold #004461", # class: 'kc' 23 | Keyword.Declaration: "bold #004461", # class: 'kd' 24 | Keyword.Namespace: "bold #004461", # class: 'kn' 25 | Keyword.Pseudo: "bold #004461", # class: 'kp' 26 | Keyword.Reserved: "bold #004461", # class: 'kr' 27 | Keyword.Type: "bold #004461", # class: 'kt' 28 | 29 | Operator: "#582800", # class: 'o' 30 | Operator.Word: "bold #004461", # class: 'ow' - like keywords 31 | 32 | Punctuation: "bold #000000", # class: 'p' 33 | 34 | # because special names such as Name.Class, Name.Function, etc. 35 | # are not recognized as such later in the parsing, we choose them 36 | # to look the same as ordinary variables. 37 | Name: "#000000", # class: 'n' 38 | Name.Attribute: "#c4a000", # class: 'na' - to be revised 39 | Name.Builtin: "#004461", # class: 'nb' 40 | Name.Builtin.Pseudo: "#3465a4", # class: 'bp' 41 | Name.Class: "#000000", # class: 'nc' - to be revised 42 | Name.Constant: "#000000", # class: 'no' - to be revised 43 | Name.Decorator: "#888", # class: 'nd' - to be revised 44 | Name.Entity: "#ce5c00", # class: 'ni' 45 | Name.Exception: "bold #cc0000", # class: 'ne' 46 | Name.Function: "#000000", # class: 'nf' 47 | Name.Property: "#000000", # class: 'py' 48 | Name.Label: "#f57900", # class: 'nl' 49 | Name.Namespace: "#000000", # class: 'nn' - to be revised 50 | Name.Other: "#000000", # class: 'nx' 51 | Name.Tag: "bold #004461", # class: 'nt' - like a keyword 52 | Name.Variable: "#000000", # class: 'nv' - to be revised 53 | Name.Variable.Class: "#000000", # class: 'vc' - to be revised 54 | Name.Variable.Global: "#000000", # class: 'vg' - to be revised 55 | Name.Variable.Instance: "#000000", # class: 'vi' - to be revised 56 | 57 | Number: "#990000", # class: 'm' 58 | 59 | Literal: "#000000", # class: 'l' 60 | Literal.Date: "#000000", # class: 'ld' 61 | 62 | String: "#4e9a06", # class: 's' 63 | String.Backtick: "#4e9a06", # class: 'sb' 64 | String.Char: "#4e9a06", # class: 'sc' 65 | String.Doc: "italic #8f5902", # class: 'sd' - like a comment 66 | String.Double: "#4e9a06", # class: 's2' 67 | String.Escape: "#4e9a06", # class: 'se' 68 | String.Heredoc: "#4e9a06", # class: 'sh' 69 | String.Interpol: "#4e9a06", # class: 'si' 70 | String.Other: "#4e9a06", # class: 'sx' 71 | String.Regex: "#4e9a06", # class: 'sr' 72 | String.Single: "#4e9a06", # class: 's1' 73 | String.Symbol: "#4e9a06", # class: 'ss' 74 | 75 | Generic: "#000000", # class: 'g' 76 | Generic.Deleted: "#a40000", # class: 'gd' 77 | Generic.Emph: "italic #000000", # class: 'ge' 78 | Generic.Error: "#ef2929", # class: 'gr' 79 | Generic.Heading: "bold #000080", # class: 'gh' 80 | Generic.Inserted: "#00A000", # class: 'gi' 81 | Generic.Output: "#888", # class: 'go' 82 | Generic.Prompt: "#745334", # class: 'gp' 83 | Generic.Strong: "bold #000000", # class: 'gs' 84 | Generic.Subheading: "bold #800080", # class: 'gu' 85 | Generic.Traceback: "bold #a40000", # class: 'gt' 86 | } 87 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Sender documentation build configuration file, created by 4 | # sphinx-quickstart on Wed Jul 16 16:20:34 2014. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys 16 | import os 17 | 18 | # If extensions (or modules to document with autodoc) are in another directory, 19 | # add these directories to sys.path here. If the directory is relative to the 20 | # documentation root, use os.path.abspath to make it absolute, like shown here. 21 | sys.path.insert(0, os.path.abspath('..')) 22 | sys.path.append(os.path.abspath('_themes')) 23 | 24 | # -- General configuration ------------------------------------------------ 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | #needs_sphinx = '1.0' 28 | 29 | # Add any Sphinx extension module names here, as strings. They can be 30 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 31 | # ones. 32 | extensions = ['sphinx.ext.autodoc'] 33 | 34 | # Add any paths that contain templates here, relative to this directory. 35 | templates_path = ['_templates'] 36 | 37 | # The suffix of source filenames. 38 | source_suffix = '.rst' 39 | 40 | # The encoding of source files. 41 | #source_encoding = 'utf-8-sig' 42 | 43 | # The master toctree document. 44 | master_doc = 'index' 45 | 46 | # General information about the project. 47 | project = u'Sender' 48 | copyright = u'2014, Shipeng Feng' 49 | 50 | # The version info for the project you're documenting, acts as replacement for 51 | # |version| and |release|, also used in various other places throughout the 52 | # built documents. 53 | # 54 | import pkg_resources 55 | try: 56 | release = pkg_resources.get_distribution('sender').version 57 | except pkg_resources.DistributionNotFound: 58 | print('To build the documentation, the distribution information of sender') 59 | print('Has to be available. Run "setup.py develop" to setup the') 60 | print('metadata. A virtualenv is recommended!') 61 | sys.exit(1) 62 | del pkg_resources 63 | 64 | version = '.'.join(release.split('.')[:2]) 65 | 66 | # The language for content autogenerated by Sphinx. Refer to documentation 67 | # for a list of supported languages. 68 | #language = None 69 | 70 | # There are two options for replacing |today|: either, you set today to some 71 | # non-false value, then it is used: 72 | #today = '' 73 | # Else, today_fmt is used as the format for a strftime call. 74 | #today_fmt = '%B %d, %Y' 75 | 76 | # List of patterns, relative to source directory, that match files and 77 | # directories to ignore when looking for source files. 78 | exclude_patterns = ['_build'] 79 | 80 | # The reST default role (used for this markup: `text`) to use for all 81 | # documents. 82 | #default_role = None 83 | 84 | # If true, '()' will be appended to :func: etc. cross-reference text. 85 | #add_function_parentheses = True 86 | 87 | # If true, the current module name will be prepended to all description 88 | # unit titles (such as .. function::). 89 | #add_module_names = True 90 | 91 | # If true, sectionauthor and moduleauthor directives will be shown in the 92 | # output. They are ignored by default. 93 | #show_authors = False 94 | 95 | # The name of the Pygments (syntax highlighting) style to use. 96 | #pygments_style = 'sphinx' 97 | 98 | # A list of ignored prefixes for module index sorting. 99 | #modindex_common_prefix = [] 100 | 101 | # If true, keep warnings as "system message" paragraphs in the built documents. 102 | #keep_warnings = False 103 | 104 | 105 | # -- Options for HTML output ---------------------------------------------- 106 | 107 | # The theme to use for HTML and HTML Help pages. See the documentation for 108 | # a list of builtin themes. 109 | html_theme = 'flask_small' 110 | 111 | # Theme options are theme-specific and customize the look and feel of a theme 112 | # further. For a list of options available for each theme, see the 113 | # documentation. 114 | html_theme_options = { 115 | 'index_logo': 'sender.png', 116 | 'github_fork': 'fengsp/sender' 117 | } 118 | 119 | # Add any paths that contain custom themes here, relative to this directory. 120 | html_theme_path = ['_themes'] 121 | 122 | # The name for this set of Sphinx documents. If None, it defaults to 123 | # " v documentation". 124 | #html_title = None 125 | 126 | # A shorter title for the navigation bar. Default is the same as html_title. 127 | #html_short_title = None 128 | 129 | # The name of an image file (relative to this directory) to place at the top 130 | # of the sidebar. 131 | #html_logo = None 132 | 133 | # The name of an image file (within the static path) to use as favicon of the 134 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 135 | # pixels large. 136 | #html_favicon = None 137 | 138 | # Add any paths that contain custom static files (such as style sheets) here, 139 | # relative to this directory. They are copied after the builtin static files, 140 | # so a file named "default.css" will overwrite the builtin "default.css". 141 | html_static_path = ['_static'] 142 | 143 | # Add any extra paths that contain custom files (such as robots.txt or 144 | # .htaccess) here, relative to this directory. These files are copied 145 | # directly to the root of the documentation. 146 | #html_extra_path = [] 147 | 148 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 149 | # using the given strftime format. 150 | #html_last_updated_fmt = '%b %d, %Y' 151 | 152 | # If true, SmartyPants will be used to convert quotes and dashes to 153 | # typographically correct entities. 154 | #html_use_smartypants = True 155 | 156 | # Custom sidebar templates, maps document names to template names. 157 | #html_sidebars = {} 158 | 159 | # Additional templates that should be rendered to pages, maps page names to 160 | # template names. 161 | #html_additional_pages = {} 162 | 163 | # If false, no module index is generated. 164 | #html_domain_indices = True 165 | 166 | # If false, no index is generated. 167 | #html_use_index = True 168 | 169 | # If true, the index is split into individual pages for each letter. 170 | #html_split_index = False 171 | 172 | # If true, links to the reST sources are added to the pages. 173 | #html_show_sourcelink = True 174 | 175 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 176 | #html_show_sphinx = True 177 | 178 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 179 | #html_show_copyright = True 180 | 181 | # If true, an OpenSearch description file will be output, and all pages will 182 | # contain a tag referring to it. The value of this option must be the 183 | # base URL from which the finished HTML is served. 184 | #html_use_opensearch = '' 185 | 186 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 187 | #html_file_suffix = None 188 | 189 | # Output file base name for HTML help builder. 190 | htmlhelp_basename = 'Senderdoc' 191 | 192 | 193 | # -- Options for LaTeX output --------------------------------------------- 194 | 195 | latex_elements = { 196 | # The paper size ('letterpaper' or 'a4paper'). 197 | #'papersize': 'letterpaper', 198 | 199 | # The font size ('10pt', '11pt' or '12pt'). 200 | #'pointsize': '10pt', 201 | 202 | # Additional stuff for the LaTeX preamble. 203 | #'preamble': '', 204 | } 205 | 206 | # Grouping the document tree into LaTeX files. List of tuples 207 | # (source start file, target name, title, 208 | # author, documentclass [howto, manual, or own class]). 209 | latex_documents = [ 210 | ('index', 'Sender.tex', u'Sender Documentation', 211 | u'Shipeng Feng', 'manual'), 212 | ] 213 | 214 | # The name of an image file (relative to this directory) to place at the top of 215 | # the title page. 216 | #latex_logo = None 217 | 218 | # For "manual" documents, if this is true, then toplevel headings are parts, 219 | # not chapters. 220 | #latex_use_parts = False 221 | 222 | # If true, show page references after internal links. 223 | #latex_show_pagerefs = False 224 | 225 | # If true, show URL addresses after external links. 226 | #latex_show_urls = False 227 | 228 | # Documents to append as an appendix to all manuals. 229 | #latex_appendices = [] 230 | 231 | # If false, no module index is generated. 232 | #latex_domain_indices = True 233 | 234 | 235 | # -- Options for manual page output --------------------------------------- 236 | 237 | # One entry per manual page. List of tuples 238 | # (source start file, name, description, authors, manual section). 239 | man_pages = [ 240 | ('index', 'sender', u'Sender Documentation', 241 | [u'Shipeng Feng'], 1) 242 | ] 243 | 244 | # If true, show URL addresses after external links. 245 | #man_show_urls = False 246 | 247 | 248 | # -- Options for Texinfo output ------------------------------------------- 249 | 250 | # Grouping the document tree into Texinfo files. List of tuples 251 | # (source start file, target name, title, author, 252 | # dir menu entry, description, category) 253 | texinfo_documents = [ 254 | ('index', 'Sender', u'Sender Documentation', 255 | u'Shipeng Feng', 'Sender', 'One line description of project.', 256 | 'Miscellaneous'), 257 | ] 258 | 259 | # Documents to append as an appendix to all manuals. 260 | #texinfo_appendices = [] 261 | 262 | # If false, no module index is generated. 263 | #texinfo_domain_indices = True 264 | 265 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 266 | #texinfo_show_urls = 'footnote' 267 | 268 | # If true, do not generate a @detailmenu in the "Top" node's menu. 269 | #texinfo_no_detailmenu = False 270 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Sender 2 | ====== 3 | 4 | .. module:: sender 5 | 6 | Sender provides a simple interface to set up SMTP and send email messages. 7 | 8 | 9 | Installation 10 | ------------ 11 | 12 | Install with the following command:: 13 | 14 | $ pip install sender 15 | 16 | 17 | Quickstart 18 | ---------- 19 | 20 | Sender is really easy to use. Emails are managed through a :class:`Mail` 21 | instance:: 22 | 23 | from sender import Mail 24 | 25 | mail = Mail() 26 | 27 | mail.send_message("Hello", fromaddr="from@example.com", 28 | to="to@example.com", body="Hello world!") 29 | 30 | 31 | Message 32 | ------- 33 | 34 | To send one message, we need to create a :class:`Message` instance:: 35 | 36 | from sender import Message 37 | 38 | msg = Message("demo subject", fromaddr="from@example.com", 39 | to="to@example.com") 40 | 41 | You can also set attribute individually:: 42 | 43 | msg.body = "demo body" 44 | 45 | It is possible to set ``fromaddr`` with a two-element tuple:: 46 | 47 | # fromaddr will be "Name " 48 | msg = Message("Hello", fromaddr=("Name", "name@example.com")) 49 | 50 | The message could have a plain text body and(or) HTML:: 51 | 52 | msg.body = "hello" 53 | msg.html = "

hello

" 54 | 55 | Let's construct one full message with all options:: 56 | 57 | msg = Message("msg subject") 58 | msg.fromaddr = ("Admin", "admin@example.com") 59 | msg.to = "to@example.com" 60 | msg.body = "this is a msg plain text body" 61 | msg.html = "Hello" 62 | msg.cc = "cc@example.com" 63 | msg.bcc = ["bcc01@example.com", "bcc02@example.com"] 64 | msg.reply_to = "reply@example.com" 65 | msg.date = time.time() 66 | msg.charset = "utf-8" 67 | msg.extra_headers = {} 68 | msg.mail_options = [] 69 | msg.rcpt_options = [] 70 | 71 | 72 | Mail 73 | ---- 74 | 75 | To connect to the SMTP server and send messages, we need to create a 76 | :class:`Mail` instance:: 77 | 78 | from sender import Mail 79 | 80 | mail = Mail("localhost", port=25, username="username", password="pass", 81 | use_tls=False, use_ssl=False, debug_level=None) 82 | 83 | You can set ``fromaddr`` to a mail instance, if the message sent by this mail 84 | instance does not set ``fromaddr``, this global ``fromaddr`` will be used:: 85 | 86 | mail.fromaddr = ("Name", "name@example.com") 87 | 88 | Now let's send our messages:: 89 | 90 | mail.send(msg) 91 | # or an iterable of messages 92 | mail.send([msg1, msg2, msg3]) 93 | 94 | There is one shortcut for sending one message quickly:: 95 | 96 | mail.send_message("hello", to="to@example.com", body="hello body") 97 | 98 | 99 | Attachment 100 | ---------- 101 | 102 | It is quite easy to add attachments, we need :class:`Attachment` instance:: 103 | 104 | from sender import Attachment 105 | 106 | with open("logo.jpg") as f: 107 | attachment = Attachment("logo.jpg", "image/jpeg", f.read()) 108 | 109 | msg.attach(attachment) 110 | 111 | If you have multiple attachments:: 112 | 113 | msg.attach(attach01) 114 | msg.attach(attach02) 115 | msg.attach(attach03) 116 | # or an iterable of attachments 117 | msg.attach((attach01, attach02, attach03)) 118 | 119 | There is one shortcut for attaching one attachment quickly:: 120 | 121 | msg.attach_attachment("logo.jpg", "image/jpeg", raw_data) 122 | 123 | 124 | API 125 | --- 126 | 127 | .. autoclass:: Mail 128 | :members: 129 | 130 | .. autoclass:: Message 131 | :members: attach, attach_attachment 132 | 133 | .. autoclass:: Attachment 134 | 135 | 136 | .. include:: ../CHANGES 137 | 138 | 139 | Contribute 140 | ---------- 141 | 142 | Pull requests are welcomed, thank you for your suggestions! 143 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Sender.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Sender.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /examples/example.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | example 4 | ~~~~~~~ 5 | 6 | Demo simple SMTP mail. 7 | 8 | :copyright: (c) 2014 by Shipeng Feng. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | from sender import Mail, Message, Attachment 12 | 13 | 14 | SMTP_HOST = 'smtp.example.com' 15 | SMTP_USER = 'user@example.com' 16 | SMTP_PASS = 'password' 17 | SMTP_ADDRESS = 'user@example.com' 18 | 19 | 20 | mail = Mail(host=SMTP_HOST, username=SMTP_USER, password=SMTP_PASS, 21 | fromaddr=SMTP_ADDRESS) 22 | 23 | 24 | msg01 = Message("Hello01", to="to@example.com", body="hello world") 25 | 26 | 27 | msg02 = Message("Hello02", to="to@example.com") 28 | msg02.fromaddr = ('no-reply', 'no-reply@example.com') 29 | msg02.body = "hello world!" 30 | 31 | 32 | msg03 = Message("Hello03", to="to@example.com") 33 | msg03.fromaddr = (u'请勿回复', 'noreply@example.com') 34 | msg03.body = u"你好世界" # Chinese :) 35 | msg03.html = u"你好世界" 36 | 37 | 38 | msg04 = Message("Hello04", body="Hello world 04") 39 | msg04.to = "to@example.com" 40 | msg04.cc = ["cc01@example.com", "cc02@example"] 41 | msg04.bcc = ["bcc@example.com"] 42 | 43 | 44 | msg05 = Message("Hello05", to="to@example.com", body="Hello world 05") 45 | with open("../docs/_static/sender.png") as f: 46 | msg05.attach_attachment("sender.png", "image/png", f.read()) 47 | 48 | 49 | msg06 = Message("Hello06", to="to@example.com", body="Hello world 06") 50 | with open("test.txt") as f: 51 | attachment = Attachment("test.txt", "text/plain", f.read()) 52 | msg06.attach(attachment) 53 | 54 | 55 | mail.send([msg01, msg02, msg03, msg04, msg05, msg06]) 56 | -------------------------------------------------------------------------------- /examples/test.txt: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /logo/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengsp/sender/26f052ea7bd07ece5d20b3e731b086c91a2e0cc3/logo/logo.psd -------------------------------------------------------------------------------- /sender.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | sender 4 | ~~~~~~ 5 | 6 | Python SMTP Client for Humans. 7 | 8 | :copyright: (c) 2016 by Shipeng Feng. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | __version__ = '0.3' 13 | 14 | import sys 15 | import smtplib 16 | import time 17 | from email import charset 18 | from email.encoders import encode_base64 19 | from email.mime.base import MIMEBase 20 | from email.mime.text import MIMEText 21 | from email.mime.multipart import MIMEMultipart 22 | from email.utils import make_msgid, formataddr, parseaddr, formatdate 23 | from email.header import Header 24 | 25 | 26 | charset.add_charset('utf-8', charset.SHORTEST, None, 'utf-8') 27 | 28 | 29 | PY2 = sys.version_info[0] == 2 30 | if not PY2: 31 | text_type = str 32 | string_types = (str,) 33 | integer_types = (int,) 34 | 35 | iterkeys = lambda d: iter(d.keys()) 36 | itervalues = lambda d: iter(d.values()) 37 | iteritems = lambda d: iter(d.items()) 38 | else: 39 | text_type = unicode 40 | string_types = (str, unicode) 41 | integer_types = (int, long) 42 | 43 | iterkeys = lambda d: d.iterkeys() 44 | itervalues = lambda d: d.itervalues() 45 | iteritems = lambda d: d.iteritems() 46 | 47 | 48 | class Mail(object): 49 | """Sender Mail main class. This class is used for manage SMTP server 50 | connections and send messages. 51 | 52 | :param host: smtp server host, default to be 'localhost' 53 | :param username: smtp server authentication username 54 | :param password: smtp server authentication password 55 | :param port: smtp server port, default to be 25 56 | :param use_tls: put the SMTP connection in TLS (Transport Layer Security) 57 | mode, default to be False 58 | :param use_ssl: put the SMTP connection in SSL mode, default to be False 59 | :param debug_level: the debug output level 60 | :param fromaddr: default sender for all messages sent by this mail instance 61 | """ 62 | 63 | def __init__(self, host='localhost', username=None, password=None, 64 | port=25, use_tls=False, use_ssl=False, debug_level=None, 65 | fromaddr=None): 66 | self.host = host 67 | self.port = port 68 | self.username = username 69 | self.password = password 70 | self.use_tls = use_tls 71 | self.use_ssl = use_ssl 72 | self.debug_level = debug_level 73 | self.fromaddr = fromaddr 74 | 75 | @property 76 | def connection(self): 77 | """Open one connection to the SMTP server. 78 | """ 79 | return Connection(self) 80 | 81 | def send(self, message_or_messages): 82 | """Sends a single messsage or multiple messages. 83 | 84 | :param message_or_messages: one message instance or one iterable of 85 | message instances. 86 | """ 87 | try: 88 | messages = iter(message_or_messages) 89 | except TypeError: 90 | messages = [message_or_messages] 91 | 92 | with self.connection as c: 93 | for message in messages: 94 | if self.fromaddr and not message.fromaddr: 95 | message.fromaddr = self.fromaddr 96 | message.validate() 97 | c.send(message) 98 | 99 | def send_message(self, *args, **kwargs): 100 | """Shortcut for send. 101 | """ 102 | self.send(Message(*args, **kwargs)) 103 | 104 | 105 | class Connection(object): 106 | """This class handles connection to the SMTP server. Instance of this 107 | class would be one context manager so that you do not have to manage 108 | connection close manually. 109 | 110 | TODO: connection pool? 111 | 112 | :param mail: one mail instance 113 | """ 114 | 115 | def __init__(self, mail): 116 | self.mail = mail 117 | 118 | def __enter__(self): 119 | if self.mail.use_ssl: 120 | server = smtplib.SMTP_SSL(self.mail.host, self.mail.port) 121 | else: 122 | server = smtplib.SMTP(self.mail.host, self.mail.port) 123 | 124 | # Set the debug output level 125 | if self.mail.debug_level is not None: 126 | server.set_debuglevel(int(self.mail.debug_level)) 127 | 128 | if self.mail.use_tls: 129 | server.starttls() 130 | 131 | if self.mail.username and self.mail.password: 132 | server.login(self.mail.username, self.mail.password) 133 | 134 | self.server = server 135 | 136 | return self 137 | 138 | def __exit__(self, exc_type, exc_value, exc_tb): 139 | self.server.quit() 140 | 141 | def send(self, message): 142 | """Send one message instance. 143 | 144 | :param message: one message instance. 145 | """ 146 | self.server.sendmail(message.fromaddr, message.to_addrs, 147 | str(message) if PY2 else message.as_bytes(), 148 | message.mail_options, message.rcpt_options) 149 | 150 | 151 | class AddressAttribute(object): 152 | """Makes an address attribute forward to the addrs""" 153 | 154 | def __init__(self, name): 155 | self.__name__ = name 156 | 157 | def __get__(self, obj, type=None): 158 | if obj is None: 159 | return self 160 | return obj.addrs[self.__name__] 161 | 162 | def __set__(self, obj, value): 163 | if value is None: 164 | obj.addrs[self.__name__] = value 165 | return 166 | 167 | if self.__name__ in ('to', 'cc', 'bcc'): 168 | if isinstance(value, string_types): 169 | value = [value] 170 | if self.__name__ == 'fromaddr': 171 | value = process_address(parse_fromaddr(value), obj.charset) 172 | elif self.__name__ in ('to', 'cc', 'bcc'): 173 | value = set(process_addresses(value, obj.charset)) 174 | elif self.__name__ == 'reply_to': 175 | value = process_address(value, obj.charset) 176 | obj.addrs[self.__name__] = value 177 | 178 | 179 | class Message(object): 180 | """One email message. 181 | 182 | :param subject: message subject 183 | :param to: message recipient, should be one or a list of addresses 184 | :param body: plain text content body 185 | :param html: HTML content body 186 | :param fromaddr: message sender, can be one address or a two-element tuple 187 | :param cc: CC list, should be one or a list of addresses 188 | :param bcc: BCC list, should be one or a list of addresses 189 | :param attachments: a list of attachment instances 190 | :param reply_to: reply-to address 191 | :param date: message send date, seconds since the Epoch, 192 | default to be time.time() 193 | :param charset: message charset, default to be 'utf-8' 194 | :param extra_headers: a dictionary of extra headers 195 | :param mail_options: a list of ESMTP options used in MAIL FROM commands 196 | :param rcpt_options: a list of ESMTP options used in RCPT commands 197 | """ 198 | 199 | to = AddressAttribute('to') 200 | fromaddr = AddressAttribute('fromaddr') 201 | cc = AddressAttribute('cc') 202 | bcc = AddressAttribute('bcc') 203 | reply_to = AddressAttribute('reply_to') 204 | 205 | def __init__(self, subject=None, to=None, body=None, html=None, 206 | fromaddr=None, cc=None, bcc=None, attachments=None, 207 | reply_to=None, date=None, charset='utf-8', 208 | extra_headers=None, mail_options=None, rcpt_options=None): 209 | self.message_id = make_msgid() 210 | self.subject = subject 211 | self.body = body 212 | self.html = html 213 | self.attachments = attachments or [] 214 | self.date = date 215 | self.charset = charset 216 | self.extra_headers = extra_headers 217 | self.mail_options = mail_options or [] 218 | self.rcpt_options = rcpt_options or [] 219 | # used for actual addresses store 220 | self.addrs = dict() 221 | # set address 222 | self.to = to or [] 223 | self.fromaddr = fromaddr 224 | self.cc = cc or [] 225 | self.bcc = bcc or [] 226 | self.reply_to = reply_to 227 | 228 | @property 229 | def to_addrs(self): 230 | return self.to | self.cc | self.bcc 231 | 232 | def validate(self): 233 | """Do email message validation. 234 | """ 235 | if not (self.to or self.cc or self.bcc): 236 | raise SenderError("does not specify any recipients(to,cc,bcc)") 237 | if not self.fromaddr: 238 | raise SenderError("does not specify fromaddr(sender)") 239 | for c in '\r\n': 240 | if self.subject and (c in self.subject): 241 | raise SenderError('newline is not allowed in subject') 242 | 243 | def as_string(self): 244 | """The message string. 245 | """ 246 | if self.date is None: 247 | self.date = time.time() 248 | 249 | if not self.html: 250 | if len(self.attachments) == 0: 251 | # plain text 252 | msg = MIMEText(self.body, 'plain', self.charset) 253 | elif len(self.attachments) > 0: 254 | # plain text with attachments 255 | msg = MIMEMultipart() 256 | msg.attach(MIMEText(self.body, 'plain', self.charset)) 257 | else: 258 | msg = MIMEMultipart() 259 | alternative = MIMEMultipart('alternative') 260 | alternative.attach(MIMEText(self.body, 'plain', self.charset)) 261 | alternative.attach(MIMEText(self.html, 'html', self.charset)) 262 | msg.attach(alternative) 263 | 264 | msg['Subject'] = Header(self.subject, self.charset) 265 | msg['From'] = self.fromaddr 266 | msg['To'] = ', '.join(self.to) 267 | msg['Date'] = formatdate(self.date, localtime=True) 268 | msg['Message-ID'] = self.message_id 269 | if self.cc: 270 | msg['Cc'] = ', '.join(self.cc) 271 | if self.reply_to: 272 | msg['Reply-To'] = self.reply_to 273 | if self.extra_headers: 274 | for key, value in self.extra_headers.items(): 275 | msg[key] = value 276 | 277 | for attachment in self.attachments: 278 | f = MIMEBase(*attachment.content_type.split('/')) 279 | f.set_payload(attachment.data) 280 | encode_base64(f) 281 | if attachment.filename is None: 282 | filename = str(None) 283 | else: 284 | filename = force_text(attachment.filename, self.charset) 285 | try: 286 | filename.encode('ascii') 287 | except UnicodeEncodeError: 288 | if PY2: 289 | filename = filename.encode('utf-8') 290 | filename = ('UTF8', '', filename) 291 | f.add_header('Content-Disposition', attachment.disposition, 292 | filename=filename) 293 | for key, value in attachment.headers.items(): 294 | f.add_header(key, value) 295 | msg.attach(f) 296 | 297 | return msg.as_string() 298 | 299 | def as_bytes(self): 300 | return self.as_string().encode(self.charset or 'utf-8') 301 | 302 | def __str__(self): 303 | return self.as_string() 304 | 305 | def attach(self, attachment_or_attachments): 306 | """Adds one or a list of attachments to the message. 307 | 308 | :param attachment_or_attachments: one or an iterable of attachments 309 | """ 310 | try: 311 | attachments = iter(attachment_or_attachments) 312 | except TypeError: 313 | attachments = [attachment_or_attachments] 314 | self.attachments.extend(attachments) 315 | 316 | def attach_attachment(self, *args, **kwargs): 317 | """Shortcut for attach. 318 | """ 319 | self.attach(Attachment(*args, **kwargs)) 320 | 321 | 322 | class Attachment(object): 323 | """File attachment information. 324 | 325 | :param filename: filename 326 | :param content_type: file mimetype 327 | :param data: raw data 328 | :param disposition: content-disposition, default to be 'attachment' 329 | :param headers: a dictionary of headers, default to be {} 330 | """ 331 | 332 | def __init__(self, filename=None, content_type=None, data=None, 333 | disposition='attachment', headers={}): 334 | self.filename = filename 335 | self.content_type = content_type 336 | self.data = data 337 | self.disposition = disposition 338 | self.headers = headers 339 | 340 | 341 | def parse_fromaddr(fromaddr): 342 | """Generate an RFC 822 from-address string. 343 | 344 | Simple usage:: 345 | 346 | >>> parse_fromaddr('from@example.com') 347 | 'from@example.com' 348 | >>> parse_fromaddr(('from', 'from@example.com')) 349 | 'from ' 350 | 351 | :param fromaddr: string or tuple 352 | """ 353 | if isinstance(fromaddr, tuple): 354 | fromaddr = "%s <%s>" % fromaddr 355 | return fromaddr 356 | 357 | 358 | class SenderUnicodeDecodeError(UnicodeDecodeError): 359 | def __init__(self, obj, *args): 360 | self.obj = obj 361 | UnicodeDecodeError.__init__(self, *args) 362 | 363 | def __str__(self): 364 | original = UnicodeDecodeError.__str__(self) 365 | return '%s. You passed in %r (%s)' % (original, self.obj, 366 | type(self.obj)) 367 | 368 | 369 | class SenderError(Exception): 370 | pass 371 | 372 | 373 | def force_text(s, encoding='utf-8', errors='strict'): 374 | """Returns a unicode object representing 's'. Treats bytestrings using 375 | the 'encoding' codec. 376 | 377 | :param s: one string 378 | :param encoding: the input encoding 379 | :param errors: values that are accepted by Python’s unicode() function 380 | for its error handling 381 | """ 382 | if isinstance(s, text_type): 383 | return s 384 | 385 | try: 386 | if not isinstance(s, string_types): 387 | if not PY2: 388 | if isinstance(s, bytes): 389 | s = text_type(s, encoding, errors) 390 | else: 391 | s = text_type(s) 392 | elif hasattr(s, '__unicode__'): 393 | s = s.__unicode__() 394 | else: 395 | s = text_type(bytes(s), encoding, errors) 396 | else: 397 | s = s.decode(encoding, errors) 398 | except UnicodeDecodeError as e: 399 | if not isinstance(s, Exception): 400 | raise SenderUnicodeDecodeError(s, *e.args) 401 | else: 402 | s = ' '.join([force_text(arg, encoding, errors) for arg in s]) 403 | return s 404 | 405 | 406 | def process_address(address, encoding='utf-8'): 407 | """Process one email address. 408 | 409 | :param address: email from-address string 410 | """ 411 | name, addr = parseaddr(force_text(address, encoding)) 412 | 413 | try: 414 | name = Header(name, encoding).encode() 415 | except UnicodeEncodeError: 416 | name = Header(name, 'utf-8').encode() 417 | try: 418 | addr.encode('ascii') 419 | except UnicodeEncodeError: 420 | if '@' in addr: 421 | localpart, domain = addr.split('@', 1) 422 | localpart = str(Header(localpart, encoding)) 423 | domain = domain.encode('idna').decode('ascii') 424 | addr = '@'.join([localpart, domain]) 425 | else: 426 | addr = Header(addr, encoding).encode() 427 | return formataddr((name, addr)) 428 | 429 | 430 | def process_addresses(addresses, encoding='utf-8'): 431 | return map(lambda e: process_address(e, encoding), addresses) 432 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sender 3 | ------ 4 | 5 | Sender is easy 6 | `````````````` 7 | 8 | .. code:: python 9 | 10 | from sender import Mail 11 | 12 | mail = Mail() 13 | 14 | mail.send_message("Hello", fromaddr="from@example.com", 15 | to="to@example.com", body="Hello world!") 16 | 17 | Install 18 | ``````` 19 | 20 | .. code:: bash 21 | 22 | $ pip install sender 23 | 24 | Links 25 | ````` 26 | 27 | * `documentation `_ 28 | * `github `_ 29 | * `development version 30 | `_ 31 | 32 | """ 33 | from setuptools import setup 34 | 35 | 36 | setup( 37 | name='sender', 38 | version='0.3', 39 | url='https://github.com/fengsp/sender', 40 | license='BSD', 41 | author='Shipeng Feng', 42 | author_email='fsp261@gmail.com', 43 | description='Python SMTP Client for Humans', 44 | long_description=__doc__, 45 | py_modules= ['sender',], 46 | zip_safe=False, 47 | classifiers=[ 48 | 'Development Status :: 4 - Beta', 49 | 'Intended Audience :: Developers', 50 | 'License :: OSI Approved :: BSD License', 51 | 'Programming Language :: Python', 52 | 'Programming Language :: Python :: 2.6', 53 | 'Programming Language :: Python :: 2.7', 54 | 'Programming Language :: Python :: 3', 55 | 'Programming Language :: Python :: 3.3', 56 | 'Programming Language :: Python :: 3.4', 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /test_sender.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | test_sender 5 | ~~~~~~~~~~~ 6 | 7 | Run tests for Sender. 8 | 9 | :copyright: (c) 2016 by Shipeng Feng. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | import sys 13 | import unittest 14 | 15 | from sender import Mail, Message, Attachment 16 | from sender import SenderError 17 | 18 | 19 | class BaseTestCase(unittest.TestCase): 20 | """Baseclass for all the tests that sender uses. We use this 21 | BaseTestCase for code style consistency. 22 | """ 23 | 24 | def setup(self): 25 | pass 26 | 27 | def teardown(self): 28 | pass 29 | 30 | def setUp(self): 31 | self.setup() 32 | 33 | def tearDown(self): 34 | unittest.TestCase.tearDown(self) 35 | self.teardown() 36 | 37 | def assert_equal(self, first, second): 38 | return self.assertEqual(first, second) 39 | 40 | def assert_true(self, expr, msg=None): 41 | self.assertTrue(expr, msg) 42 | 43 | def assert_false(self, expr, msg=None): 44 | self.assertFalse(expr, msg) 45 | 46 | def assert_raises(self, exception, callable=None, *args, **kwargs): 47 | self.assertRaises(exception, callable, *args, **kwargs) 48 | 49 | def assert_in(self, first, second): 50 | self.assertIn(first, second) 51 | 52 | def assert_not_in(self, first, second): 53 | self.assertNotIn(first, second) 54 | 55 | def assert_isinstance(self, obj, cls): 56 | self.assertIsInstance(obj, cls) 57 | 58 | if sys.version_info[:2] == (2, 6): 59 | def assertIn(self, x, y): 60 | assert x in y, "%r not found in %r" % (x, y) 61 | 62 | def assertNotIn(self, x, y): 63 | assert x not in y, "%r unexpectedly in %r" % (x, y) 64 | 65 | def assertIsInstance(self, x, y): 66 | assert isinstance(x, y), "not isinstance(%r, %r)" % (x, y) 67 | 68 | 69 | class MailTestCase(BaseTestCase): 70 | 71 | def test_global_fromaddr(self): 72 | pass 73 | 74 | 75 | class MessageTestCase(BaseTestCase): 76 | 77 | def test_subject(self): 78 | msg = Message('test') 79 | self.assert_equal(msg.subject, 'test') 80 | msg = Message('test', fromaddr='from@example.com', to='to@example.com') 81 | self.assert_in(msg.subject, str(msg)) 82 | 83 | def test_to(self): 84 | msg = Message(fromaddr='from@example.com', to='to@example.com') 85 | self.assert_equal(msg.to, set(['to@example.com'])) 86 | self.assert_in('to@example.com', str(msg)) 87 | msg = Message(to=['to01@example.com', 'to02@example.com']) 88 | self.assert_equal(msg.to, set(['to01@example.com', 89 | 'to02@example.com'])) 90 | 91 | def test_fromaddr(self): 92 | msg = Message(fromaddr='from@example.com', to='to@example.com') 93 | self.assert_equal(msg.fromaddr, 'from@example.com') 94 | self.assert_in('from@example.com', str(msg)) 95 | msg = Message() 96 | msg.fromaddr = ('From', 'from@example.com') 97 | self.assert_in('', str(msg)) 98 | 99 | def test_cc(self): 100 | msg = Message(fromaddr='from@example.com', to='to@example.com', 101 | cc='cc@example.com') 102 | self.assert_in('cc@example.com', str(msg)) 103 | 104 | def test_bcc(self): 105 | msg = Message(fromaddr='from@example.com', to='to@example.com', 106 | bcc='bcc@example.com') 107 | self.assert_not_in('bcc@example.com', str(msg)) 108 | 109 | def test_reply_to(self): 110 | msg = Message(fromaddr='from@example.com', to='to@example.com', 111 | reply_to='reply-to@example.com') 112 | self.assert_equal(msg.reply_to, 'reply-to@example.com') 113 | self.assert_in('reply-to@example.com', str(msg)) 114 | 115 | def test_process_address(self): 116 | msg = Message(fromaddr=('From\r\n', 'from\r\n@example.com'), 117 | to='to\r@example.com', reply_to='reply-to\n@example.com') 118 | self.assert_in('', str(msg)) 119 | self.assert_in('to@example.com', str(msg)) 120 | self.assert_in('reply-to@example.com', str(msg)) 121 | 122 | def test_charset(self): 123 | msg = Message() 124 | self.assert_equal(msg.charset, 'utf-8') 125 | msg = Message(charset='ascii') 126 | self.assert_equal(msg.charset, 'ascii') 127 | 128 | def test_extra_headers(self): 129 | msg = Message(fromaddr='from@example.com', to='to@example.com', 130 | extra_headers={'Extra-Header-Test': 'Test'}) 131 | self.assert_in('Extra-Header-Test: Test', str(msg)) 132 | 133 | def test_mail_and_rcpt_options(self): 134 | msg = Message() 135 | self.assert_equal(msg.mail_options, []) 136 | self.assert_equal(msg.rcpt_options, []) 137 | msg = Message(mail_options=['BODY=8BITMIME']) 138 | self.assert_equal(msg.mail_options, ['BODY=8BITMIME']) 139 | msg = Message(rcpt_options=['NOTIFY=OK']) 140 | self.assert_equal(msg.rcpt_options, ['NOTIFY=OK']) 141 | 142 | def test_to_addrs(self): 143 | msg = Message(to='to@example.com') 144 | self.assert_equal(msg.to_addrs, set(['to@example.com'])) 145 | msg = Message(to='to@example.com', cc='cc@example.com', 146 | bcc=['bcc01@example.com', 'bcc02@example.com']) 147 | expected_to_addrs = set(['to@example.com', 'cc@example.com', 148 | 'bcc01@example.com', 'bcc02@example.com']) 149 | self.assert_equal(msg.to_addrs, expected_to_addrs) 150 | msg = Message(to='to@example.com', cc='to@example.com') 151 | self.assert_equal(msg.to_addrs, set(['to@example.com'])) 152 | 153 | def test_validate(self): 154 | msg = Message(fromaddr='from@example.com') 155 | self.assert_raises(SenderError, msg.validate) 156 | msg = Message(to='to@example.com') 157 | self.assert_raises(SenderError, msg.validate) 158 | msg = Message(subject='subject\r', fromaddr='from@example.com', 159 | to='to@example.com') 160 | self.assert_raises(SenderError, msg.validate) 161 | msg = Message(subject='subject\n', fromaddr='from@example.com', 162 | to='to@example.com') 163 | self.assert_raises(SenderError, msg.validate) 164 | 165 | def test_attach(self): 166 | msg = Message() 167 | att = Attachment() 168 | atts = [Attachment() for i in range(3)] 169 | msg.attach(att) 170 | self.assert_equal(msg.attachments, [att]) 171 | msg.attach(atts) 172 | self.assert_equal(msg.attachments, [att] + atts) 173 | 174 | def test_attach_attachment(self): 175 | msg = Message() 176 | msg.attach_attachment('test.txt', 'text/plain', 'this is test') 177 | self.assert_equal(msg.attachments[0].filename, 'test.txt') 178 | self.assert_equal(msg.attachments[0].content_type, 'text/plain') 179 | self.assert_equal(msg.attachments[0].data, 'this is test') 180 | 181 | def test_plain_text(self): 182 | plain_text = 'Hello!\nIt works.' 183 | msg = Message(fromaddr='from@example.com', to='to@example.com', 184 | body=plain_text) 185 | self.assert_equal(msg.body, plain_text) 186 | self.assert_in('Content-Type: text/plain', str(msg)) 187 | 188 | def test_plain_text_with_attachments(self): 189 | msg = Message(fromaddr='from@example.com', to='to@example.com', 190 | subject='hello', body='hello world') 191 | msg.attach_attachment(content_type='text/plain', data=b'this is test') 192 | self.assert_in('Content-Type: multipart/mixed', str(msg)) 193 | 194 | def test_html(self): 195 | html_text = 'Hello
It works.' 196 | msg = Message(fromaddr='from@example.com', to='to@example.com', 197 | html=html_text) 198 | self.assert_equal(msg.html, html_text) 199 | self.assert_in('Content-Type: multipart/alternative', str(msg)) 200 | 201 | def test_message_id(self): 202 | msg = Message(fromaddr='from@example.com', to='to@example.com') 203 | self.assert_in('Message-ID: %s' % msg.message_id, str(msg)) 204 | 205 | def test_attachment_ascii_filename(self): 206 | msg = Message(fromaddr='from@example.com', to='to@example.com') 207 | msg.attach_attachment('my test doc.txt', 'text/plain', b'this is test') 208 | self.assert_in('Content-Disposition: attachment; filename=' 209 | '"my test doc.txt"', str(msg)) 210 | 211 | def test_attachment_unicode_filename(self): 212 | msg = Message(fromaddr='from@example.com', to='to@example.com') 213 | # Chinese filename :) 214 | msg.attach_attachment(u'我的测试文档.txt', 'text/plain', 215 | 'this is test') 216 | self.assert_in('UTF8\'\'%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF' 217 | '%95%E6%96%87%E6%A1%A3.txt', str(msg)) 218 | 219 | 220 | class AttachmentTestCase(BaseTestCase): 221 | 222 | def test_disposition(self): 223 | attach = Attachment() 224 | self.assert_equal(attach.disposition, 'attachment') 225 | 226 | def test_headers(self): 227 | attach = Attachment() 228 | self.assert_equal(attach.headers, {}) 229 | 230 | 231 | class SenderTestCase(BaseTestCase): 232 | pass 233 | 234 | 235 | def suite(): 236 | """A testsuite that has all the sender tests. 237 | """ 238 | suite = unittest.TestSuite() 239 | suite.addTest(unittest.makeSuite(MailTestCase)) 240 | suite.addTest(unittest.makeSuite(MessageTestCase)) 241 | suite.addTest(unittest.makeSuite(AttachmentTestCase)) 242 | suite.addTest(unittest.makeSuite(SenderTestCase)) 243 | return suite 244 | 245 | 246 | if __name__ == "__main__": 247 | unittest.main(__name__, defaultTest='suite') 248 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py26, py27, pypy, py33, py34 3 | 4 | [testenv] 5 | commands = python test_sender.py 6 | --------------------------------------------------------------------------------