Mar-16-2022, 09:40 PM
Hi,
I'm trying to send a simple email with the code below:
[attachment=1661]
Python is not my strong point but I'm sure it has more to do with SMTPLIB rather than python.
Does anyone know what is going on here?
Thanks
I'm trying to send a simple email with the code below:
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage from email.mime.application import MIMEApplication def send_test_mail(body): sender_email = <SenderEmail> receiver_email = <ReceiverEmail> msg = MIMEMultipart() msg['Subject'] = '[Email Test]' msg['From'] = sender_email msg['To'] = receiver_email msgText = MIMEText('<b>%s</b>' % (body), 'html') msg.attach(msgText) try: with smtplib.SMTP_SSL('smtp.gmail.com', 587) as smtpObj: smtpObj.ehlo() smtpObj.login(<LoginUserName>, <LoginPassword>) smtpObj.sendmail(sender_email, receiver_email, msg.as_string()) except Exception as e: print(e) if __name__ == "__main__": send_test_mail("Welcome to Medium!")Whe the email is received, I get the paperclip icon indicating there is an attachment when there clearly isn't one:
[attachment=1661]
Python is not my strong point but I'm sure it has more to do with SMTPLIB rather than python.
Does anyone know what is going on here?
Thanks