def _send(self, message): """A helper method that does the actual sending.""" if not message.recipients(): return False try: recipients = ','.join(message.to) recipients_bcc = ','.join(message.bcc) html_body = None if isinstance(message, EmailMultiAlternatives): for alt in message.alternatives: if alt[1] == "text/html": html_body=alt[0] break if getattr(message, 'content_subtype', None) == 'html': html_body=message.body reply_to = None custom_headers = {} if message.extra_headers and isinstance(message.extra_headers, dict): if message.extra_headers.has_key('Reply-To'): reply_to = message.extra_headers.pop('Reply-To') if len(message.extra_headers): custom_headers = message.extra_headers attachments = [] if message.attachments and isinstance(message.attachments, list): if len(message.attachments): attachments = message.attachments postmark_message = PMMail(api_key=self.api_key, subject=message.subject, sender=message.from_email, to=recipients, bcc=recipients_bcc, text_body=message.body, html_body=html_body, reply_to=reply_to, custom_headers=custom_headers, attachments=attachments) postmark_message.tag = getattr(message, 'tag', None) postmark_message.send(test=self.test_mode) except: if self.fail_silently: return False raise return True
def _send(self, message): """A helper method that does the actual sending.""" if not message.recipients(): return False try: recipients = ','.join(message.to) html_body = None if isinstance(message, EmailMultiAlternatives): for alt in message.alternatives: if alt[1] == "text/html": html_body = alt[0] break reply_to = None custom_headers = {} if message.extra_headers and isinstance(message.extra_headers, dict): if message.extra_headers.has_key('Reply-To'): reply_to = message.extra_headers.pop('Reply-To') if len(message.extra_headers): custom_headers = message.extra_headers attachments = [] if message.attachments and isinstance(message.attachments, list): if len(message.attachments): attachments = message.attachments postmark_message = PMMail(api_key=self.api_key, subject=message.subject, sender=message.from_email, to=recipients, text_body=message.body, html_body=html_body, reply_to=reply_to, custom_headers=custom_headers, attachments=attachments) postmark_message.tag = getattr(message, 'tag', None) postmark_message.send(test=self.test_mode) except: if self.fail_silently: return False raise return True
def _build_message(self, message): """A helper method to convert a PMEmailMessage to a PMMail""" if not message.recipients(): return False recipients = ','.join(message.to) recipients_bcc = ','.join(message.bcc) recipients_cc = ','.join(message.cc) html_body = None if isinstance(message, EmailMultiAlternatives): for alt in message.alternatives: if alt[1] == "text/html": html_body=alt[0] break reply_to = None custom_headers = {} if message.extra_headers and isinstance(message.extra_headers, dict): if message.extra_headers.has_key('Reply-To'): reply_to = message.extra_headers.pop('Reply-To') if len(message.extra_headers): custom_headers = message.extra_headers attachments = [] if message.attachments and isinstance(message.attachments, list): if len(message.attachments): attachments = [(f, base64.encodestring(content), m) for (f, content, m) in message.attachments] postmark_message = PMMail(api_key=self.api_key, subject=message.subject, sender=message.from_email, to=recipients, cc=recipients_cc, bcc=recipients_bcc, text_body=message.body, html_body=html_body, reply_to=reply_to, custom_headers=custom_headers, attachments=attachments) postmark_message.tag = getattr(message, 'tag', None) return postmark_message
def _build_message(self, message): """A helper method to convert a PMEmailMessage to a PMMail""" if not message.recipients(): return False recipients = ','.join(message.to) recipients_bcc = ','.join(message.bcc) html_body = None if isinstance(message, EmailMultiAlternatives): for alt in message.alternatives: if alt[1] == "text/html": html_body=alt[0] break reply_to = None custom_headers = {} if message.extra_headers and isinstance(message.extra_headers, dict): if message.extra_headers.has_key('Reply-To'): reply_to = message.extra_headers.pop('Reply-To') if len(message.extra_headers): custom_headers = message.extra_headers attachments = [] if message.attachments and isinstance(message.attachments, list): if len(message.attachments): attachments = message.attachments postmark_message = PMMail(api_key=self.api_key, subject=message.subject, sender=message.from_email, to=recipients, bcc=recipients_bcc, text_body=message.body, html_body=html_body, reply_to=reply_to, custom_headers=custom_headers, attachments=attachments) postmark_message.tag = getattr(message, 'tag', None) return postmark_message