0

I am trying to add signature in an email using python, but I am getting error everytime I try to run the code. The code is -

def addsign(sign_path, subject,msg,mailto):
    mail = MIMEMultipart("mixed")
    mail['Subject'] = subject
    mail['To'] = mailto
    mail['From'] = "ISFledAutomations"
    with open(sign_path, 'rb') as imgdata:
        img = MIMEImage(imgdata.read())
        img['Content-Disposition'] = 'inline; filename=sign_path'
        mail.attach(img)
        #img = make_msgid(domain=imgdata)
    message = """                <p>
                                <br><b> Thanks & Regards:- <b><br>
                                   <br><b> DNB Performance Team<br>
                                </p>"""
    mail.preamble = MIMEText(message,'html') 
    

    #print(mail)
    
    s = smtplib.SMTP("xyz@example.com",25)
    s.set_debuglevel(2)
    s.sendmail(r"xyz@example.com", mailto, mail.as_string())
    s.close()

I have tried changing the statement mail to mail.as_string() and vice-versa but I am getting the error TypeError: expected string or bytes-like object at the statement s.sendmail(r"xyz@email.com", mailto, mail.as_string()) , even removed the raw string tag, any suggestions? It is connecting to smtp server.

I am getting the following error - [Error message received] [1]: https://i.stack.imgur.com/N8cB9.png

0 Answers0