I have a function in PYTHON that sends emails with one .doc attachment and one image attachment (.jpg)
The email is HTML.
I want to know how to display an attached image in an HTML message ... is there any instruction that can help me with this?
Thank you very much .... That's what I developed
def enviarCorreo(fromaddr, toaddr, text, file, imagen_1, imagen_2): msg = MIMEMultipart('mixed') msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = 'asunto' msg.attach(MIMEText(text,'HTML')) #IMAGE ATTACHMENT ******************************************* adjuntoImagen_1 = MIMEBase('application', "octet-stream") adjuntoImagen_1.set_payload(open(imagen_1, "rb").read()) encode_base64(adjuntoImagen_1) anexoImagen_1 = os.path.basename(imagen_1) adjuntoImagen_1.add_header('Content-Disposition', 'attachment; filename= "%s"' % anexoImagen_1) msg.attach(adjuntoImagen_1) #FILE ATACHMENT ********************************************** adjunto = MIMEBase('application', "octet-stream") adjunto.set_payload(open(file, "rb").read()) encode_base64(adjunto) anexo = os.path.basename(file) adjunto.add_header('Content-Disposition', 'attachment; filename= "%s"' % anexo) msg.attach(adjunto) #SEND ******************************************************** server = smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromaddr, toaddr, msg.as_string()) server.quit() return
source share