Skip to content

Instantly share code, notes, and snippets.

@androiddrew
Created January 30, 2018 19:48
Show Gist options
  • 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': '[email protected]',
'MAIL_PASSWORD': 'dontcommitthistoversioncontrol',
'MAIL_PORT': 587,
'MAIL_USE_TLS': True,
'MAIL_DEFAULT_SENDER': '[email protected]'
}
}
@actor(queue_name="example")
def send_a_message(message: str, mail: Mail):
msg = Message(message,
sender='[email protected]',
recipients=['[email protected]'])
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