Embed image in email rather than reference remove file.

This commit is contained in:
Dan 2020-09-28 13:27:25 -04:00
parent 2a5979d0e3
commit 8c705d1bf4
3 changed files with 12 additions and 1 deletions

View File

@ -2,9 +2,11 @@ import smtplib
import uuid
from datetime import datetime, time, date
from email.header import Header
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import re
from os.path import join
import dateutil
import phonenumbers
@ -148,6 +150,15 @@ class NotificationService(object):
msgAlternative.attach(part1)
msgAlternative.attach(part2)
# Embed the logo image
# This example assumes the image is in the current directory
fp = open(join(app.root_path, 'static', 'uva_logo.png'), 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
# Define the image's ID as referenced above
msgImage.add_header('Content-ID', '<logo>')
msgRoot.attach(msgImage)
# Leaving this on here, just in case we need it later.
if ical:
ical_atch = MIMEText(ical.decode("utf-8"), 'calendar')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -103,7 +103,7 @@
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
<tr>
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top; background-color:#232d4b; padding: 12px">
<img src="{{base_url + '/images/uva_logo.png'}}" alt="University of Virginia"/>
<img src="cid:logo" alt="University of Virginia"/>
</td>
</tr>