Notifications
Email notification service for Magistrala — listens to domain invitation events and sends styled HTML email notifications to users when they are invited, accept, or reject a domain invitation.
The Notifications service is an event-driven service that sends email notifications for domain invitation lifecycle events. It listens to the platform event stream (NATS or RabbitMQ), fetches user details from the Users service over gRPC, and delivers styled HTML emails via SMTP when a user is invited to a domain, accepts an invitation, or rejects one.
Events Handled
| Event | Trigger |
|---|---|
invitation.send | A user is invited to join a domain |
invitation.accept | The invited user accepts the domain invitation |
invitation.reject | The invited user rejects the domain invitation |
Configuration
General
| Variable | Description | Default |
|---|---|---|
MG_NOTIFICATIONS_LOG_LEVEL | Log level (debug, info, warn, error) | info |
MG_NOTIFICATIONS_INSTANCE_ID | Instance identifier | "" |
MG_NOTIFICATIONS_DOMAIN_ALT_NAME | Alternative label for "domain" (e.g. workspace) | domains |
MG_ES_URL | Event store URL | nats://localhost:4222 |
Email (SMTP)
| Variable | Description | Default |
|---|---|---|
MG_EMAIL_HOST | SMTP server host | localhost |
MG_EMAIL_PORT | SMTP server port | 25 |
MG_EMAIL_USERNAME | SMTP username | "" |
MG_EMAIL_PASSWORD | SMTP password | "" |
MG_EMAIL_FROM_ADDRESS | Sender email address | noreply@magistrala.com |
MG_EMAIL_FROM_NAME | Sender display name | Magistrala Notifications |
Email Templates
| Variable | Description |
|---|---|
MG_EMAIL_INVITATION_TEMPLATE | Path to invitation sent email template |
MG_EMAIL_ACCEPTANCE_TEMPLATE | Path to invitation accepted email template |
MG_EMAIL_REJECTION_TEMPLATE | Path to invitation rejected email template |
gRPC (Users service)
| Variable | Description |
|---|---|
MG_USERS_GRPC_URL | Users service gRPC URL |
MG_USERS_GRPC_TIMEOUT | gRPC request timeout |
MG_USERS_GRPC_CLIENT_CERT | Path to client certificate |
MG_USERS_GRPC_CLIENT_KEY | Path to client key |
MG_USERS_GRPC_SERVER_CA_CERTS | Path to trusted CA certificates for Users gRPC |
Email Templates
The service ships three HTML email templates with Magistrala branding:
| Template | Header Color | Purpose |
|---|---|---|
invitation-sent-email.tmpl | Blue (#083662) | Notify user of a domain invitation |
invitation-accepted-email.tmpl | Green | Notify inviter that user accepted |
invitation-rejected-email.tmpl | Red | Notify inviter that user rejected |
All templates are responsive HTML and include a call-to-action section. You can supply custom templates via the MG_EMAIL_*_TEMPLATE environment variables.
Deployment
The service requires NATS for the event stream and the Users service gRPC endpoint. It has no database of its own.
git clone https://github.com/absmach/magistrala
cd magistrala
go build -o notifications cmd/notifications/main.go
MG_NOTIFICATIONS_LOG_LEVEL=info \
MG_ES_URL=nats://localhost:4222 \
MG_EMAIL_HOST=smtp.example.com \
MG_EMAIL_PORT=587 \
MG_EMAIL_USERNAME=user \
MG_EMAIL_PASSWORD=pass \
MG_EMAIL_FROM_ADDRESS=noreply@example.com \
MG_USERS_GRPC_URL=localhost:7009 \
./notificationsArchitecture
domains service → event store (NATS) → notifications service → users service (gRPC)
↓
SMTP Server → Email RecipientsThe service is stateless — it fetches all required data per event from the Users gRPC endpoint and delivers immediately via SMTP. No local state is kept between events.
Testing
# Unit tests
go test ./notifications/... -v
# Email integration tests (requires a running SMTP server)
MG_RUN_EMAIL_TESTS=true go test ./notifications/emailer -v