Created
February 3, 2023 13:59
-
-
Save graphoarty/9306fcbd82e2173d5c6ee9f7602e3058 to your computer and use it in GitHub Desktop.
threads in python
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
import asyncio | |
def SendEmail(email, subject, message): | |
import threading | |
t = threading.Thread(target=SendEmailThread, args=(email, subject, message)) | |
t.start() | |
def SendEmailThread(email, subject, message): | |
loop = asyncio.new_event_loop() | |
loop.run_until_complete(SendEmailAsync(email, subject, message)) | |
@asyncio.coroutine | |
def SendEmailAsync(email, subject, message): | |
# from django.core.mail import send_mail | |
# send_mail(subject, message, "{} <mailgun@{}>".format(subject, mailgun_domain_name), [email], fail_silently=True) | |
try: | |
requests.post( | |
"https://api.mailgun.net/v3/{}/messages".format(mailgun_domain_name), | |
auth=("api", mailgun_api_key), | |
data={"from": "{} <mailgun@{}>".format(subject, mailgun_domain_name), | |
"to": [email], | |
"subject": subject, | |
"text": message}) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment