Mar-12-2020, 05:30 PM
Hello,
I am learning Python and the first thing I managed to do is sending an email to myself. I used the code below that I found online I pretty much understand everything it does except the line msg.attach(MIMEText(message, 'plain')) that I need help with : what does it mean/do please ?
I am learning Python and the first thing I managed to do is sending an email to myself. I used the code below that I found online I pretty much understand everything it does except the line msg.attach(MIMEText(message, 'plain')) that I need help with : what does it mean/do please ?
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText # message = "Your message" msg = MIMEMultipart() password = "makjdsgfjsbfgjju" msg['From'] = "[email protected]" msg['To'] = "[email protected]" msg['Subject'] = "title" msg.attach(MIMEText(message, 'plain')) server = smtplib.SMTP('smtp.gmail.com: 587') server.starttls() server.login(msg['From'], password) server.sendmail(msg['From'], msg['To'], msg.as_string()) server.quit()