diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-27 19:35:01 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-27 19:35:01 +0300 |
| commit | e9547637ddb6b4fde18ed487d4730182afb6d92a (patch) | |
| tree | f33ab2a81162d51f464a0ebe7a9035710d9bdc38 | |
| parent | 83d91747820c3fb7d752e1d595d5df218fcea2e5 (diff) | |
Fix SendGridAlerter
| -rw-r--r-- | app/SendGridAlerter.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/app/SendGridAlerter.py b/app/SendGridAlerter.py index 0509a57..adb2296 100644 --- a/app/SendGridAlerter.py +++ b/app/SendGridAlerter.py @@ -25,27 +25,27 @@ class SendGridAlerter: try: now = datetime.now() now_text = now.strftime("%a, %d %b %Y %H:%M:%S +0000") - to_lst = [{"email": email} for email in self.email_to] + + from_name, from_email = self.email_from.split(":") + to_lst = [{"email": to} for to in self.email_to] subject = f"Aggro alert on {now_text}" API_URL = "https://api.sendgrid.com/v3/mail/send" + data = { "personalizations": [{"to": to_lst}], - "from": {"email": self.email_from}, - "subject": subject, + "from": {"email": from_email, "name": from_name}, + "subject": f"Aggro alert on {now_text}", "content": [ { - "type": "text/plain", - "value": text, + "type": "text/html", + "value": f"<pre>{text}</pre>", } ], } r = requests.post( API_URL, - data=data, - headers={ - "Authorization": f"Bearer {self.api_token}", - "Content-Type": "application/json", - }, + json=data, + headers={"Authorization": f"Bearer {self.api_token}"}, ) if r.status_code >= 400: raise Exception( |
