Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send an email
#1
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 ?

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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Send Email with attachment metro17 4 3,250 Apr-14-2020, 04:59 PM
Last Post: CodeItBro
  Help send email by Python using smtplib hangme 6 6,184 Jan-25-2020, 03:31 AM
Last Post: shapeg
  Start tls - Unable to send email darunkumar 7 11,567 May-30-2018, 10:43 AM
Last Post: darunkumar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020