{ "info": { "author": "Drew Bednar", "author_email": "drew@androiddrew.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# molten-mail\n\n[![PyPI](https://img.shields.io/pypi/v/molten-mail.svg)](https://pypi.org/project/molten-mail/)\n[![PyPI](https://img.shields.io/pypi/pyversions/molten-mail.svg)](https://pypi.org/project/molten-mail/)\n[![Build Status](https://travis-ci.org/androiddrew/molten-mail.svg?branch=master)](https://travis-ci.org/androiddrew/molten-mail)\n[![codecov](https://codecov.io/gh/androiddrew/molten-mail/branch/master/graph/badge.svg)](https://codecov.io/gh/androiddrew/molten-mail)\n\n\nProvides a simple interface to set up SMTP with your [Molten](https://github.com/Bogdanp/molten) web application and send messages from your handler functions. Please note this work derives largely from the [Flask-Mail](https://github.com/mattupstate/flask-mail) extension by 'Dan Jacob' and contributors, but has been modified extensively to remove Python 2 support and be used as a Molten component.\n\n\n## Installation\n\n`pip install molten-mail`\n\nIf you plan on using HTML templates you will need to ensure that [Jinja2] is installed. \n\n`pip install molten-mail[templates]`\n\n## Usage\n\nBe sure to check the [examples] folder for sample applications and more complex usage.\n\n### Example Setup\n\nTo send mail messages from your view functions you must instantiate a `Mail` instance yourself or use the `MailComponent`. The `MailComponent` will instantiate a global `Mail` instance from settings provided in the `molten.Settings`.\n\nHere we have a minimally viable app capable of sending an email message and returning a 204 response code:\n\n```python\nfrom molten import (\n App,\n Route,\n Settings,\n SettingsComponent,\n QueryParams,\n HTTP_204,\n HTTP_400,\n Response,\n)\nfrom molten_mail import MailComponent, Mail, Message\n\n# Replace with your own SMTP parameters\nsettings = Settings(\n {\n \"MAIL_SERVER\": \"smtp.example.com\",\n \"MAIL_USERNAME\": \"me@example.com\",\n \"MAIL_PASSWORD\": \"dontaddthistoyourversioncontrol\",\n \"MAIL_PORT\": 587,\n \"MAIL_USE_TLS\": True,\n \"MAIL_DEFAULT_SENDER\": \"me@example.com\",\n }\n)\n\n\ndef send_message(params: QueryParams, mail: Mail):\n \"\"\"Emails an email address provided in the query string\"\"\"\n addresses = params.get_all(\"email\")\n if not addresses:\n return Response(\n HTTP_400,\n content=\"Provide emails in the query params to send a welcome message\",\n )\n msg = Message(\n subject=\"Welcome to Molten!\",\n body=\"Welcome to Molten! Glad to have you here.\",\n recipients=addresses,\n )\n mail.send(msg)\n return Response(HTTP_204, content=\"\")\n\n\nroutes = [Route(\"/\", send_message, \"POST\")]\n\ncomponents = [SettingsComponent(settings), MailComponent()]\n\napp = App(routes=routes, components=components)\n```\n\n### Configuration Options\n\nA singleton `Mail` component can be configured for use in dependency injection using options included in your `molten.Settings`. This requires that you include the `MailComponent` within you `molten.App` instance. The key values can either be all upper or lowercase and begin with `MAIL_`. The available options are:\n\n* 'MAIL_SERVER': default 'localhost'\n* 'MAIL_USERNAME': default None\n* 'MAIL_PASSWORD': default None\n* 'MAIL_PORT': default 25\n* 'MAIL_USE_TLS': default False\n* 'MAIL_USE_SSL': default False\n* 'MAIL_DEFAULT_SENDER': default None\n* 'MAIL_DEBUG': default False\n* 'MAIL_MAX_EMAILS': default None\n* 'MAIL_SUPPRESS_SEND': default False\n* 'MAIL_ASCII_ATTACHMENTS': False\n\n\n\n### Sending Messages\n\nTo send a message, instantiate a `Mail` component. Then create an instance of `Message`, and pass it to your `Mail` component using `mail.send(msg)`\n\n```python\nfrom molten_mail import Mail, Message\n\nmail = Mail(server=\"localhost\",\n user=\"me@example.com\",\n password=\"dontaddthistoyourversioncontrol\",\n port=587,\n use_tls=True,\n default_sender=\"me@example.com\")\nmsg = Message(subject=\"Hey there!\", body=\"Welcome to Molten Mail\", recipients=[\"you@example.com\"])\nmail.send(msg)\n\n```\n\nYour message recipients can be set in bulk or individually:\n\n```python\nmsg.recipients = ['you@example.com', 'me@example.com']\nmsg.add_recipient('otherperson@example.com')\n```\n\nIf you have included a default sender you do not need to set the message sender explicitly, as it will use this configuration value by default:\n\n```python\nmsg = Message('Hello',\n recipients=['you@example.com'])\n```\n\nThe sender can also be passed as a two element tuple containing a name and email address which will be split like so:\n\n```python\nmsg = Message('Hello',\n sender=('Me', 'me@example.com'))\n\nassert msg.sender == 'Me '\n```\n\nA Message can contain a body and/or HTML:\n\n```python\nmsg.body = 'message body'\nmsg.html = 'Hello Molten-mail!'\n```\n\nA convenience function `send_message` can also be used to create and send a message:\n\n```python\nmail.send_message(subject=\"Your subject\", body=\"Message body\", recipients=[\"you@example.com\"])\n```\n\n### HTML Email Templates\n\nMolten-mail includes a convenience component `MailTemplates` for rendering HTML email bodies using [Jinja2]. You have to install `jinja2` yourself before using this module.\n\nYou must include the `MailTemplatesComponent` in your app, passing the path to a folder containing your templates. \n\n```python\nfrom molten import App, Route, Response, HTTP_204, Settings, SettingsComponent\nfrom molten_mail import Mail, MailComponent\nfrom molten_mail.templates import MailTemplates, MailTemplatesComponent\n\nsettings = Settings({\n ...\n})\n\ndef view_func(mail: Mail, mail_templates: MailTemplates): -> Response:\n mail.send_message(\n subject=\"Hello Molten!\",\n html=mail_templates.render(\"my_email_template.html\", somevalue=\"Key values for the template context\"),\n recipients=[\"you@example.com\"]\n )\n return Response(HTTP_204, content=\"\")\n\napp = App(\n components=[SettingsComponent(settings),\n MailComponent(),\n MailTemplatesComponent('./path_to_templates_dir')],\n routes=[Route('/', view_func, method=\"POST\"]\n)\n\n```\n\n\n## Testing\n\nTo run the test suite with coverage first install the package in editable mode with it's full testing requirements:\n\n`$ pip install -e \".[dev]\"`\n\nTo run the project's tests\n\n`$ pytest --cov`\n\nTo run tests against multiple python interpreters use:\n\n`$ tox`\n\n[Jinja2]: http://jinja.pocoo.org/docs/\n[examples]: https://github.com/androiddrew/molten-mail/tree/master/examples\n\n# HISTORY\n\n### 0.1.0 Initial Release\n\n* Initial release.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/androiddrew/molten-mail", "keywords": "molten-mail molten_mail molten mail email SMTP", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "molten-mail", "package_url": "https://pypi.org/project/molten-mail/", "platform": "", "project_url": "https://pypi.org/project/molten-mail/", "project_urls": { "Homepage": "https://github.com/androiddrew/molten-mail" }, "release_url": "https://pypi.org/project/molten-mail/0.1.0/", "requires_dist": [ "molten (>=0.7.1)", "pytest; extra == 'dev'", "pytest-cov; extra == 'dev'", "tox; extra == 'dev'", "jinja2 (<3.0,>=2.10); extra == 'dev'", "jinja2 (<3.0,>=2.10); extra == 'templates'" ], "requires_python": "", "summary": "A simple email component for the Molten web framework", "version": "0.1.0" }, "last_serial": 4833010, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "984cd46849a56b2272c60e37e64d6d47", "sha256": "393bac634d14c98f2cd7d4018341317095f92bf3eb8bcbae996670781c85562f" }, "downloads": -1, "filename": "molten_mail-0.1.0-py36-none-any.whl", "has_sig": false, "md5_digest": "984cd46849a56b2272c60e37e64d6d47", "packagetype": "bdist_wheel", "python_version": "py36", "requires_python": null, "size": 10582, "upload_time": "2019-02-18T02:12:04", "url": "https://files.pythonhosted.org/packages/43/e2/49ab3fb3e2a741e3522029435cf188c2095ffeec5735ccb58dbb90f40069/molten_mail-0.1.0-py36-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6d888f41d5445be413463e3144dd504c", "sha256": "dd6a60a0fca288c4dcd90d24a98bb8014368ed2a5e8e148a0df36c792653719d" }, "downloads": -1, "filename": "molten_mail-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6d888f41d5445be413463e3144dd504c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15975, "upload_time": "2019-02-18T02:12:06", "url": "https://files.pythonhosted.org/packages/f1/d4/305c4583eda6799c95835c4d1caf54c0adbb3d26af4894513e1244900af0/molten_mail-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "984cd46849a56b2272c60e37e64d6d47", "sha256": "393bac634d14c98f2cd7d4018341317095f92bf3eb8bcbae996670781c85562f" }, "downloads": -1, "filename": "molten_mail-0.1.0-py36-none-any.whl", "has_sig": false, "md5_digest": "984cd46849a56b2272c60e37e64d6d47", "packagetype": "bdist_wheel", "python_version": "py36", "requires_python": null, "size": 10582, "upload_time": "2019-02-18T02:12:04", "url": "https://files.pythonhosted.org/packages/43/e2/49ab3fb3e2a741e3522029435cf188c2095ffeec5735ccb58dbb90f40069/molten_mail-0.1.0-py36-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6d888f41d5445be413463e3144dd504c", "sha256": "dd6a60a0fca288c4dcd90d24a98bb8014368ed2a5e8e148a0df36c792653719d" }, "downloads": -1, "filename": "molten_mail-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6d888f41d5445be413463e3144dd504c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15975, "upload_time": "2019-02-18T02:12:06", "url": "https://files.pythonhosted.org/packages/f1/d4/305c4583eda6799c95835c4d1caf54c0adbb3d26af4894513e1244900af0/molten_mail-0.1.0.tar.gz" } ] }