M
📧 Powerful, Flexible Email Templating for MedusaJS
MedusaJS Mail Templates
📧 Powerful, Flexible Email Templating for MedusaJS
🌟 Features
- Advanced email template generation
- Nodemailer integration
- SMTP and transport flexibility
- Preview and development modes
- Internationalization support
- Extensive customization options
📦 Installation
Install the package using npm:
npm install @vymalo/medusa-mail
Or using yarn:
yarn add @vymalo/medusa-mail
🔧 Configuration Types
interface EmailConfig<T = any> {// Nodemailer message configurationmessage?: Mail.Options;// Email transport optionstransport?: NodeMailerTransportOptions;// Template views and renderingviews?: View;// Send behavior controlsend?: boolean;preview?: boolean | PreviewEmailOpts;// Advanced rendering optionscustomRender?: boolean;render?: (view: string, locals?: T) => Promise<any>;// Internationalizationi18n?: any;// Rendering configurationstextOnly?: boolean;htmlToText?: HtmlToTextOptions | false;// Subject line customizationsubjectPrefix?: string | false;// HTML inlining and stylingjuice?: boolean;juiceSettings?: JuiceGlobalConfig;juiceResources?: juice.Options;// Custom template path resolutiongetPath?: (path: string, template: string, locals: any) => string;}
🚀 Usage Example
modules: [{resolve: "@medusajs/medusa/notification",options: {providers: [{resolve: `@vymalo/medusa-mail`,id: "email-provider",options: {// Basic configurationchannels: ["email"],message: {from: "no-reply@yourcompany.com"},// Environment-specific settingssend: process.env.NODE_ENV === "production",preview: process.env.NODE_ENV !== "production",// Transport configurationtransport: "smtp://localhost:1025",// Advanced customizationssubjectPrefix: process.env.NODE_ENV !== "production"? `[${process.env.NODE_ENV.toUpperCase()}]`: false,// HTML to text conversionhtmlToText: {wordwrap: 130,preserveNewlines: true}},},],},}]
🛠️ Key Configuration Options
Message Configuration
- : Nodemailer message options
- : Sender email address
- , , : Recipient configurations
- : Email subject
Transport Options
- : Connection method
- SMTP:
- SendGrid, Mailgun, etc.
- Supports all Nodemailer transport methods
Rendering Modes
- : Enable/disable actual email sending
- : Generate email preview
- : Render text-only emails
- : Use custom rendering function
Internationalization
- : Enable template translations
- Supports various internationalization libraries
🌐 Environment Considerations
- Use different configurations per environment
- Disable sending in development
- Enable email previews
- Secure sensitive transport credentials
🔒 Security Best Practices
- Use environment variables for credentials
- Limit preview and sending in production
- Implement proper error handling
- Validate email configurations
🤝 Contributing
Contributions welcome!
- Improve template rendering
- Add new transport methods
- Enhance internationalization support