Created
August 3, 2020 10:18
-
-
Save ragingbal/2f912a922ad0dab434381ddb02db0514 to your computer and use it in GitHub Desktop.
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 smtplib | |
from email.message import EmailMessage | |
from email.headerregistry import Address | |
from email.utils import make_msgid | |
import jinja2 | |
msg = EmailMessage() | |
msg.set_content('test abc') | |
# me == the sender's email address | |
# you == the recipient's email address | |
msg['Subject'] = 'test 123' | |
msg['From'] = '[email protected]' | |
msg['To'] = '[email protected]' | |
# Send the message via our own SMTP server. | |
s = smtplib.SMTP('mailhog:1025') | |
templateLoader = jinja2.FileSystemLoader(searchpath="./") | |
templateEnv = jinja2.Environment(loader=templateLoader) | |
TEMPLATE_FILE = "test_message.jinja" | |
template = templateEnv.get_template(TEMPLATE_FILE) | |
outputText = template.render() # this is where to put args to the template renderer | |
asparagus_cid = make_msgid() | |
msg.add_alternative(outputText.format(asparagus_cid=asparagus_cid[1:-1]), subtype='html') | |
s.send_message(msg) | |
s.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment