Created
November 22, 2022 00:29
-
-
Save phette23/ebbfb5470ca11ffe1a50e07a58ccdb1a to your computer and use it in GitHub Desktop.
demo of sending HTML email in syllabus reminders project
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
from email.message import EmailMessage | |
import smtplib | |
from reminders.config import config | |
from_address = 'ephetteplace@cca.edu' | |
to_address = 'ephetteplace@cca.edu' | |
msg = EmailMessage() | |
msg['Subject'] = "Test HTML Email" | |
msg['From'] = from_address | |
msg['To'] = to_address | |
# Create the body of the message | |
html = """\ | |
<html> | |
<head> | |
<script type="application/ld+json"> | |
{ | |
"@context": "https://schema.org", | |
"@type": "EmailMessage", | |
"potentialAction": { | |
"@type": "ViewAction", | |
"target": "https://portal.cca.edu/login", | |
"name": "Submit Syllabus" | |
}, | |
"description": "Submit your syllabus via CCA's Portal." | |
} | |
</script> | |
</head> | |
<body> | |
<p>Test email <b>in HTML</b> with <a href="https://example.com">links</a> <i>and stuff</i>.</p> | |
</body> | |
</html> | |
""" | |
msg.set_content(html, subtype='html') | |
with smtplib.SMTP(config['SMTP_DOMAIN'], port=config['SMTP_PORT']) as server: | |
print(msg.as_string()) | |
server.login(config['SMTP_USER'], config['SMTP_PASSWORD']) | |
server.sendmail(from_address, to_address, msg.as_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment