Sending pictures with yagmail doesn't work

344 Views Asked by At

I'm trying to send png with yagmail module but i get this error :

enter image description here

Here is the code :

import yagmail
import os

currentDirectory = os.getcwd()
path_fichier_screenshot2 = currentDirectory + "\\screenshot2.png"
print(path_fichier_screenshot2)

try:
    yag = yagmail.SMTP(user="myemail", password='pwd')
    contents = [yagmail.inline(path_fichier_screenshot2)]
    yag.send("target_email", "test", contents)
    print("Email sent successfully")
except:
    print("Error, email was not sent")

When i just send text, it works. Any clue ?

1

There are 1 best solutions below

1
On

If you want to send the image as an attachment, you can do this:

yag = yagmail.SMTP(user="myemail", password='pwd')
contents = "Hello , sending png as an attachment"
attachments = [path_fichier_screenshot2]

yag.send("target_email", "test", contents, attachments=attachments)

Refer to this doc for more information.