|
10 | 10 | except Exception as e: |
11 | 11 | import email.utils as rfc822 |
12 | 12 |
|
| 13 | + |
13 | 14 | class SendGridBackend(BaseEmailBackend): |
14 | 15 | ''' |
15 | 16 | SendGrid Web API Backend |
16 | 17 | ''' |
17 | 18 | def __init__(self, fail_silently=False, **kwargs): |
18 | | - super(SendGridBackend, self).__init__(fail_silently=fail_silently, **kwargs) |
| 19 | + super(SendGridBackend, self).__init__( |
| 20 | + fail_silently=fail_silently, **kwargs) |
19 | 21 | self.api_user = getattr(settings, "SENDGRID_USER", None) |
20 | | - self.api_key = getattr(settings, "SENDGRID_PASSWORD", None) |
| 22 | + self.api_key = getattr(settings, "SENDGRID_PASSWORD", None) |
21 | 23 |
|
22 | | - if self.api_user == None or self.api_key == None: |
23 | | - raise ImproperlyConfigured('''Either SENDGRID_USER or SENDGRID_PASSWORD |
| 24 | + if self.api_user is None or self.api_key is None: |
| 25 | + raise ImproperlyConfigured(''' |
| 26 | + Either SENDGRID_USER or SENDGRID_PASSWORD |
24 | 27 | was not declared in settings.py''') |
25 | | - self.sg = sendgrid.SendGridClient(self.api_user, self.api_key, raise_errors= not fail_silently) |
| 28 | + self.sg = sendgrid.SendGridClient( |
| 29 | + self.api_user, self.api_key, |
| 30 | + raise_errors=not fail_silently) |
26 | 31 |
|
27 | 32 | def open(self): |
28 | 33 | pass |
@@ -62,14 +67,14 @@ def _build_sg_mail(self, email): |
62 | 67 | for alt in email.alternatives: |
63 | 68 | if alt[1] == "text/html": |
64 | 69 | mail.set_html(alt[0]) |
65 | | - if email.cc and not self.fail_silently: |
66 | | - raise Exception("CC list must be empty for SendGridHttpsBackEnd. CC not supported by the web API") |
67 | 70 |
|
68 | 71 | for attachment in email.attachments: |
69 | 72 | if isinstance(attachment, MIMEBase): |
70 | | - mail.add_attachment_stream(attachment.get_filename(), attachment.get_payload()) |
| 73 | + mail.add_attachment_stream( |
| 74 | + attachment.get_filename(), |
| 75 | + attachment.get_payload()) |
71 | 76 | elif isinstance(attachment, tuple): |
72 | | - mail.add_attachment_stream(attachment[0],attachment[1]) |
| 77 | + mail.add_attachment_stream(attachment[0], attachment[1]) |
73 | 78 |
|
74 | 79 | if email.extra_headers: |
75 | 80 | if "Reply-To" in email.extra_headers: |
|
0 commit comments