Send e-mail to Gmail with inline image using Python

后端 未结 2 1457
故里飘歌
故里飘歌 2020-12-01 07:11

My objective is to use Python to send an e-mail to a Gmail user that has an inline image. It is not possible to host this image online and then link to it through a hr

2条回答
  •  再見小時候
    2020-12-01 07:46

    I think you need to add the following lines:

    from email.mime.image import MIMEImage
    
    body = MIMEText('

    Test Image

    ', _subtype='html') msg.attach(body) img = MIMEImage(image.read(), 'jpeg') img.add_header('Content-Id', '') msg.attach(img)

    testimage should be replaced with a unique identifier

提交回复
热议问题