mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-22 20:00:22 +00:00
61d0427898
Signed-off-by: dusan <borovcanindusan1@gmail.com>
Notifications Service
The Notifications Service is responsible for sending email notifications when domain invitation events occur in the Magistrala platform.
Overview
This service listens to invitation events from the domains service and sends email notifications to users when:
- They are invited to join a domain (
invitation.send) - Someone accepts their domain invitation (
invitation.accept) - Someone rejects their domain invitation (
invitation.reject)
The service uses gRPC to fetch user information from the users service and sends styled email notifications using SMTP.
Features
- Event-Driven: Listens to invitation events from the event store (NATS/RabbitMQ)
- gRPC Integration: Fetches user details (name, email) from the users service
- Beautiful Email Templates: Styled HTML email templates with Magistrala branding (#083662)
- Configurable: Email server settings and templates are fully configurable
Architecture
domains service → event store → notifications service → users service (gRPC)
↓
SMTP Server → Email Recipients
Configuration
The service is configured using environment variables:
General Configuration
MG_NOTIFICATIONS_LOG_LEVEL- Log level (default: "info")MG_NOTIFICATIONS_INSTANCE_ID- Instance ID for the serviceMG_NOTIFICATIONS_DOMAIN_ALT_NAME- Alternative name for domains such as, say, workspaces or tenants (default: "domains")MG_ES_URL- Event store URL (default: "nats://localhost:4222")
Email Configuration
MG_EMAIL_HOST- SMTP server host (default: "localhost")MG_EMAIL_PORT- SMTP server port (default: "25")MG_EMAIL_USERNAME- SMTP usernameMG_EMAIL_PASSWORD- SMTP passwordMG_EMAIL_FROM_ADDRESS- From email address (default: "noreply@magistrala.com")MG_EMAIL_FROM_NAME- From name (default: "Magistrala Notifications")
Template Configuration
MG_EMAIL_INVITATION_TEMPLATE- Path to invitation email templateMG_EMAIL_ACCEPTANCE_TEMPLATE- Path to acceptance email templateMG_EMAIL_REJECTION_TEMPLATE- Path to rejection email template
gRPC Configuration (Users Service)
MG_USERS_GRPC_URL- Users service gRPC URLMG_USERS_GRPC_TIMEOUT- gRPC request timeoutMG_USERS_GRPC_CLIENT_CERT- Client certificate pathMG_USERS_GRPC_CLIENT_KEY- Client key pathMG_USERS_GRPC_SERVER_CA_CERTS- Server CA certificates path
Running the Service
go run cmd/notifications/main.go
Or build and run:
go build -o notifications cmd/notifications/main.go
./notifications
Email Templates
The service includes three beautifully styled email templates with Magistrala branding:
- Invitation Sent (
invitation-sent-email.tmpl) - Blue gradient header (#083662) - Invitation Accepted (
invitation-accepted-email.tmpl) - Green gradient header - Invitation Rejected (
invitation-rejected-email.tmpl) - Red gradient header
All templates are responsive and include:
- Professional styling
- Gradient headers
- Clear call-to-action sections
- Magistrala branding
Testing
Run the tests:
go test ./notifications/... -v
To run email integration tests (requires SMTP server):
MG_RUN_EMAIL_TESTS=true go test ./notifications/emailer -v
Development
The service consists of:
notifier.go- Main service interfaceemailer/emailer.go- Email notification implementationevents/consumer.go- Event consumer for invitation eventscmd/notifications/main.go- Service entry point- Tests with mocks for unit testing
Dependencies
- Users service (gRPC) - for fetching user information
- Event store (NATS/RabbitMQ) - for receiving invitation events
- SMTP server - for sending emails