brynq-sdk-mandrill 1.0.0__tar.gz → 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_mandrill
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: Mandrill wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ import mandrill
3
3
  import codecs
4
4
  import base64
5
5
  from brynq_sdk.brynq import BrynQ
6
- from typing import Union, List
6
+ from typing import Union, List, Optional, BinaryIO
7
7
 
8
8
 
9
9
  class MailClient(BrynQ):
@@ -27,14 +27,15 @@ class MailClient(BrynQ):
27
27
  else:
28
28
  raise ValueError('No credentials found for Mandrill. Either pass a BrynQ credential label or set the environment variables MANDRILL_TOKEN, MANDRILL_EMAIL_FROM and MANDRILL_NAME_FROM')
29
29
 
30
- def send_mail(self, email_to: list, subject: str, language='NL', content=None, attachment=None):
30
+ def send_mail(self, email_to: list, subject: str, language='NL', content: Optional[str] = None, attachment: Optional[BinaryIO | List[BinaryIO]] = None, cc: Optional[List | str] = None) -> List[dict]:
31
31
  """
32
32
  Send a mail with the BrynQ layout and using mandrill
33
33
  :param email_to: a list with name and mailadress to who the mail must be send
34
34
  :param subject: The subject of the email
35
35
  :param language: Determines the salutation and greeting text. For example Beste or Dear
36
36
  :param content: The message of the email
37
- :param attachment: The attachment of an email loaded as binary file (NOT the location of the file)
37
+ :param attachment: The attachment/attachments of an email loaded as binary file (NOT the location of the file)
38
+ :param cc: A list with name and mail address to be CC'd
38
39
  :return: If the sending of the mail is successful or not
39
40
  """
40
41
 
@@ -50,12 +51,30 @@ class MailClient(BrynQ):
50
51
  salutation = 'Dear '
51
52
  greeting_text = 'Kind regards'
52
53
 
53
- # Set attachment. Do not in loop because of errors
54
+ # Process attachments
55
+ encoded_attachments = []
54
56
  if attachment is not None:
55
- opened_attachment = attachment.read()
56
- encoded_attachment = base64.b64encode(opened_attachment).decode('utf-8')
57
- else:
58
- encoded_attachment = None
57
+
58
+ # add single attachment to a list
59
+ if not isinstance(attachment, list):
60
+ attachment = [attachment]
61
+
62
+ for file in attachment:
63
+ opened_attachment = file.read()
64
+ encoded_attachments.append({
65
+ 'content': base64.b64encode(opened_attachment).decode('utf-8'),
66
+ 'name': file.name.split('/')[-1]
67
+ })
68
+
69
+ # Prepare CC list
70
+ cc_list = []
71
+ if cc is not None:
72
+ for cc_object in cc:
73
+ cc_list.append({
74
+ 'email': cc_object['mail'],
75
+ 'name': cc_object['name'],
76
+ 'type': 'cc'
77
+ })
59
78
 
60
79
  # Pick the configurations from the config file and create the mail
61
80
  response = []
@@ -77,14 +96,11 @@ class MailClient(BrynQ):
77
96
  'html': new_html,
78
97
  'to': [{'email': email_object['mail'],
79
98
  'name': email_object['name'],
80
- 'type': 'to'}]
99
+ 'type': 'to'}] + cc_list # Add CC recipients
81
100
  }
82
- if encoded_attachment is not None:
83
- mail.update({
84
- 'attachments': [{'content': encoded_attachment,
85
- 'name': attachment.name.split('/')[-1]
86
- }]
87
- })
101
+
102
+ if encoded_attachments:
103
+ mail['attachments'] = encoded_attachments
88
104
 
89
105
  # Send the mail and return the result per mail address
90
106
  result = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-mandrill
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: Mandrill wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='brynq_sdk_mandrill',
6
- version='1.0.0',
6
+ version='1.1.1',
7
7
  description='Mandrill wrapper from BrynQ',
8
8
  long_description='Mandrill wrapper from BrynQ',
9
9
  author='BrynQ',