def Send(self, reminder_config): '''Filter the data and send the reminder. ''' query = reminder_config.get_query() self.logger.info('QUERY=%s' % query) total_records = self.db_cursor.execute(query) self.logger.info('Records in cursor set: %d' % total_records) send_mail = SendMail(self.mandrill_config) total_sent = 0 total_error = 0 fields = self.db_cursor.description for row in self.db_cursor: content = [{"name": x[0], "content": row[x[0]]} for x in fields] email = row['email'] name = row['name'] row_content = {x[0]: row[x[0]] for x in fields} attachments = self.__build_attachments_parameter(reminder_config.attachment_url, row_content) sent, reject_reason = send_mail.send_using_template(email, name, reminder_config.reminder_template_name, content, attachments) if sent == False: self.logger.error('Email {}. Reason: {}'.format(email, reject_reason)) total_error += 1 continue self.__update_record(reminder_config.update, row_content) total_sent += 1 self.logger.info('OK: Email {}'.format(email)) self.logger.info('Sent with success: {} Fail: {}'.format(total_sent, total_error)) return total_sent, total_error, query
def send(self, send_resume_to, template_name): send_mail = SendMail(self.mandrill_config) self.finish_time = datetime.now() content = [ {'name': 'start-time', 'content': self.start_time.strftime("%Y-%m-%d %H:%M:%S")}, {'name': 'records-processed', 'content': self.sent_with_success + self.sent_with_error}, {'name': 'success', 'content': self.sent_with_success}, {'name': 'error', 'content': self.sent_with_error}, {'name': 'finish-time', 'content': self.finish_time.strftime("%Y-%m-%d %H:%M:%S")}, {'name': 'command-line-parameters', 'content': self.command_line_parameters}, {'name': 'query-filter-used', 'content': self.query} ] sent, reject_reason = send_mail.send_using_template( send_resume_to, 'Reminder', template_name, content ) return sent, reject_reason