UnderCover/undercover/email.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-09-26 08:24:59 -04:00
from mailjet_rest import Client
import os
api_key = os.environ['MAILJET_API_KEY']
api_secret = os.environ['MAILJET_SECRET_KEY']
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
2022-09-26 08:40:10 -04:00
2022-09-26 08:24:59 -04:00
def send_password_reset(to_email: str, reset_link: str):
data = {
'Messages': [
{
"From": {
"Email": "donotreply@undercover.cafe",
"Name": "UnderCover"
},
"To": [
{
"Email": to_email
# "Name": "Sage"
}
],
"Subject": "UnderCover - Password Reset",
"TextPart": "Complete your UnderCover password reset by visiting " + reset_link,
"HTMLPart": "<h3><a href='" + reset_link + "'>Click here to complete your UnderCover password reset</a></h3><br />Or copy and paste this link into your browser: " + reset_link,
"CustomID": "PasswordResetLink"
}
]
}
2022-09-26 08:24:59 -04:00
result = mailjet.send.create(data=data)
return 200 <= result.status_code <= 299
2022-09-26 08:24:59 -04:00
2022-09-26 08:40:10 -04:00
if __name__ == "__main__":
send_password_reset('sage@sagev.space', 'https://sagev.space/')