Simple Mail Send with Local SMTP
Program
import smtplib
SERVER="localhost"
FROM="debojyotib@nrifintech.com"
TO=["debojyotib@nrifintech.com","debasishba@nrifintech.com"]
SUBJECT="Hi---This is a python mail..."
TEXT="This is the test mail body"
message= """\
FROM: %s
TO: %s
SUBJECT: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
Read a CSV file and Send Mail with Local SMTP
Program
import smtplib
#--------------------------Read CSV-----------
import csv
SERVER="localhost"
f=open('Book1.csv')
csv_f=csv.reader(f)
for row in csv_f:
# print row[2]
toemail=row[2]
fname=row[1]
lname=row[0]
username=row[3]
password=row[4]
# print "Your email id is :"+email
#---------------------------------------------
FROM="debojyotib@nrifintech.com"
#TO=["debojyotib@nrifintech.com","debasishba@nrifintech.com"]
TO=['"'+toemail+'"']
#print(TO)
#exit
SUBJECT="Python mail .. Reading Informations from CSV file "
TEXT="Hello "+fname+"\nPlease click on the link below with the following credentials.\n\nURL: http://www.mail.google.com\nUsername: "+username+"\nPassword: "+password+"\n\nRegards,\nTeam\n\ncontent is provided as attachment."
# message= """\
#FROM: %s
#TO: %s
#SUBJECT: %s
#
#%s
#""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
message="FROM: "+FROM+"\nTO: "+", ".join(TO)+"\nSUBJECT: "+SUBJECT+"\n\n"+TEXT
print(message)
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()