Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
contents = attachments if contents is None else contents + attachments
has_included_images, content_objects = prepare_contents(contents, encoding)
msg = MIMEMultipart()
if headers is not None:
# Strangely, msg does not have an update method, so then manually.
for k, v in headers.items():
msg[k] = v
if headers is None or "Date" not in headers:
msg["Date"] = formatdate()
msg_alternative = MIMEMultipart("alternative")
msg_related = MIMEMultipart("related")
msg_related.attach("-- HTML goes here --")
msg.attach(msg_alternative)
add_subject(msg, subject)
add_recipients_headers(user, useralias, msg, addresses)
htmlstr = ""
altstr = []
if has_included_images:
msg.preamble = "This message is best displayed using a MIME capable email reader."
if contents is not None:
for content_object, content_string in zip(content_objects, contents):
if content_object["main_type"] == "image":
# all image objects need base64 encoding, so do it now
email.encoders.encode_base64(content_object["mime_object"])
# aliased image {'path' : 'alias'}
if isinstance(content_string, dict) and len(content_string) == 1:
for key in content_string:
hashed_ref = str(abs(hash(key)))
alias = content_string[key]