Skip to content

Instantly share code, notes, and snippets.

@phette23
Created November 22, 2022 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/ebbfb5470ca11ffe1a50e07a58ccdb1a to your computer and use it in GitHub Desktop.
Save phette23/ebbfb5470ca11ffe1a50e07a58ccdb1a to your computer and use it in GitHub Desktop.
demo of sending HTML email in syllabus reminders project
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