Overview
The notification system sends automated email alerts for SyftBox events:- New job submissions
- Job approvals and completions
- Peer connection requests
- Peer request approvals
Gmail Integration
Authentication
https://www.googleapis.com/auth/gmail.send- Send emails on behalf of user
GmailAuth
One-time OAuth2 authentication setupParameters:
credentials_path: Path- Path to Google Cloud credentials.json
Credentials - Google OAuth credentials objectOpens browser for OAuth consent flow, saves token for future use.Load and refresh existing credentialsParameters:
token_path: Path- Path to saved Gmail token
Credentials - Valid credentials (auto-refreshes if expired)Obtaining credentials.json
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Gmail API
- Create OAuth 2.0 Client ID (Desktop app type)
- Download credentials as
credentials.json - Place at
~/.syft-creds/credentials.json
Email Sender
GmailSender
Initialize Gmail senderParameters:
credentials: Credentials- Google OAuth credentialsuse_html: bool = True- Send HTML emails (falls back to plain text)
Job Notifications
Notify Data Owner about new job submissionParameters:
do_email: str- Data Owner emailjob_name: str- Name of the jobsubmitter: str- Data Scientist emailtimestamp: Optional[datetime]- Submission timejob_url: Optional[str]- URL to view job
bool - True if sent successfullyNotify Data Scientist that their job was approvedParameters:
ds_email: str- Data Scientist emailjob_name: str- Name of approved jobjob_url: Optional[str]- URL to view job
bool - True if sent successfullyNotify Data Scientist that their job completedParameters:
ds_email: str- Data Scientist emailjob_name: str- Name of completed jobduration: Optional[int]- Execution time in secondsresults_url: Optional[str]- URL to download results
bool - True if sent successfullyPeer Notifications
Notify Data Owner about new peer requestParameters:
do_email: str- Data Owner emailds_email: str- Data Scientist emailpeer_url: Optional[str]- URL to review request
bool - True if sent successfullyNotify Data Scientist that their request was sentParameters:
ds_email: str- Data Scientist emaildo_email: str- Data Owner email
bool - True if sent successfullyNotify Data Scientist that their peer request was acceptedParameters:
ds_email: str- Data Scientist emaildo_email: str- Data Owner email
bool - True if sent successfullyGeneric Email
Send custom email with HTML and plain textParameters:
to_email: str- Recipient emailsubject: str- Email subjectbody_text: str- Plain text body (fallback)body_html: Optional[str]- HTML body (preferred)
bool - True if sent successfullyEmail Templates
TemplateRenderer
Renders Jinja2 templates for HTML emails.Parameters:
templates_dir: Optional[Path]- Custom templates directory (defaults to built-in)
Render template with context dataParameters:
template_name: str- Template file name (e.g., “emails/new_job.html”)context: dict- Template variables
str - Rendered HTMLBuilt-in Templates
emails/new_job.html- New job notificationemails/job_approved.html- Job approval notificationemails/job_executed.html- Job completion notificationemails/new_peer_request.html- Peer request notificationemails/peer_granted.html- Peer approval notification
Template Filters
State Management
JsonStateManager
Tracks notification history to prevent duplicate emails.Parameters:
state_file: Path- Path to JSON state file
Check if entity was already notifiedParameters:
entity_id: str- Unique identifier (job name, peer email)event_type: str- Event type (“new”, “approved”, “executed”)
bool - True if already notifiedMark entity as notifiedParameters:
entity_id: str- Unique identifierevent_type: str- Event type
Get arbitrary data from stateParameters:
key: str- Data keydefault: Optional[Any]- Default if key doesn’t exist
Any - Stored valueStore arbitrary data in stateParameters:
key: str- Data keyvalue: Any- JSON-serializable value
Configuration
syft-bg Configuration
Stored at~/.syft-creds/config.yaml:
CLI Commands
Timeout Configuration
Gmail API requests have a 2-minute timeout:Error Handling
False on failure rather than raising exceptions.
Best Practices
- Always use state management - Prevents duplicate notifications
- Enable HTML emails - Better user experience with templates
- Set reasonable intervals - 30s for notifications is recommended
- Monitor logs - Use
syft-bg logs notify -fto debug issues - Handle OAuth expiry - Credentials auto-refresh if refresh token is valid
See Also
- Monitoring Services - Job and peer monitors
- Auto-Approval - Automatic approval rules