@@ -43,21 +43,40 @@ def _translate_keys(self, **kwargs):
43
43
model ['content' ]['html' ] = kwargs .get ('html' )
44
44
model ['content' ]['text' ] = kwargs .get ('text' )
45
45
model ['content' ]['template_id' ] = kwargs .get ('template' )
46
- model ['content' ]['headers' ] = kwargs .get ('custom_headers' )
46
+ model ['content' ]['headers' ] = kwargs .get ('custom_headers' , {} )
47
47
48
48
recipient_list = kwargs .get ('recipient_list' )
49
49
if recipient_list :
50
50
model ['recipients' ]['list_id' ] = recipient_list
51
51
else :
52
52
recipients = kwargs .get ('recipients' , [])
53
- model ['recipients' ] = self ._extractRecipients (recipients )
53
+ cc = kwargs .get ('cc' )
54
+ bcc = kwargs .get ('bcc' )
55
+
56
+ if cc :
57
+ model ['content' ]['headers' ]['CC' ] = ',' .join (cc )
58
+ cc_copies = self ._format_copies (recipients , cc )
59
+ recipients = recipients + cc_copies
60
+ if bcc :
61
+ bcc_copies = self ._format_copies (recipients , bcc )
62
+ recipients = recipients + bcc_copies
63
+
64
+ model ['recipients' ] = self ._extract_recipients (recipients )
54
65
55
66
attachments = kwargs .get ('attachments' , [])
56
67
model ['content' ]['attachments' ] = self ._extract_attachments (
57
68
attachments )
58
69
59
70
return model
60
71
72
+ def _format_copies (self , recipients , copies ):
73
+ formatted_copies = []
74
+ if len (recipients ) > 0 :
75
+ formatted_copies = self ._extract_recipients (copies )
76
+ for recipient in formatted_copies :
77
+ recipient ['address' ].update ({'header_to' : recipients [0 ]})
78
+ return formatted_copies
79
+
61
80
def _extract_attachments (self , attachments ):
62
81
formatted_attachments = []
63
82
for attachment in attachments :
@@ -77,7 +96,7 @@ def _get_base64_from_file(self, filename):
77
96
encoded_string = base64 .b64encode (a_file .read ()).decode ("ascii" )
78
97
return encoded_string
79
98
80
- def _extractRecipients (self , recipients ):
99
+ def _extract_recipients (self , recipients ):
81
100
formatted_recipients = []
82
101
for recip in recipients :
83
102
try :
@@ -103,10 +122,12 @@ def send(self, **kwargs):
103
122
"""
104
123
Send a transmission based on the supplied parameters
105
124
106
- :param list|dict recipients: If list it is an array of email addresses,
125
+ :param list|dict recipients: If list it is an list of email addresses,
107
126
if dict ``{'address': {'name': 'Name', 'email': 'me' }}``
108
127
:param str recipient_list: ID of recipient list, if set recipients
109
128
above will be ignored
129
+ :param cc: List of email addresses to send carbon copy to
130
+ :param bcc: List of email addresses to send blind carbon copy to
110
131
:param str template: ID of template. If set HTML or text will not be
111
132
used
112
133
:param bool use_draft_template: Default to False. Set to true if you
0 commit comments