-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathuse_jet_mail.py
54 lines (43 loc) · 1.25 KB
/
use_jet_mail.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
51
52
53
54
from mailjet_rest import Client
import re
api_key = 'your_api_key'
api_secret = 'your_api_secret'
# Make a regular expression
# for validating an Email
regex = '^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$'
# Define a function for
# for validating an Email
def validate_email(email):
# pass the regular expression
# and the string in search() method
if re.search(regex, email):
# print("Valid Email")
return True
else:
# print("Invalid Email")
return False
def send_email_to_employee(name, lname, email_address, subject, message):
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
'Messages': [
{
"From": {
"Email": "your email address",
"Name": "HT Employment System"
},
"To": [
{
"Email": f"{email_address}",
"Name": f"{name} {lname}"
}
],
"Subject": f"{subject}",
"TextPart": "Greetings",
"HTMLPart": f"<h5>Dear {name} {lname}!</h5><br /><p>{message}</p>",
"CustomID": "AppGettingStartedTest"
}
]
}
result = mailjet.send.create(data=data)
#print(result.status_code)
# print (result.json())