I have python 2.7 installed and i run my python programs via the command line like :

python /myfilepath/myfile.py

The code

See the whole code on github here

python

One thing to configure

For gmail you have to allow unsecure apps to access your gmail

The skeleton

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = “YOUR ADDRESS”
toaddr = “ADDRESS YOU WANT TO SEND TO”
msg = MIMEMultipart()
msg[‘From’] = fromaddr
msg[‘To’] = toaddr
msg[‘Subject’] = “SUBJECT OF THE MAIL”
body = “YOUR MESSAGE HERE”
msg.attach(MIMEText(body, ‘plain’))
server = smtplib.SMTP(‘smtp.gmail.com’, 587)
server.starttls()
server.login(fromaddr, “YOUR PASSWORD”)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Nothing to explain, just replace

  • YOUR ADDRESS by your mail
  • ADDRESS YOU WANT TO SEND TO by your correspondent e-mail
  • YOUR MESSAGE HERE by the message you want to send
  • YOUR PASSWORD by your password

My modifications See the whole code on github here

The variable = raw_input(“question etc”) for below python 3.0 it takes user input after the string mentionned in the bracket else in python 3.0 it’s just input instead of raw_input

The print(“”) prints what’s in the bracket

See the whole code on github here

Advertisements