Zum Hauptinhalt springen

SendGrid Smart-Home-Integration, kostenlos und Open Source

SendGrid-Integration fĂŒr Gladys Assistant

Unofficial: e-mails from your scenes sent through your SendGrid account.

Info

Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfĂŒgbar.

Unofficial integration, not affiliated with Twilio SendGrid. It sends e-mails from your scenes through your SendGrid account with the Mail Send API v3; it never reads any. This integration has never been tested with a real SendGrid account: it was built from the official SendGrid documentation and tested against local fake servers. Reports are welcome.

What leaves, and when​

An e-mail leaves only on one of these two paths:

  1. The “Send an e-mail with SendGrid” scene action: one plain-text e-mail, with an optional subject (the default subject otherwise), to the recipients of the configuration: all of them when the “Recipient” field is empty, or the one it names. An address that is not in the list is refused and nothing leaves: a scene cannot write to anyone else. Each recipient receives the e-mail alone (nobody sees the others). Its output message_id is the SendGrid id of the e-mail (X-Message-Id).
  2. The Test button, in SendGrid sandbox mode, to the first recipient: SendGrid checks the key and the test message and delivers nothing. Whether SendGrid also checks the sender in sandbox mode is not confirmed: the first real e-mail tells. The button calls SendGrid at each click, outside the daily limit (bounded by the 2 requests at once and the pause). If SendGrid ignored the sandbox flag, the test e-mail would really be delivered (not checked on a real account yet).

Nothing is sent at start-up, on a schedule, on a reconnection or when the configuration is saved. The Gladys messages (“Send a message” action, system messages) are not relayed: this integration only serves scenes.

Setting up​

  1. In SendGrid, Settings → API Keys → Create API Key, choose Restricted Access and give Mail Send only (full access works too, but is not needed). Copy the key (it starts with SG.; SendGrid shows it once).
  2. Settings → Sender Authentication: verify the sender address (Single Sender Verification) or authenticate its domain. Without it, SendGrid refuses every e-mail (“not the sender address”).
  3. In Gladys, fill in the key, the data region (EU only for an account or subuser created in the SendGrid EU region), the sender address, optionally the sender name, the recipients (1 to 10 addresses separated by commas), the default subject and the daily limit; save, then click Test.

The API key is kept by Gladys in its database, never shown again, and sent only to SendGrid.

