2

I'm currently using the yagmail module to send e-mails with Python, and I'm having difficulty embedding locally stored images into an e-mail. Is this possible?

Here's a code example:

contents = ["<img src='/path/to/local/image'>"]

yag = yagmail.SMTP('myemail@gmail.com', 'password')
yag.send('myotheremail@gmail.com', 'E-mail Title', contents)

Using the above code example, if I input an external path (e.g, imgur image or google image), it works perfectly, put I cannot seem to get a local path recognized.

The solution doesn't have to be using yagmail, it just seems to be the easiest e-mail module I've used so far.

Thanks for any help!

Colin M
  • 35
  • 4
  • You need to attach them to your email: https://stackoverflow.com/questions/3362600/how-to-send-email-attachments – uphill Oct 11 '17 at 18:23
  • Can I embed them after they are attached? I forgot to specify, but I need to have them embedded into the e-mail, not just attached. – Colin M Oct 11 '17 at 18:33

2 Answers2

5

yagmail creator here:

Try this:

contents = [yagmail.inline("/path/to/local/image")]
PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
0

You could put the image on a cloud CDN like google drive has this kind of function and send the email as HTML including the picture.

Yuze Ma
  • 357
  • 1
  • 9