Ejemplo n.º 1
0
    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
            no_text = False
            if message.__class__.__name__ == 'EmailMultiAlternatives':
                for alt in message.alternatives:
                    if alt[1] == "text/html":
                        html_body=alt[0]
                        break
            elif message.content_subtype == "html":
                html_body = message.body
                no_text = True
            
            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
            
            postmark_message = PMMail(api_key=self.api_key, 
                                  subject=message.subject,
                                  sender=message.from_email,
                                  to=recipients,
                                  text_body=None if no_text else message.body,
                                  html_body=html_body,
                                  reply_to=reply_to,
                                  custom_headers=custom_headers)

            postmark_message.send()
        except:
            if self.fail_silently:
                # Since we try to email admins if fail_silently=False
                # we need to just throw away the error if fail_silently=True
                # or else we could end up with infinite loops of failed
                # mail-sending if the problem is with the mail configuration
                # or postmark service.
                return False

            import sys, traceback
            traceback = '\n'.join(traceback.format_exception(*(sys.exc_info())))
            from pprint import pformat
            mail_data = pformat(message.__dict__)
            message = u"%s\n\n%s" % (traceback, mail_data)
            from django.core.mail import mail_admins
            mail_admins('Error sending mail', message, fail_silently=True)
            #raise
        return True
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
    def _send(self, message):
        """A helper method that does the actual sending."""
        if not message.recipients():
            return False
        try:
            recipients = ','.join(message.to)
            if message.bcc:
                bcc = ','.join(message.bcc)
            else:
                bcc = ''
            html_body = None
            if message.__class__.__name__ == '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=bcc,
                                  text_body=message.body,
                                  html_body=html_body,
                                  reply_to=reply_to,
                                  custom_headers=custom_headers,
                                  attachments=attachments)

            postmark_message.send()
        except:
            if self.fail_silently:
                return False
            raise
        return True
Ejemplo n.º 4
0
    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 _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
            no_text = False
            if message.__class__.__name__ == 'EmailMultiAlternatives':
                for alt in message.alternatives:
                    if alt[1] == "text/html":
                        html_body=alt[0]
                        break
            elif message.content_subtype == "html":
                html_body = message.body
                no_text = True
            
            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
            
            postmark_message = PMMail(api_key=self.api_key, 
                                  subject=message.subject,
                                  sender=message.from_email,
                                  to=recipients,
                                  text_body=None if no_text else message.body,
                                  html_body=html_body,
                                  reply_to=reply_to,
                                  custom_headers=custom_headers)

            postmark_message.send()
        except:
            if self.fail_silently:
                return False
            raise
        return True
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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