What protects your account and your plan​

  • Fixed recipients and sender: only the administrator chooses them, in the configuration.
  • Daily limit (20 by default, 1 to 500): at most this many e-mails over any 24 hours, one per recipient (an e-mail to 3 recipients counts 3). Beyond it nothing is sent (an e-mail that does not fit for all its recipients is refused whole) and the action fails with the time of the next possible e-mail. The count is kept in /data across restarts. An e-mail is counted before it leaves. It is given back only when nothing left: SendGrid answered 400, 401, 403, 413 or 429, or the connection never opened (connection refused, unknown name, network unreachable). No answer, a cut connection, a 5xx or any other 4xx (408, 418, a company relay's 499...) keep it counted: it may have left.
  • /data not safe: while /data is not read yet, unreadable, too slow (more than 1 second) or a write fails, the count could not survive a restart. Then only 2 e-mails per rolling 24 hours leave (counted in memory, one per recipient); the next is refused (“/data is unread, unreadable or cannot be written
”) and the status says so. A /data that does not exist yet (first start) is normal: the daily limit applies. Once /data works again, the normal limit applies again.
  • Never sent twice: SendGrid accepts an e-mail with a 202 Accepted; the integration never sends an e-mail again, whatever happened (no answer, a cut connection, a server error). When SendGrid did not confirm, the action fails with “it may have been sent, so it is not sent again”.
  • Texts bounded: subject on one line (line breaks removed), 200 characters at most; text 10,000 characters at most; plain text only, click and open tracking turned off.
  • At most 2 e-mails at once, 10 waiting; beyond, or when the wait would leave too little time, “too many e-mails at once” and nothing is sent. An e-mail waiting while the key, the region or the sender changes, or whose recipient is removed from the list, is not sent.
  • Slow down: after a 429 (too many requests) or a SendGrid server error (5xx, even with an unreadable body), nothing is sent for 60 seconds, doubled at each new failure up to 1 hour (a Retry-After or X-RateLimit-Reset of SendGrid is followed up to 6 hours), Test included. The pause is kept in /data; an e-mail accepted while it began does not lift it.
  • Refused key: only a 401 carrying SendGrid's own error body. Then nothing more is sent with this key until the key or the region changes or the Test button succeeds (the Test button tries a refused key too, outside a pause). Only two 8-bit prints of a salted HMAC are kept in /data, never the key; a new key entered while the integration runs is tried even if its prints happen to match (a key entered while it was stopped is blocked by such a match, 1 chance in 65,536: the Test button then lifts it). Not a refusal of the key: a 401 without SendGrid's body (empty, a proxy page, a cut answer), a 403 (sender not verified, key without the “Mail Send” access), a refused e-mail (400, 413). A 401 without SendGrid's body and a 403 are not tried again at each e-mail either: they set the same pause as a 429 (60 seconds doubled up to 1 hour, kept in /data, Test included); nothing is kept about the key. Saving another key, region or sender address lifts such a pause at once (a 429 or 5xx pause stays).

Status​

StatusMeaning
ReadySettings filled in; the key is checked at the first e-mail or the Test button.
SendGrid accepted the last e-mailWith the count of the last 24 hours and the limit.
SendGrid accepted the key and the test messageThe last Test succeeded (nothing delivered).
Refused key / sender not verified / paused / daily limit reachedNothing is sent; the text says until when or what to change.
Daily counter not saved/data is unread, read-only or slow: only 2 e-mails per 24 hours leave until it works.

Privacy​

The logs show addresses masked (j***@e***.com); the key, subjects and texts are never logged, put in the status or written to /data, nor the texts of SendGrid's error answers (they may quote an address). /data/sendgrid.json holds the times of the e-mails of the last 24 hours, the pause and the prints of a refused key.

Limits​

  • Plain text only; no attachment, no template, no HTML.
  • E-mails are not received.
  • The sending quotas of your SendGrid plan apply on top of the daily limit; every e-mail counts in your plan.

Konfigurationseinstellungen​

Diese Einstellungen fragt SendGrid in seinem Konfigurationsbildschirm in Gladys ab.

EinstellungTypPflichtfeldBeschreibung
SendGrid in GladyssectionNeinUnofficial integration, not affiliated with Twilio SendGrid. It only sends e-mails, never reads any, through the “Send an e-mail with SendGrid” scene action, and only to the recipients listed below. In SendGrid, create an API key with the “Mail Send” access only (Settings, API Keys, Restricted Access), verify the sender address (Single Sender Verification) or its domain, then click “Test”: SendGrid checks the key and a test message in sandbox mode and delivers nothing. Every e-mail counts in your SendGrid plan; the daily limit below stops a runaway scene.
API keysecretJaStarts with “SG.”; give it the “Mail Send” access only. Kept by Gladys in its database, never shown again, sent only to SendGrid.
Data regionselectNeinEU only for an account or subuser created in the SendGrid EU region (its key only works on the EU host).
Sender addressstringJaMust be verified in SendGrid (Single Sender Verification, or an authenticated domain), otherwise SendGrid refuses every e-mail.
Sender namestringNein
RecipientsstringJa1 to 10 addresses separated by commas. The scenes write only to these: to all of them, or to the one the action names. Each recipient receives the e-mail alone (no one sees the others) and counts as one e-mail.
Default subjectstringNeinUsed by the scene action when it gives no subject.
Daily limit of e-mailsnumberNeinAt most this many e-mails in any 24 hours, one per recipient (Test excluded); beyond, nothing is sent and the action fails. Kept across restarts.

So installierst du SendGrid in Gladys​

  1. Öffne in Gladys Integrationen: SendGrid erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
  2. Klicke auf Installieren. Gladys lÀdt das Docker-Image (ghcr.io/lm1lc3n7/gladys-sendgrid:0.1.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die OberflÀche der Integration (GerÀte, Erkennung und Konfiguration).
  3. Öffne den Bildschirm Konfiguration der Integration, fĂŒlle die Einstellungen aus und speichere.
  4. Du kannst sie auch direkt ĂŒber die URL ihres Repositorys installieren: https://github.com/LM1LC3N7/gladys-sendgrid.

SendGrid benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stĂŒndlich aktualisiert, eine neue Version ist also spĂ€testens eine Stunde nach ihrer Veröffentlichung verfĂŒgbar.

Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.

Über externe Integrationen​

SendGrid ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und fĂŒhrt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LM1LC3N7 veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.

Abonniere den Newsletter von Gladys Assistant

Ein paar E-Mails im Monat zu neuen Releases und Neuigkeiten aus dem Projekt. Verschickt von Pierre-Gilles Leymarie, dem GrĂŒnder des Projekts. Jederzeit abbestellbar 🙂