-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3cf9b0
commit 8f0d5b5
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import csv | ||
from io import StringIO | ||
|
||
import sendgrid | ||
from sendgrid.helpers.mail import Mail, Attachment | ||
from python_http_client.exceptions import HTTPError | ||
import base64 | ||
|
||
from admin_settings import settings | ||
|
||
def send_failure_notification_email(employees, number_of_employees ,admin_email): | ||
|
||
with open('apps/bamboohr/templates/mail_template.html', 'r') as file: | ||
email_template = file.read() | ||
|
||
email_content_html = email_template.format_map({'number_of_employees':number_of_employees}) | ||
|
||
csv_file = StringIO() | ||
csv_writer = csv.DictWriter(csv_file, fieldnames=['id', 'name']) | ||
csv_writer.writeheader() | ||
csv_writer.writerows(employees) | ||
|
||
csv_content_base64 = base64.b64encode(csv_file.getvalue().encode()).decode() | ||
|
||
message = Mail( | ||
from_email=settings.SENDGRID_EMAIL, | ||
to_emails=admin_email, | ||
subject='Error Importing Employees from Bamboo HR to Fyle', | ||
html_content=email_content_html | ||
) | ||
|
||
attachment = Attachment() | ||
attachment.file_content = csv_content_base64 | ||
attachment.file_name = 'employee_data.csv' | ||
attachment.file_type = 'text/csv' | ||
attachment.disposition = 'attachment' | ||
message.attachment = attachment | ||
|
||
sg = sendgrid.SendGridAPIClient(api_key=settings.SENDGRID_API_KEY) | ||
sg.send(message) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,6 @@ polling==0.3.2 | |
# Requests | ||
requests==2.25.0 | ||
sentry-sdk==1.19.1 | ||
|
||
#sendgrid | ||
sendgrid==6.11.0 |