Created
April 28, 2012 08:18
-
-
Save anilshanbhag/2517081 to your computer and use it in GitHub Desktop.
Batch Mailing from the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from smtplib import SMTP | |
import datetime | |
debuglevel = 1 | |
smtp = SMTP() | |
smtp.set_debuglevel(debuglevel) | |
smtp.connect("smtp.cse.iitb.ac.in",25) | |
smtp.starttls() | |
smtp.login('USERNAME HERE', 'PASSWORD HERE') | |
for line in open("batch.txt").readlines(): | |
parts = line.split(',') | |
from_addr = "FROM" #Example : "Anil Shanbhag <anil@cse.iitb.ac.in>" | |
to_addr = "TO" | |
subj = "SUBJECT HERE" | |
date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) | |
message_text = "MESSAGE HERE" | |
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr, subj, date, message_text ) | |
smtp.sendmail(from_addr, to_addr, msg) | |
smtp.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment