{"id":13394077,"url":"https://github.com/eladnava/mailgen","last_synced_at":"2025-05-13T15:09:30.339Z","repository":{"id":37514598,"uuid":"59653935","full_name":"eladnava/mailgen","owner":"eladnava","description":"A Node.js package that generates clean, responsive HTML e-mails for sending transactional mail.","archived":false,"fork":false,"pushed_at":"2025-01-08T14:58:17.000Z","size":1525,"stargazers_count":2541,"open_issues_count":4,"forks_count":120,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-23T18:54:05.019Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eladnava.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-25T10:25:41.000Z","updated_at":"2025-04-23T01:33:43.000Z","dependencies_parsed_at":"2024-01-13T19:24:46.809Z","dependency_job_id":"243b55bd-30f1-4228-a852-536690808e15","html_url":"https://github.com/eladnava/mailgen","commit_stats":{"total_commits":236,"total_committers":20,"mean_commits":11.8,"dds":0.2584745762711864,"last_synced_commit":"f02c1ad0e57169cded52222885f2f73ccb716e2b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eladnava%2Fmailgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eladnava%2Fmailgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eladnava%2Fmailgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eladnava%2Fmailgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eladnava","download_url":"https://codeload.github.com/eladnava/mailgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969240,"owners_count":21992262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:08.208Z","updated_at":"2025-05-13T15:09:25.316Z","avatar_url":"https://github.com/eladnava.png","language":"HTML","funding_links":[],"categories":["HTML","Projects by main language","🤖 AI \u0026 Machine Learning"],"sub_categories":["Old Projects"],"readme":"# mailgen\n[![npm version](https://badge.fury.io/js/mailgen.svg)](https://www.npmjs.com/package/mailgen)\n\nA Node.js package that generates clean, responsive HTML e-mails for sending transactional mail.\n\n\u003e Programmatically create beautiful e-mails using plain old JavaScript.\n\n## Demo\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/salted/reset.png\" height=\"400\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/salted/receipt.png\" height=\"400\" /\u003e\n\n\u003e These e-mails were generated using the built-in `salted` theme.\n\n## Usage\n\nFirst, install the package using npm:\n\n```shell\nnpm install mailgen --save\n```\n\nThen, start using the package by importing and configuring it:\n\n```js\nvar Mailgen = require('mailgen');\n\n// Configure mailgen by setting a theme and your product info\nvar mailGenerator = new Mailgen({\n    theme: 'default',\n    product: {\n        // Appears in header \u0026 footer of e-mails\n        name: 'Mailgen',\n        link: 'https://mailgen.js/'\n        // Optional product logo\n        // logo: 'https://mailgen.js/img/logo.png'\n    }\n});\n```\n\nNext, generate an e-mail using the following code:\n\n```js\nvar email = {\n    body: {\n        name: 'John Appleseed',\n        intro: 'Welcome to Mailgen! We\\'re very excited to have you on board.',\n        action: {\n            instructions: 'To get started with Mailgen, please click here:',\n            button: {\n                color: '#22BC66', // Optional action button color\n                text: 'Confirm your account',\n                link: 'https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010'\n            }\n        },\n        outro: 'Need help, or have questions? Just reply to this email, we\\'d love to help.'\n    }\n};\n\n// Generate an HTML email with the provided contents\nvar emailBody = mailGenerator.generate(email);\n\n// Generate the plaintext version of the e-mail (for clients that do not support HTML)\nvar emailText = mailGenerator.generatePlaintext(email);\n\n// Optionally, preview the generated HTML e-mail by writing it to a local file\nrequire('fs').writeFileSync('preview.html', emailBody, 'utf8');\n\n// `emailBody` now contains the HTML body,\n// and `emailText` contains the textual version.\n//\n// It's up to you to send the e-mail.\n// Check out nodemailer to accomplish this:\n// https://nodemailer.com/\n```\n\nThis code would output the following HTML template:\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/default/welcome.png\" height=\"400\" /\u003e\n\n## More Examples\n\n* [Receipt](examples/receipt.js)\n* [Password Reset](examples/reset.js)\n\n## Plaintext E-mails\n\nTo generate a [plaintext version of the e-mail](https://litmus.com/blog/best-practices-for-plain-text-emails-a-look-at-why-theyre-important), simply call `generatePlaintext()`:\n\n```js\n// Generate plaintext email using mailgen\nvar emailText = mailGenerator.generatePlaintext(email);\n```\n\n## Supported Themes\n\nThe following open-source themes are bundled with this package:\n\n* `default` by [Postmark Transactional Email Templates](https://github.com/wildbit/postmark-templates)\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/default/welcome.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/default/reset.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/default/receipt.png\" height=\"200\" /\u003e\n\n* `neopolitan` by [Send With Us](https://github.com/sendwithus/templates/tree/master/templates/neopolitan)\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/neopolitan/welcome.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/neopolitan/reset.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/neopolitan/receipt.png\" height=\"200\" /\u003e\n\n* `salted` by [Jason Rodriguez](https://github.com/rodriguezcommaj/salted)\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/salted/welcome.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/salted/reset.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/salted/receipt.png\" height=\"200\" /\u003e\n\n* `cerberus` by [Ted Goas](http://tedgoas.github.io/Cerberus/)\n\n\u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/cerberus/welcome.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/cerberus/reset.png\" height=\"200\" /\u003e \u003cimg src=\"https://raw.github.com/eladnava/mailgen/master/screenshots/cerberus/receipt.png\" height=\"200\" /\u003e\n\nWe thank the contributing authors for creating these themes.\n\n## Custom Themes\n\nIf you want to supply your own custom theme or add a new built-in theme, check out [THEME.md](THEME.md) for instructions.\n\n## RTL Support\n\nTo change the default text direction (left-to-right), simply override it as follows:\n\n```js\nvar mailGenerator = new Mailgen({\n    theme: 'salted',\n    // Custom text direction\n    textDirection: 'rtl',\n});\n```\n\n## Custom Logo Height\n\nTo change the default product logo height, set it as follows:\n\n```js\nvar mailGenerator = new Mailgen({\n    product: {\n        // Custom product logo URL\n        logo: 'https://mailgen.js/img/logo.png',\n        // Custom logo height\n        logoHeight: '30px'\n    }\n});\n```\n\n## Language Customizations\n\nTo customize the e-mail greeting (Hi) or signature (Yours truly), supply custom strings within the e-mail `body`:\n\n```js\nvar email = {\n    body: {\n        greeting: 'Dear',\n        signature: 'Sincerely'\n    }\n};\n```\n\nTo not include the signature or greeting at all, set the signature or greeting fields to `false`:\n\n```js\nvar email = {\n    body: {\n      signature: false,\n      greeting: false // This will override and disable name \u0026 title options\n    }\n};\n```\n\nTo use a custom title string rather than a greeting/name introduction, provide it instead of `name`:\n\n```js\nvar email = {\n    body: {\n        // Title will override `name`\n        title: 'Welcome to Mailgen!'\n    }\n};\n```\n\nTo customize the `copyright`, override it when initializing `Mailgen` within your `product` as follows:\n\n```js\n// Configure mailgen\nvar mailGenerator = new Mailgen({\n    theme: 'salted',\n    product: {\n        name: 'Mailgen',\n        link: 'https://mailgen.js/',\n        // Custom copyright notice\n        copyright: `Copyright © ${new Date().getFullYear()} Mailgen. All rights reserved.`,\n    }\n});\n```\n\n## Multiline Support\n\nTo inject multiple lines of text for the `intro` or `outro`, simply supply an array of strings:\n\n```js\nvar email = {\n    body: {\n        intro: ['Welcome to Mailgen!', 'We\\'re very excited to have you on board.'],\n        outro: ['Need help, or have questions?', 'Just reply to this email, we\\'d love to help.'],\n    }\n};\n```\n\n## Elements\n\nMailgen supports injecting custom elements such as dictionaries, tables and action buttons into e-mails.\n\n### Action\n\nTo inject an action button in to the e-mail, supply the `action` object as follows:\n\n```js\nvar email = {\n    body: {\n        action: {\n            instructions: 'To get started with Mailgen, please click here:',\n            button: {\n                color: '#48cfad', // Optional action button color\n                text: 'Confirm your account',\n                link: 'https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010'\n            }\n        }\n    }\n};\n```\n\nTo inject multiple action buttons in to the e-mail, supply the `action` object as follows:\n\n```js\nvar email = {\n    body: {\n        action: [\n            {\n                instructions: 'To get started with Mailgen, please click here:',\n                button: {\n                    color: '#22BC66',\n                    text: 'Confirm your account',\n                    link: 'https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010'\n                }\n            },\n            {\n                instructions: 'To read our frequently asked questions, please click here:',\n                button: {\n                    text: 'Read our FAQ',\n                    link: 'https://mailgen.js/faq'\n                }\n            }\n        ]\n    }\n};\n```\n\nYou can enable a fallback link and instructions for action buttons in case e-mail clients don't render them properly. This can be achieved by setting `button.fallback` to `true`, or  by specifying custom fallback text as follows:\n```js\nvar email = {\n    body: {\n        action: [\n            {\n                instructions: 'To get started with Mailgen, please click here:',\n                button: {\n                    color: '#22BC66',\n                    text: 'Confirm your account',\n                    link: 'https://mailgen.js/confirm?s=d9729feb74992cc3482b350163a1a010',\n                    fallback: true\n                }\n            },\n            {\n                instructions: 'To read our frequently asked questions, please click here:',\n                button: {\n                    text: 'Read our FAQ',\n                    link: 'https://mailgen.js/faq',\n                    fallback: {\n                        text: 'This is my custom text for fallback'\n                    }\n                }\n            }\n        ]\n    }\n};\n```\n\n### Table\n\nTo inject a table into the e-mail, supply the `table` object as follows:\n\n```js\nvar email = {\n    body: {\n        table: {\n            data: [\n                {\n                    item: 'Node.js',\n                    description: 'Event-driven I/O server-side JavaScript environment based on V8.',\n                    price: '$10.99'\n                },\n                {\n                    item: 'Mailgen',\n                    description: 'Programmatically create beautiful e-mails using plain old JavaScript.',\n                    price: '$1.99'\n                }\n            ],\n            columns: {\n                // Optionally, customize the column widths\n                customWidth: {\n                    item: '20%',\n                    price: '15%'\n                },\n                // Optionally, change column text alignment\n                customAlignment: {\n                    price: 'right'\n                }\n            }\n        }\n    }\n};\n```\n\nTo inject multiple tables into the e-mail, supply the `table` property with an array of objects as follows:\n\n```js\nvar email = {\n    body: {\n        table: [\n            {\n                // Optionally, add a title to each table.\n                title: 'Order 1',\n                data: [\n                    {\n                        item: 'Item 1',\n                        description: 'Item 1 description',\n                        price: '$1.99'\n                    },\n                    {\n                        item: 'Item 2',\n                        description: 'Item 2 description',\n                        price: '$2.99'\n                    }\n                ],\n                columns: {\n                    // Optionally, customize the column widths\n                    customWidth: {\n                        item: '20%',\n                        price: '15%'\n                    },\n                    // Optionally, change column text alignment\n                    customAlignment: {\n                        price: 'right'\n                    }\n                }\n            },\n            {\n                // Optionally, add a title to each table.\n                title: 'Order 2',\n                data: [\n                    {\n                        item: 'Item 1',\n                        description: 'Item 1 description',\n                        price: '$2.99'\n                    },\n                    {\n                        item: 'Item 2',\n                        description: 'Item 2 description',\n                        price: '$1.99'\n                    }\n                ],\n                columns: {\n                    // Optionally, customize the column widths\n                    customWidth: {\n                        item: '20%',\n                        price: '15%'\n                    },\n                    // Optionally, change column text alignment\n                    customAlignment: {\n                        price: 'right'\n                    }\n                }\n            }\n        ]\n    }\n};\n```\n\n\u003e Note: Tables are currently not supported in plaintext versions of e-mails.\n\n### Dictionary\n\n To inject key-value pairs of data into the e-mail, supply the `dictionary` object as follows:\n\n ```js\nvar email = {\n    body: {\n        dictionary: {\n            date: 'June 11th, 2016',\n            address: '123 Park Avenue, Miami, Florida'\n        }\n    }\n};\n```\n\n## Go-To Actions\n\nYou can make use of Gmail's [Go-To Actions](https://developers.google.com/gmail/markup/reference/go-to-action) within your e-mails by suppling the `goToAction` object as follows:\n\n```js\nvar email = {\n    body: {\n        // Optionally configure a Go-To Action button\n        goToAction: {\n            text: 'Go to Dashboard',\n            link: 'https://mailgen.com/confirm?s=d9729feb74992cc3482b350163a1a010',\n            description: 'Check the status of your order in your dashboard'\n        }\n    }\n};\n```\n\n\u003e Note that you need to [get your sender address whitelisted](https://developers.google.com/gmail/markup/registering-with-google) before your Go-To Actions will show up in Gmail.\n\n## Troubleshooting\n\n1. After sending multiple e-mails to the same Gmail / Inbox address, they become grouped and truncated since they contain similar text, breaking the responsive e-mail layout.\n\n\u003e Simply sending the `X-Entity-Ref-ID` header with your e-mails will prevent grouping / truncation.\n\n## Contributing\n\nThanks so much for wanting to help! We really appreciate it.\n\n* Have an idea for a new feature?\n* Want to add a new built-in theme?\n\nExcellent! You've come to the right place.\n\n1. If you find a bug or wish to suggest a new feature, please create an issue first\n2. Make sure your code \u0026 comment conventions are in-line with the project's style\n3. Make your commits and PRs as tiny as possible - one feature or bugfix at a time\n4. Write detailed commit messages, in-line with the project's commit naming conventions\n\n\u003e Check out [THEME.md](THEME.md) if you want to add a new built-in theme to Mailgen.\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feladnava%2Fmailgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feladnava%2Fmailgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feladnava%2Fmailgen/lists"}