Magistrala
Dev GuideServices

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

EventTrigger
invitation.sendA user is invited to join a domain
invitation.acceptThe invited user accepts the domain invitation
invitation.rejectThe invited user rejects the domain invitation

Configuration

General

VariableDescriptionDefault
MG_NOTIFICATIONS_LOG_LEVELLog level (debug, info, warn, error)info
MG_NOTIFICATIONS_INSTANCE_IDInstance identifier""
MG_NOTIFICATIONS_DOMAIN_ALT_NAMEAlternative label for "domain" (e.g. workspace)domains
MG_ES_URLEvent store URLnats://localhost:4222

Email (SMTP)

VariableDescriptionDefault
MG_EMAIL_HOSTSMTP server hostlocalhost
MG_EMAIL_PORTSMTP server port25
MG_EMAIL_USERNAMESMTP username""
MG_EMAIL_PASSWORDSMTP password""
MG_EMAIL_FROM_ADDRESSSender email addressnoreply@magistrala.com
MG_EMAIL_FROM_NAMESender display nameMagistrala Notifications

Email Templates

VariableDescription
MG_EMAIL_INVITATION_TEMPLATEPath to invitation sent email template
MG_EMAIL_ACCEPTANCE_TEMPLATEPath to invitation accepted email template
MG_EMAIL_REJECTION_TEMPLATEPath to invitation rejected email template

gRPC (Users service)

VariableDescription
MG_USERS_GRPC_URLUsers service gRPC URL
MG_USERS_GRPC_TIMEOUTgRPC request timeout
MG_USERS_GRPC_CLIENT_CERTPath to client certificate
MG_USERS_GRPC_CLIENT_KEYPath to client key
MG_USERS_GRPC_SERVER_CA_CERTSPath to trusted CA certificates for Users gRPC

Email Templates

The service ships three HTML email templates with Magistrala branding:

TemplateHeader ColorPurpose
invitation-sent-email.tmplBlue (#083662)Notify user of a domain invitation
invitation-accepted-email.tmplGreenNotify inviter that user accepted
invitation-rejected-email.tmplRedNotify 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 \
./notifications

Architecture

domains service → event store (NATS) → notifications service → users service (gRPC)

                                           SMTP Server → Email Recipients

The 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

On this page