Friday, February 10, 2012

Sending emails using a python script

 I have scene many programmers prefer to use python scripts to send those emails.

So here i am going to show a sample working script.

Pre requirements  : python2.6

  
import smtplib



fromaddr = 'sender@gmail.com'

toaddrs  = 'recipient@gmail.com'

msg = ' i am sending this trough my sample programe. this is really cool.. :-) send me a reply when u recieve this mail.'



# Credentials (if needed)  

username = 'username'

password = 'password'



# The actual mail send

server = smtplib.SMTP('smtp.gmail.com:587')

server.starttls()

server.login(username,password)

server.sendmail(fromaddr, toaddrs, msg)

server.quit()
Save this file as example.py
How to run the script :      
    Go to the location of example.py and run following command.    
          python example.py
Then check you mail. :-)

No comments:

Post a Comment