https://github.com/kurlov/aiohttp-sendgrid
SendGrid mail API wrapper
https://github.com/kurlov/aiohttp-sendgrid
aiohttp api-wrapper asyncio low-latency python sendgrid
Last synced: about 1 month ago
JSON representation
SendGrid mail API wrapper
- Host: GitHub
- URL: https://github.com/kurlov/aiohttp-sendgrid
- Owner: kurlov
- License: mit
- Created: 2017-12-31T10:58:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-19T04:35:27.000Z (about 6 years ago)
- Last Synced: 2025-04-19T00:35:51.341Z (about 2 months ago)
- Topics: aiohttp, api-wrapper, asyncio, low-latency, python, sendgrid
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
aiohttp-sendgrid
================
.. image:: https://travis-ci.org/Kurlov/aiohttp-sendgrid.svg?branch=master
:target: https://travis-ci.org/Kurlov/aiohttp-sendgrid
.. image:: https://badge.fury.io/py/aiohttp-sendgrid.svg
:target: https://badge.fury.io/py/aiohttp-sendgridSendGrid mail API wrapper
Installation
------------
``pip install aiohttp_sendgrid``Usage
-----
Create an instance of API client:.. code:: python
import asyncio
from aiohttp_sendgrid import Sendgrid
api_key = ''
mailer = Sendgrid(api_key=api_key)Important to note that if ``api_key`` is not provided then it will try to
read ``SENDGRID_API_KEY`` environment variableSend email to single recipient
-------------------------------
.. code:: pythonto = '[email protected]'
sender = '[email protected]'
subject = 'greetings'
content = 'Hello
'
send_mail = mailer.send(to, sender, subject, content)
loop = asyncio.get_event_loop()
loop.run_until_complete(send_mail)Both ``to`` and ``sender`` might be also a dictionary with ``email`` key,
if you want to specify name for sender or recipient then add ``name`` key to
the dictionary. Thus, ``to = {'email': '[email protected]', 'name': 'Recipient'}``
is also a correct value.Send single email to multiple recipients
----------------------------------------
.. code:: pythonto = ['[email protected]', 'another@example']
sender = '[email protected]'
subject = 'greetings'
content = 'Hello
'
send_mail = mailer.send(to, sender, subject, content)
loop = asyncio.get_event_loop()
loop.run_until_complete(send_mail)``to`` might be tuple or list of strings or dictionaries.
Example of valid input::'[email protected]'
{'email': '[email protected]'}
{'email': '[email protected]', 'name': 'Name'}
['[email protected]']
['[email protected]', '[email protected]']
[{'email': '[email protected]'}]
[{'email': '[email protected]'}, {'email': '[email protected]'}]
[{'email': '[email protected]', 'name': 'Name'}]
[{'email': '[email protected]', 'name': 'Name'},
{'email': '[email protected]', 'name': 'Name2'}]
['[email protected]', {'email': '[email protected]'},
{'email': '[email protected]', 'name': 'Name3'}]