Skip to content

Instantly share code, notes, and snippets.

@androiddrew
Created January 30, 2018 19:48
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 androiddrew/c52313c8fc4b2d57172610bf86f76991 to your computer and use it in GitHub Desktop.
Save androiddrew/c52313c8fc4b2d57172610bf86f76991 to your computer and use it in GitHub Desktop.
An example using apistar-mail and apistar_dramatiq for async mail sending
from apistar import Include, Route
from apistar.frameworks.wsgi import WSGIApp as App
from apistar.http import QueryParams
from apistar_mail import mail_component, Mail, Message
from apistar_dramatiq import actor
settings = {
'MAIL': {
'MAIL_SERVER': 'smtp.example.com',
'MAIL_USERNAME': 'me@example.com',
'MAIL_PASSWORD': 'dontcommitthistoversioncontrol',
'MAIL_PORT': 587,
'MAIL_USE_TLS': True,
'MAIL_DEFAULT_SENDER': 'me@example.com'
}
}
@actor(queue_name="example")
def send_a_message(message: str, mail: Mail):
msg = Message(message,
sender='me@example.com',
recipients=['you@example.com'])
mail.send(msg)
def end_point(qparams: QueryParams):
message = qparams.get('message')
send_a_message.send(message)
return
routes = [
Route('/', 'POST', end_point)
]
components = [
mail_component
]
app = App(
settings=settings,
routes=routes,
components=components
)
if __name__ == '__main__':
app.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment