Changeset 2:108a82defd3e in mailjam for postman/mta.py
- Timestamp:
- May 15, 2012, 2:29:03 AM (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/mta.py
r1 r2 8 8 class Sendmail(): 9 9 10 def __init__(self, mailing_list ):10 def __init__(self, mailing_list=None): 11 11 if not isinstance(mailing_list, MailingList): 12 12 raise ValueError(mailing_list, ' is not a valid mailing list') 13 13 self.mailing_list = mailing_list 14 14 self.suscriptors = self.mailing_list.members_addresses 15 self.reply_address = self.mailing_list.address 15 self.reply_to = self.mailing_list.address 16 self.raw_email = None 16 17 self.queue = [] 17 18 self.archive = self.mailing_list.config.get('archive', 18 config. storage_path)19 config.archive_path) 19 20 20 def get_raw_email( ):21 def get_raw_email(self): 21 22 try: 22 raw_email = sys.stdin.read()23 self.raw_email = sys.stdin.read() 23 24 except: 24 25 raise IOError('Can not get a valid email from stdin') 25 return raw_email26 return self.raw_email 26 27 27 def save_raw_email(): 28 def save_raw_email(self): 29 if not self.raw_email: 30 # FIXME: perhaps a while loop here, with some maximum recursion 31 # check, would be nice here 32 self.get_raw_email 28 33 filename = os.path.join(self.archive, 29 34 datetime.today().strftime('%Y%d%m%H%M%S%f')) 30 35 tmpfile = file(filename, 'w') 31 tmpfile.write( raw_email)36 tmpfile.write(self.raw_email) 32 37 tmpfile.close() 33 38 self.queue.append(filename) 34 39 35 def send_email(): 36 if not self.queue: 37 raise ValueError('The emails queue is empty') 38 next_email = self.queue.pop() 39 email_file = file(next_email, 'r') 40 email_data = email.message_from_file(email_file) 41 email_file.close() 40 def send_email(self): 41 if self.queue: 42 next_email = self.queue.pop() 43 email_file = file(next_email, 'r') 44 email_data = email.message_from_file(email_file) 45 email_file.close() 42 46 43 email_data['Reply-to'] = self.reply_address47 email_data['Reply-to'] = self.reply_to 44 48 45 smtp_conn = smtplib.SMTP() 46 smtp_conn.connect() 47 smtp_conn.sendmail(email_data['From'], self.suscriptors, 48 email_data.as_string()) 49 smtp_conn.close() 49 smtp_conn = smtplib.SMTP() 50 smtp_conn.connect() 51 smtp_conn.sendmail(email_data['From'], self.suscriptors, 52 email_data.as_string()) 53 smtp_conn.close() 54 55 def run(self): 56 self.get_raw_email() 57 self.save_raw_email() 58 self.send_email()
Note:
See TracChangeset
for help on using the changeset viewer.