@vymalo/medusa-mail
v1.0.9
Published
๐ง Powerful, Flexible Email Templating for MedusaJS
Maintainers
Readme
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-mailOr using yarn:
yarn add @vymalo/medusa-mail๐ง Configuration Types
interface EmailConfig<T = any> {
// Nodemailer message configuration
message?: Mail.Options;
// Email transport options
transport?: NodeMailerTransportOptions;
// Template views and rendering
views?: View;
// Send behavior control
send?: boolean;
preview?: boolean | PreviewEmailOpts;
// Advanced rendering options
customRender?: boolean;
render?: (view: string, locals?: T) => Promise<any>;
// Internationalization
i18n?: any;
// Rendering configurations
textOnly?: boolean;
htmlToText?: HtmlToTextOptions | false;
// Subject line customization
subjectPrefix?: string | false;
// HTML inlining and styling
juice?: boolean;
juiceSettings?: JuiceGlobalConfig;
juiceResources?: juice.Options;
// Custom template path resolution
getPath?: (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 configuration
channels: ["email"],
message: {
from: "[email protected]"
},
// Environment-specific settings
send: process.env.NODE_ENV === "production",
preview: process.env.NODE_ENV !== "production",
// Transport configuration
transport: "smtp://localhost:1025",
// Advanced customizations
subjectPrefix: process.env.NODE_ENV !== "production"
? `[${process.env.NODE_ENV.toUpperCase()}]`
: false,
// HTML to text conversion
htmlToText: {
wordwrap: 130,
preserveNewlines: true
}
},
},
],
},
}
]๐ ๏ธ Key Configuration Options
Message Configuration
message: Nodemailer message optionsfrom: Sender email addressto,cc,bcc: Recipient configurationssubject: Email subject
Transport Options
transport: Connection method- SMTP:
smtp://host:port - SendGrid, Mailgun, etc.
- SMTP:
- Supports all Nodemailer transport methods
Rendering Modes
send: Enable/disable actual email sendingpreview: Generate email previewtextOnly: Render text-only emailscustomRender: Use custom rendering function
Internationalization
i18n: 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
