aboutsummaryrefslogtreecommitdiff
path: root/users/mail_send.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-06-13 19:31:04 +0000
committerBobby <[email protected]>2024-06-13 19:31:04 +0000
commitc27b2930170dbc69d5b2c302bff2eba6b97a5525 (patch)
tree2c29f50b15926c41de662791182091fab1a2d2dc /users/mail_send.py
parent77275c2c688aa1f337659d98255582627450d43f (diff)
downloadthatcomputerscientist-c27b2930170dbc69d5b2c302bff2eba6b97a5525.tar.xz
thatcomputerscientist-c27b2930170dbc69d5b2c302bff2eba6b97a5525.zip
Ability to Reset Passwords and Better Email Templates
Diffstat (limited to 'users/mail_send.py')
-rw-r--r--users/mail_send.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/users/mail_send.py b/users/mail_send.py
index be167eb1..df837a32 100644
--- a/users/mail_send.py
+++ b/users/mail_send.py
@@ -13,51 +13,55 @@ def send_email(sender, sender_name, recipient, subject, body_html, body_text):
# this is the approved sender email
SENDER = sender
SENDERNAME = sender_name
-
+
# Replace [email protected] with a "To" address. If your account
# is still in the sandbox, this address must be verified.
RECIPIENT = recipient
-
+
# Replace the USERNAME_SMTP value with your Email Delivery SMTP username.
USERNAME_SMTP = settings.USERNAME_SMTP
-
+
# Put the PASSWORD value from your Email Delivery SMTP password into the following file.
PASSWORD_SMTP = settings.PASSWORD_SMTP
-
+
# If you're using Email Delivery in a different region, replace the HOST value with an appropriate SMTP endpoint.
# Use port 25 or 587 to connect to the SMTP endpoint.
HOST = settings.EMAIL_HOST
PORT = settings.EMAIL_PORT
-
+
# The subject line of the email.
SUBJECT = subject
-
+
# The email body for recipients with non-HTML email clients.
BODY_TEXT = body_text
-
+
# The HTML body of the email.
BODY_HTML = body_html
# create message container
msg = EmailMessage()
- msg['Subject'] = SUBJECT
- msg['From'] = email.utils.formataddr((SENDERNAME, SENDER))
- msg['To'] = RECIPIENT
+ msg["Subject"] = SUBJECT
+ msg["From"] = email.utils.formataddr((SENDERNAME, SENDER))
+ msg["To"] = RECIPIENT
# make the message multi-part alternative, making the content the first part
- msg.add_alternative(BODY_TEXT, subtype='text')
+ msg.add_alternative(BODY_TEXT, subtype="text")
# this adds the additional part to the message
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
- msg.add_alternative(BODY_HTML, subtype='html')
+ msg.add_alternative(BODY_HTML, subtype="html")
# Try to send the message.
- try:
+ try:
server = smtplib.SMTP(HOST, PORT)
server.ehlo()
# most python runtimes default to a set of trusted public CAs that will include the CA used by OCI Email Delivery.
# However, on platforms lacking that default (or with an outdated set of CAs), customers may need to provide a capath that includes our public CA.
- server.starttls(context=ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=None, capath=None))
+ server.starttls(
+ context=ssl.create_default_context(
+ purpose=ssl.Purpose.SERVER_AUTH, cafile=None, capath=None
+ )
+ )
# smtplib docs recommend calling ehlo() before & after starttls()
server.ehlo()
server.login(USERNAME_SMTP, PASSWORD_SMTP)
@@ -68,4 +72,4 @@ def send_email(sender, sender_name, recipient, subject, body_html, body_text):
except Exception as e:
return e
else:
- return True \ No newline at end of file
+ return True