I need to send email with logo file which is svg. I attach it but it does not get displayed correctly.
Here is my code:
msg=MIMEMultipart()
img_msg=MIMEMultipart('related')
full_path_to_logo_file=os.path.join('C:\\Users\\emails\\images', 'email-logo.svg')
with open(full_path_to_logo_file, 'rb') as logo_file:
logo_in_binary=logo_file.read()
logo_image=MIMEImage(logo_in_binary, _subtype="svg")
logo_image.add_header('Content-ID','<logo_image_svg>')
img_msg.attach(logo_image)
full_path_to_background_image_file=os.path.join('C:\\Users\\emails\\images', 'email-background.jpg')
with open(full_path_to_background_image_file, 'rb') as background_image_file:
background_in_binary=background_image_file.read()
background_image=MIMEImage(background_in_binary, _subtype="jpg")
background_image.add_header('Content-ID','<background_image_jpg>')
img_msg.attach(background_image)
msg.attach(img_msg)
Part with jpg image works fine.
Here is how it looks in email.
svg file gets attached to email and when I open it with editor, I see svg-xml paths. So, it looks like it works in terms of data being generated, but somehow it does not get attached to email properly.
Here is html/css code of email:
<!--[if mso]>
<table cellspacing="0" cellpadding="0" border="0" width="350" align="center">
<tr>
<td>
<![endif]-->
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; margin: 0 auto;">
<tr>
<td bgcolor="#000000" style="background-color: #000000; padding: 0 25px;">
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse;">
<tr>
<td style="padding: 10px 0; text-align: center; font-family: 'Roboto', sans-serif; color: #FFFFFF;">
<img src="cid:logo_image_svg" width="90" height="50" alt=" " border="0" style="height: auto; background: #000000; font-family: 'Roboto', sans-serif; font-size: 10px; line-height: 10px; color: #FFFFFF;">
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</div>
P.S. I have sent this to gmail account.
P.P.S. Another interesting thing is that when I remove _subtype="svg", I am getting error saying that it cannot recognize type of the file. Could this be somehow related?