Search code examples
pythonimageemailyagmail

Python/Yagmail - How to embed local images into e-mail?


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!


Solution

  • yagmail creator here:

    Try this:

    contents = [yagmail.inline("/path/to/local/image")]