简体   繁体   中英

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 (eg, 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!

yagmail creator here:

Try this:

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

您可以将图像放在云CDN上,例如Google驱动器具有这种功能,然后以HTML格式发送电子邮件,包括图片。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM