# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['mailers']

package_data = \
{'': ['*']}

install_requires = \
['aiosmtplib>=1.1,<2.0']

extras_require = \
{'aiofiles': ['aiofiles>=0.4.0,<0.5.0'], 'full': ['aiofiles>=0.4.0,<0.5.0']}

setup_kwargs = {
    'name': 'mailers',
    'version': '0.0.2',
    'description': 'Email delivery for asyncio.',
    'long_description': '<p align="center">\n<a href="https://travis-ci.org/alex-oleshkevich/mailers">\n    <img src="https://api.travis-ci.com/alex-oleshkevich/mailers.svg?branch=master" alt="Build Status">\n</a>\n<a href="https://codecov.io/gh/alex-oleshkevich/mailers">\n    <img src="https://codecov.io/gh/alex-oleshkevich/mailers/branch/master/graph/badge.svg" alt="Coverage">\n</a>\n<a href="https://pypi.org/project/mailers/">\n    <img src="https://badge.fury.io/py/mailers.svg" alt="Package version">\n</a>\n</p>\n\n---\n\n# Mailers for asyncio\n\n## Installation\n\n```bash\npip install mailers\n```\n\nIf you plan to use `FileTransport` you would also need to install \n[`aiofiles`](https://github.com/Tinche/aiofiles) extra:\n\n```bash\npip install mailers[aiofiles]\n```\n\nOr install all optional dependencies at once:\n\n```bash\npip install mailers[full]\n```\n\n\n## Usage\n\nThe package uses two main concepts: mailers and transports. \nThe mailer is a class which abstracts you from the underlying transport\nand the transport does the actual message delivery.\n\n```python\nfrom mailers import EmailMessage, configure, send_mail\n\nconfigure(mailers={\n    \'default\': \'smtp://user:password@localhost:25?timeout=2\'\n})\n\nmessage = EmailMessage(\n    to=\'user@localhost\', from_address=\'from@localhost\',\n    subject=\'Hello\', text_body=\'World!\'\n)\nawait send_mail(\'user@localhost\', message)\n```\n\nOr if you prefer more control on what is going one, take this more verbose path:\n\n```python\nfrom mailers import Mailer, SMTPTransport, EmailMessage\n\nmailer = Mailer(SMTPTransport(\'localhost\', 25))\n\nmessage = EmailMessage(\n    to=\'user@localhost\', from_address=\'from@localhost\',\n    subject=\'Hello\', text_body=\'World!\'\n)\nawait mailer.send(message)\n``` \n\n### Shortcuts\n\nThe packages exports some utility methods to simplify the work: `configure` and `send_mail`.\n\n`configure` methods allows to configure multiple mailers and bind URL specs at once.\n\n```python\nfrom mailers import configure\n\nconfigure(\n    mailers={\n        \'default\': \'smtp://localhost\',\n        \'admin\': \'smtp://localhost\'   \n    },\n    transports={\n        \'myproto\': \'myproto.ImplementationClass\'            \n    }\n)\n``` \n\nIn case you have multiple mailers, the `send_mail` shortcut accepts `mailer` argument to specify the mailer to use:\n```python\nsend_mail(to, message, mailer=\'admin\')\n```\n\nWhen you dont\'t set `mailer` argument, the function will use mailer with name `default`.  \n\n\n## Compose messages\n\nThe arguments and methods of `EmailMessage ` class are self-explanatory so here is some basic example:\n\n```python\nfrom mailers import EmailMessage, Attachment\n\nmessage = EmailMessage(\n    to=\'user@localhost\', \n    from_address=\'from@example.tld\', \n    cc=\'cc@example.com\', \n    bcc=[\'bcc@example.com\'], \n    text_body=\'Hello world!\',\n    html_body=\'<b>Hello world!</b>\',\n    attachments=[\n        Attachment(\'CONTENTS\', \'file.txt\', \'text/plain\'),    \n    ]   \n)\n\n# attachments can be added on demand:\n\nwith open(\'file.txt\', \'r\') as f:\n    message.attach(f.read(), f.name, \'text/plain\')\n\n    # alternatively\n    message.add_attachment(\n        Attachment(f.read(), f.name, \'text/plain\')\n    )\n```\n\n`cc`, `bcc`, `to`, `reply_to` can be either strings or lists of strings.\n\n### A note about attachments\n\nAccessing files is a blocking operation. You may want to use `aiofiles` or alternate library\nwhich reads files in non-blocking mode.\n\nThis package does not implement direct access to files at moment. \nThis is something to do at later stage. \n\n## Transports\n\n### Preinstalled transports\n\nAll transport classes can be found in `mailers.transports` module.\n\n| Class             | Example URL                                       | Description                                                       |\n|-------------------|---------------------------------------------------|-------------------------------------------------------------------|\n| SMTPTransport     | smtp://user:pass@hostname:port?timeout=&use_tls=1 | Sends mails using SMTP protocol.                                  |\n| InMemoryTransport | not available                                     | Stores sent messages in the local variable. See an example below. |\n| FileTransport     | file:///path/to/directory                         | Writes sent messages into directory.                              |\n| NullTransport     | null://                                           | Does not perform any sending.                                     |\n| StreamTransport   | not available                                     | Writes message to an open stream. See an example below.           |\n| ConsoleTransport  | console://                                        | Prints messages into stdout.                                      |\n| GMailTransport    | gmail://username:password                         | Sends via GMail.                                                  |\n| MailgunTransport  | mailgun://username:password                       | Sends via Mailgun.                                                |\n\n\n### Special notes\n\n#### InMemoryTransport\n\n`InMemoryTransport` takes a list and writes outgoing mail into it. \nRead this list to inspect the outbox.\n\n```python\nfrom mailers import InMemoryTransport, EmailMessage\n\nmessage = EmailMessage()\nmailbox = []\ntransport = InMemoryTransport(mailbox)\nawait transport.send(message)\n\nassert message in mailbox\n```\n\n#### StreamTransport\n\nWrites messages into the open stream.\n\n```python\nfrom mailers import StreamTransport, EmailMessage\nfrom io import TextIO\n\nmessage = EmailMessage()\n\ntransport = StreamTransport(output=TextIO())\nawait transport.send(message)\n```\n\n`output` is any IO compatible object.\n\n\n### Custom transports.\n\nEach transport must implement `async def send(self, message: EmailMessage) -> None` method. \nPreferably, inherit from `BaseTransport` class:\n\n```python\nfrom mailers import BaseTransport, Mailer, EmailMessage\n\nclass PrintTransport(BaseTransport):\n    async def send(self, message: EmailMessage) -> None\n        print(str(message))\n\nmailer = Mailer(PrintTransport())\n```\n\nIn order to make your transport to accept `EmailURL` instances, your transport class has to implement `from_url` \nclass method:\n\n```python\nfrom mailers import BaseTransport, EmailMessage, EmailURL\n\nclass PrintTransport(BaseTransport):\n    @classmethod\n    def from_url(cls, url: EmailURL) -> "PrintTransport":\n        return cls()\n```\n\n### Add custom transport protocols.\n\nOnce you build a custom transport you can add it\'s URL to enable URL-based configurations.\n```python\nfrom mailers import Transports, Mailer\n\nTransports.bind_url(\'myprotocol\', \'my.transport.Name\')\n\nmailer = Mailer(\'myprotocol://\')\n``` \n\nNote that the transport must to implement `from_url` method to accept URL parameters.\nOtherwise it will be constructed without any arguments passed to the `__init__` method.\n',
    'author': 'alex.oleshkevich',
    'author_email': 'alex.oleshkevich@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/alex-oleshkevich/mailers',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'extras_require': extras_require,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
