问题
I have develop a function in PYTHON that sends emails with one .doc attachment and one image attachment (.jpg)
The message of the email is HTML.
I want to know how to display the Attached Image on the HTML message....is there any instruction that can help me with this???
Thanks a lot.... Here is the function 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
回答1:
In your html, use img tags with a src of:
cid:<filename used in your Content-Disposition header>
So, for instance:
<p>
<img src="cid:image1.jpeg"/>
</p>
来源:https://stackoverflow.com/questions/8304618/display-an-attached-image-on-the-html-message