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.
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/PKG-INFO +1 -1
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk/mandrill/mail_client.py +31 -15
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/PKG-INFO +1 -1
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/setup.py +1 -1
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk/mandrill/__init__.py +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk/mandrill/templates/mail_brynq.html +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/not-zip-safe +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/requires.txt +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/top_level.txt +0 -0
- {brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/setup.cfg +0 -0
|
@@ -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
|
-
#
|
|
54
|
+
# Process attachments
|
|
55
|
+
encoded_attachments = []
|
|
54
56
|
if attachment is not None:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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 = {
|
|
File without changes
|
{brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk/mandrill/templates/mail_brynq.html
RENAMED
|
File without changes
|
{brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/requires.txt
RENAMED
|
File without changes
|
{brynq_sdk_mandrill-1.0.0 → brynq_sdk_mandrill-1.1.1}/brynq_sdk_mandrill.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|