Send SVG image content to email as HTML using boto3

I want to send SVG content (without saved file) as HTML to Outlook email address. This SVG content works fine in browser showing a circle image, however sending it via boto3.client to Outlook email results in empty mail. Why? Any suggestions appreciated.

import io
import json
import boto3
from botocore.exceptions import ClientError

SENDER = "Name1 LastName1 <>"
RECIPIENT = "Name2 LastName2 <>"
AWS_REGION = "us-east-1"
SUBJECT = "something"

svg = """
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />

BODY_HTML = f"""<html>


client = boto3.client('ses',region_name=AWS_REGION)

    response = client.send_email(
            'ToAddresses': [
            'Body': {
                'Html': {
                    'Charset': CHARSET,
                    'Data': BODY_HTML
            'Subject': {
                'Charset': CHARSET,
                'Data': SUBJECT
except ClientError as e:
    print("Email sent! Message ID:"),

1 answer

  • answered 2022-05-07 19:32 Eugene Astafiev

    SVG graphics are widely supported in web browsers but not all email programs know what to do with these new images. In case of Outlook you need to export the file to any image file format like PNG or JPEG and then attach it to the mail item. Then in the message body you can refer to use using a special syntax with a cid: prefix. Also you need to set the PR_ATTACH_CONTENT_ID MAPI property (DASL name "") using the Attachment.PropertyAccessor.SetProperty method and refer that attachment through the src attribute that matches the value of PR_ATTACH_CONTENT_ID set on the attachment. PR_ATTACH_CONTENT_ID corresponds to the Content-ID MIME header when the message is sent.

    attachment = MailItem.Attachments.Add("c:\temp\MyPicture.jpg")
    attachment.PropertyAccessor.SetProperty("", "YourImageId")
    MailItem.HTMLBody = "<html><body>Test image <img src=""cid:YourImageId""></body></html>"

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum