Answer the question
In order to leave comments, you need to log in
How to remove an image from attached files?
Good day.
I create a letter on my project and send it using Python. In the body of the letter there is a company logo, so that Google would display pictures, then I add them as follows:
def send_email(self, supply_order, new_confirmation, extra_text):
...
email = EmailMultiAlternatives(
subject,
email_body,
from_email=company.email,
to=emails_to,
cc=[company.email_copy]
)
self.add_files(email, supply_order, products_table, logo_path)
email.send(fail_silently=False)
def add_files(self, email, supply_order, products_table, logo):
...
email.attach('order.csv', csvfile.getvalue(), 'text/csv')
email.attach('order.pdf', pdf.dest.getvalue(), 'application/pdf')
if logo:
fp = open(urllib.unquote(logo), 'rb')
img = MIMEImage(fp.read())
fp.close()
img.add_header('Content-ID', '<logo>')
email.attach(img)
--===============2904978512032783707==
Content-Type: image/jpeg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: <logo>
--===============2904978512032783707==--
--===============2904978512032783707==
Content-Type: image/jpeg
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: <logo>
TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24J1dCBieSB0
...
LCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGhc3VyZS4=
--===============2904978512032783707==--
Answer the question
In order to leave comments, you need to log in
For inline images, it is necessary that:
1. the image headers contain Content-Disposition: inline
2. the image is located inside the multipart/related part, which includes this image and the HTML part of the letter
3. the HTML part contains a link to the image
and MIME-Version: 1.0 is not should be in the header of the part, only in the main header of the letter. <img src=cid:....>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question