-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
67 lines (55 loc) · 1.84 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 10 10:48:38 2020
@author: dev
"""
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
import configparser
from configparser import ConfigParser
class Email:
def __init__(self):
'''
Utilising the Sendgrid API to send email notifications.
Returns
-------
None.
'''
email_config = ConfigParser()
email_config.read('./config.ini')
self.api_token = email_config.get('sendgrid_email','API_token')
self.email = email_config.get('sendgrid_email','email')
def message_send(self, num, date_time):
'''
Parameters
----------
num : int
Count of the people not following distancing guidelines in a video.
time : Datetime object
Time of processing the video files.
Returns
-------
None.
'''
date_time = date_time.replace('_',' ')
date_time = date_time.split()
time = date_time[1]
date = date_time[0]
message = Mail(
from_email =' [email protected]',
to_emails = self.email,
subject = 'Distancing protocol notification',
html_content = 'Greetings.<br>We found <strong>'+str(num)+
'</strong> instances of social distancing lapses in Sriperumbudur, Chennai plant.<br><strong>Date: '+
date+'</strong><br><strong>Time: '+time+'</strong>')
try:
sg = SendGridAPIClient(self.api_token)
response = sg.send(message)
print('Message sent successfully.')
# print(response.status_code)
# print(response.body)
# print(response.headers)
except Exception as e:
print(e.message)