Created
January 30, 2018 19:48
-
-
Save androiddrew/c52313c8fc4b2d57172610bf86f76991 to your computer and use it in GitHub Desktop.
An example using apistar-mail and apistar_dramatiq for async mail sending
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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