Adding a picture at the bottom of the mail content when sending e-mail with Python SMTP

Viewed 99

Using the email and smtp libraries, I have developed a script that automatically sends mail via outlook's smtp server.

I enter the content of the mail and after the content is written I want to send the picture at the bottom.

But it sends the picture not at the bottom as I want it, but at the top of the mail content.

Example mail ( This is only image ) : https://ibb.co/d5HFwRG

My code:

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage

def send_mail(gender, messages, subject):
    global msg

    try:
        msg = MIMEMultipart()
        s = smtplib.SMTP(host="SMTP.office365.com", port=587)
        s.starttls()
        s.login(mail, password)

        msg['From'] = mail
        msg['To'] = example@outlook.com
        msg['Subject'] = messages

        msg.attach(MIMEText(message, 'plain', 'utf-8'))

        attachment = open("image.jpg", "rb")
        p = MIMEBase('application', 'octet-stream')
        p.set_payload((attachment).read())
        encoders.encode_base64(p)
        p.add_header('Content-Disposition', "attachment; filename= %s" % image)
        msg.attach(p)

        s.send_message(msg)

        del msg

    except Exception as e:
        print(e)

My code is actually much more complex, but I just showed you the function I use to send mail. I had to change the names of some variables while adding them here, so the above code may not work for you, you need to edit it.

How can I get that picture sent in the Mail to the bottom?

0 Answers
Related