api.services.gmail ================== .. py:module:: api.services.gmail Attributes ---------- .. autoapisummary:: api.services.gmail.logger api.services.gmail.GMAIL_SCOPES Functions --------- .. autoapisummary:: api.services.gmail.create_draft api.services.gmail.send_alert_email api.services.gmail.send_email Module Contents --------------- .. py:data:: logger .. py:data:: GMAIL_SCOPES :value: ['https://www.googleapis.com/auth/gmail.compose'] .. py:function:: create_draft(owner: str, receiver_mail: str, receiver_name: str, receiver_surname: str, bon_de_commande: bytes, file_name: str) -> None Create a Gmail draft with the bon de commande attached. Uses a Google Workspace service account with domain-wide delegation to impersonate the ``owner`` (the responsible employee) and create the draft in their mailbox. :param owner: Email of the account in which the draft is created. :param receiver_mail: Email of the recipient. :param receiver_name: Surname of the recipient. :param receiver_surname: First name of the recipient. :param bon_de_commande: The bon de commande PDF bytes to attach. .. py:function:: send_alert_email(subject: str, body: str) -> None Best-effort error alert, sent (not drafted) from ALERT_EMAIL_SENDER to ALERT_EMAIL_RECIPIENTS. Never raises -- a failed alert must never fail the script run it's reporting on; a log line is the fallback. .. py:function:: send_email(*, sender: str, to: list[str], cc: list[str], subject: str, body: str, attachments: list[tuple[str, bytes]]) -> None Send a plain-text email with PDF / ZIP attachments from ``sender``'s mailbox (domain-wide delegation, as above). Raises on failure: the caller (the payroll routes) reports it to the user, unlike the best-effort alerts. Uploaded as media (message/rfc822): a JSON ``raw`` body is limited to a few MB, the media upload goes up to Gmail's own 25 MB message limit.