api.services.gmail

Attributes

Functions

create_draft(owner, receiver_mail, receiver_name, ...) → None

Create a Gmail draft with the bon de commande attached.

send_alert_email(subject, body) → None

Best-effort error alert, sent (not drafted) from ALERT_EMAIL_SENDER to

send_email(*, sender, to, cc, subject, body, attachments) → None

Send a plain-text email with PDF / ZIP attachments from sender's mailbox

Module Contents

api.services.gmail.logger
api.services.gmail.GMAIL_SCOPES = ['https://www.googleapis.com/auth/gmail.compose']
api.services.gmail.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.

Parameters:
  • owner – Email of the account in which the draft is created.

  • receiver_mail – Email of the recipient.

  • receiver_name – Surname of the recipient.

  • receiver_surname – First name of the recipient.

  • bon_de_commande – The bon de commande PDF bytes to attach.

api.services.gmail.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.

api.services.gmail.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.