0

I'm sending images as attachments using smtplib, and attaching them as email.mime.base.MIMEBase objects. These images show up inline with the email body. I want these images to be clickable. Is it possible to add hrefs to each of these images?

Here's the code for attaching the image:

msg = MIMEMultipart()
msg['From'] = email_username
msg['To'] = ", ".join(destination_list)
msg['Subject'] = "Subject goes here"

message_body = "<b>Message body</b>"

msg.attach(MIMEText(message_body, 'html'))

part = MIMEBase('application', 'octet-stream')
part.set_payload(open('attachment.png','rb').read())
encoders.encode_base64(part)
part.add_header('Content-Disposition')
msg.attach(part)
Prateek Dewan
  • 1,587
  • 3
  • 16
  • 29
  • If I'm interpreting you correctly; you'd give them `cid`s when creating them, and refer to these identifiers in your html – Sam Mason Sep 25 '18 at 16:53
  • I don't follow. This is what I'm doing: `part = MIMEBase('application', 'octet-stream')` `part.set_payload((attachment).read())` `encoders.encode_base64(part)` `part.add_header('Content-Disposition')` – Prateek Dewan Sep 25 '18 at 16:58
  • I'd suggest updating your question with more details… that said, have a look in the docs: https://docs.python.org/3/library/email.examples.html – Sam Mason Sep 25 '18 at 17:01

0 Answers0