Skip to content

Instantly share code, notes, and snippets.

@graphoarty
Created February 3, 2023 13:59
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 graphoarty/9306fcbd82e2173d5c6ee9f7602e3058 to your computer and use it in GitHub Desktop.
Save graphoarty/9306fcbd82e2173d5c6ee9f7602e3058 to your computer and use it in GitHub Desktop.
threads in python
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