Skip to content

Instantly share code, notes, and snippets.

@sebinthomas
Created July 17, 2011 07:43
Show Gist options
  • Save sebinthomas/1087323 to your computer and use it in GitHub Desktop.
Save sebinthomas/1087323 to your computer and use it in GitHub Desktop.
Python script to send all the python files in the current directory as mail to oneself
#!usr/bin/env python
# Python script to send the .py files in a directory as a mail to ourselves
# By Sebin thomas. sebinthomas.tumblr.com
# You use this script under your own risk
# Author is not responsible for any harm occured to you with the usage of this script
# Under the GNU/GPL licence
import glob
import smtplib
from getpass import getpass
def mail(mailid,pword,body): # To send the mail
mailsession=smtplib.SMTP("smtp.google.com",587) #google mail's SMTP server and preferred port
mailsession.ehlo()
mailsession.starttls()
mailsession.ehlo()
mailsession.login(mailid,pword)
headers="\r\n".join(["From : "+mailid,"Subject : Programs from lab "," To: "+mailid,"mime-version: 1.0","content-type: text/html"]) # necessary headers for a mail
mailsession.sendmail(mailid,mailid,headers+" \r\n\r\n ----"+body+"----") # we are sending a mail to ourselves
mailsession.close()
def main():
mailid=raw_input("enter the full mail id eg : me@me.com : ")
password=getpass("password")
updatelist=open("list.txt","a+") # a list of files we have already sent
print("opened list.txt")
update=updatelist.read()
print update
for filename in glob.glob("*.py"): #traversing through the files in the directory
print filename
if filename not in update : #if not in list
print("not in update")
updatelist.write(filename)
updatelist.close()
print(" update written")
content=open(filename,"r+") # read the contents of the file
mail(mailid,password,content.read()) # mail it to ourselves
if __name__=="__main__" :
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment