#!/usr/bin/env python
import os, sys, smtplib, string

PRODUCT = "AIS Parser SDK"
VERSION = "v1.7"
SUBJECT = "%s %s Now Available" % (PRODUCT, VERSION)
LOCATION = "http://download.aisparser.com/"

# Process the current customer list file
customers = {}
for line in open('customers.txt'):
	fields = line.strip().split(':')
	if len(fields) > 1:
		un, pw = fields
	else:
		un = fields[0]
		pw = None
	customers[un] = pw


# Read the template file
s = open('release.txt').read()
t = string.Template(s)

smtp = smtplib.SMTP('mail.brianlane.com')
for cust in customers:
	if customers[cust] != None:
		fields = {	'from':'bcl@brianlane.com',
		 			'to':cust,
					'username':cust,
					'password':customers[cust],
					'subject':SUBJECT,
					'product':PRODUCT,
					'version':VERSION,
					'location':LOCATION,
				}
		msg = t.substitute(fields)
		smtp.set_debuglevel(1)
		smtp.sendmail(fields['from'], fields['to'], msg)
	else:
		print "No password for %s" % (cust)

smtp.quit()
