Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Created July 2, 2021 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelcolvin/a5b5cc53255642076067c62904b30670 to your computer and use it in GitHub Desktop.
Save samuelcolvin/a5b5cc53255642076067c62904b30670 to your computer and use it in GitHub Desktop.
aioaws SES example
from pathlib import Path
from httpx import AsyncClient
from aioaws.ses import SesConfig, SesClient, SesRecipient, SesAttachment
async def ses_demo(client: AsyncClient):
ses_client = SesClient(client, SesConfig('<access key>', '<secret key>', '<region>'))
message_id = await ses_client.send_email(
SesRecipient('sende@example.com', 'Sender', 'Name'),
'This is the subject',
[SesRecipient('recipient@eample.com', 'John', 'Doe')],
'this is the plain text body',
html_body='<b>This is the HTML body.<b>',
bcc=[SesRecipient(...)],
attachments=[
SesAttachment(b'this is content', 'attachment-name.txt', 'text/plain'),
SesAttachment(Path('foobar.png')),
],
unsubscribe_link='https:://example.com/unsubscribe',
configuration_set='SES configuration set',
message_tags={'ses': 'tags', 'go': 'here'},
)
print('SES message ID:', message_id)
async def main():
async with AsyncClient() as client:
await ses_demo(client)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment