Notification Providers
Notification providers handle sending notifications through various channels like email, SMS, push notifications, and more. They support both template-based and content-based notifications with attachments.Available Notification Providers
Medusa includes two notification providers:Local Notification Provider
@medusajs/medusa/notification-local - Logs notifications to the console.
Use cases:
- Development and testing
- Debugging notification flows
- Preview notification data
SendGrid Notification Provider
@medusajs/medusa/notification-sendgrid - Sends email notifications via SendGrid.
Use cases:
- Production email delivery
- Transactional emails
- Marketing emails
- Template-based emails
- Support for SendGrid templates
- HTML email content
- Email attachments
- Dynamic template data
Installation
Both providers are included in the core Medusa package:Configuration
- Local Provider
- SendGrid Provider
- Multiple Providers
Configure the local notification provider:
medusa-config.ts
Notification Provider Interface
All notification providers extendAbstractNotificationProviderService and implement the following method:
send(notification: ProviderSendNotificationDTO): Promise<ProviderSendNotificationResultsDTO>
Sends a notification.
With HTML Content:
to- Recipient email addresschannel- Notification channel (e.g., “email”, “sms”)template- Template identifier (provider-specific)from- Sender email (optional, uses default from config)content- Notification contentsubject- Email subjecthtml- HTML contenttext- Plain text content (optional)
data- Dynamic data for templatesattachments- File attachmentsfilename- Attachment filenamecontent- Base64-encoded contentcontent_type- MIME typedisposition- “attachment” or “inline”id- Content ID for inline images
Using the Notification Module
Access notification providers through the Notification Module:Notification Workflows
Notifications are typically sent through workflows that handle specific events:Common Notification Types
Order Confirmation
Shipment Notification
Password Reset
Creating Custom Notification Providers
Create a custom notification provider by extendingAbstractNotificationProviderService:
packages/modules/providers/notification-custom/src/services/custom-notification.ts
SMS Provider Example
packages/modules/providers/notification-sms/src/services/sms-notification.ts
packages/modules/providers/notification-custom/src/index.ts
Reference
- Local Provider:
packages/modules/providers/notification-local/src/services/local.ts - SendGrid Provider:
packages/modules/providers/notification-sendgrid/src/services/sendgrid.ts - Base class:
packages/core/utils/src/notification/abstract-notification-provider.ts - Types:
packages/core/types/src/notification/provider.ts
Next Steps
Payment Providers
Send payment confirmation emails
Fulfillment Providers
Send shipment notifications