Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Python sending a html email with a gif, prefering plain text alternative over html.

$
0
0
This script seems to work, but it always sends the plain text email with the gif as an attachment, rather than the html email with the gif inside it, does anyone know why? import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage   me = "ajames@brecon-hs.powys.sch.uk" you = "swilliams@brecon-hs.powys.sch.uk"   msg = MIMEMultipart('related') msg['Subject'] = 'Test Message' msg['From'] = me msg['To'] = you msg.preamble = 'This is a super cool multipart message using html and python c:'   msgAlt = MIMEMultipart('alternative') msg.attach(msgAlt)   msgTxt = MIMEText('You see this if it fails') msgAlt.attach(msgTxt)   thehtmlcode = """\ <html>  <head>Test Header</head>  <body>    <p>This isn't plain text!<br>       If you're seeing this everything should be working as planned :D<br>       Here's the gif <a href="http://tinypic.com?ref=2wpnfnt" target="_blank">http://i43.tinypic.com/2wpnfnt.gif</a>     </p>   </body> </html> """ msgTxt = MIMEText(thehtmlcode, msgAlt.attach(msgTxt))   fp = open('coffee.gif', 'rb') msgImg = MIMEImage(fp.read()) fp.close()   msgImg.add_header('EMEGRENCY thing', '<Itsapicture>') msg.attach(msgImg)   s = smtplib.SMTP('BHS-MAIL') s.send_message(msg)

Viewing all articles
Browse latest Browse all 13965

Latest Images

Trending Articles



Latest Images