mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
16ba29cf4a
Property Based Tests / api-test (push) Has been cancelled
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusan <borovcanindusan1@gmail.com> Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@absmach.eu> Co-authored-by: Rodney Osodo <socials@rodneyosodo.com> Co-authored-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 fetches user information from Atom entities and sends styled email notifications using SMTP.
Features
- Event-Driven: Listens to invitation events from the event store (NATS/RabbitMQ)
- Atom Integration: Fetches user details (name, email) from Atom
- 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 → Atom
↓
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
Atom Configuration
ATOM_URL- Atom HTTP URLATOM_SERVICE_TOKEN- Service bearer token, if provisionedATOM_SERVICE_USERNAME/ATOM_SERVICE_SECRET- Service credential fallbackATOM_ADMIN_USERNAME/ATOM_ADMIN_SECRET- Admin credential fallbackATOM_TIMEOUT- Atom HTTP timeout
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
- Atom - for fetching user information
- Event store (NATS/RabbitMQ) - for receiving invitation events
- SMTP server - for sending emails