-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_sender.py
50 lines (47 loc) · 1.73 KB
/
email_sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from mailjet_rest import Client
import base64
from email_sender_keys import *
def send_email(email_to, email_reply_to, attached_file):
"""
Envío de email con archivo adjunto a través de Mailjet \n
Recuerda configurar archivo email_sender_keys.py
Arguments:
email_to: email de destinatario
email_reply_to: email de respuesta
attached_file: ruta relativa del archivo incluida la extensión. Solo acepta archivos con extensión .jpg
"""
with open(attached_file, 'rb') as file:
file_base64 = base64.b64encode(file.read()).decode('utf-8')
mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_SECRET_KEY), version='v3.1')
data = {
'Messages': [
{
"From": {
"Email": MAILJET_SENDER_EMAIL,
"Name": "Julio pruebas"
},
"To": [
{
"Email": email_to,
"Name": "You"
}
],
"Headers": {
"Reply-To": email_reply_to,
},
"Subject": "Pruebas adjuntos",
"TextPart": "Greetings from Mailjet!",
"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!",
"Attachments": [
{
"ContentType": "image/jpg",
"Filename": "infografia.jpg",
"Base64Content": file_base64
}
]
}
]
}
result = mailjet.send.create(data=data)
print(result.status_code)
print(result.json())