-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jairo Matos Da Rocha
committed
Sep 30, 2024
1 parent
4256e59
commit 9c0bc84
Showing
8 changed files
with
259 additions
and
191 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
import smtplib, ssl | ||
from email.mime.text import MIMEText | ||
from email.mime.multipart import MIMEMultipart | ||
|
||
|
||
from workers.models.email import SendEmail | ||
from workers.render import template | ||
from workers.utils.emial import html_to_text | ||
|
||
|
||
def send_email(payload: SendEmail): | ||
|
||
sender_email = os.environ.get('EMAIL_SENDER') | ||
password = os.environ.get('EMAIL_PASSWORD') | ||
receiver_email = payload['receiver_email'] | ||
|
||
|
||
message = MIMEMultipart("alternative") | ||
message["Subject"] = "multipart test" | ||
message["From"] = sender_email | ||
message["To"] = receiver_email | ||
|
||
to_render = payload['message'] | ||
html = template.get_template(to_render['templet_name']).render(to_render['content']) | ||
|
||
message.attach(MIMEText(html_to_text(html), "plain")) | ||
message.attach(MIMEText(html, "html")) | ||
|
||
# Create secure connection with server and send email | ||
context = ssl.create_default_context() | ||
with smtplib.SMTP_SSL(os.environ.get('SERVER_EMAIL'), 465, context=context) as server: | ||
server.login(sender_email, password) | ||
server.sendmail( | ||
sender_email, receiver_email, message.as_string() | ||
) |
Oops, something went wrong.