{"id":19123093,"url":"https://github.com/digitalbazaar/bedrock-mail","last_synced_at":"2025-05-05T18:30:03.264Z","repository":{"id":25778827,"uuid":"29217207","full_name":"digitalbazaar/bedrock-mail","owner":"digitalbazaar","description":"Bedrock mail","archived":false,"fork":false,"pushed_at":"2024-10-15T20:37:04.000Z","size":95,"stargazers_count":2,"open_issues_count":4,"forks_count":2,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-15T06:16:54.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-13T23:35:08.000Z","updated_at":"2024-10-15T20:37:08.000Z","dependencies_parsed_at":"2022-08-24T14:14:23.652Z","dependency_job_id":null,"html_url":"https://github.com/digitalbazaar/bedrock-mail","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fbedrock-mail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fbedrock-mail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fbedrock-mail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fbedrock-mail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/bedrock-mail/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252552815,"owners_count":21766774,"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-11-09T05:24:19.160Z","updated_at":"2025-05-05T18:30:03.241Z","avatar_url":"https://github.com/digitalbazaar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bedrock-mail\n\nA [Bedrock][] module that allows you to send automated, template-based emails\nin response to events. Data used in the templates comes from both data in the\nevents and from \"triggers\" that are run to load data for the event. Templates\ncan be written in any language supported by [email-templates][].\n\n## Requirements\n\n- An available [nodemailer][] transport (SMTP, AWS SES, etc).\n\n## Quick Examples\n\n```\nnpm install bedrock-mail\n```\n\n```js\nconst bedrock = require('bedrock');\nconst brMail = require('bedrock-mail');\nconst {config} = bedrock;\n\n// configure default mail behavior\n// defaults to send if NODE_ENV is 'production'\n//config.mail.send = true;\n// defaults for every message\nconfig.mail.message = {\n  from: 'My Company Support \u003csupport@example.com\u003e'\n};\n\n// setup SMTP transport\nbedrock.config.mail.transport = {\n  type: 'smtp',\n  options: {\n    host: 'mail.example.com'\n  },\n  verify: true\n};\n\n// setup default template locals for all mails\nbedrock.config.mail.locals.service = {\n  name: 'My Service',\n  url: 'https://example.com/'\n};\n\n// schedule generic event\nbedrock.events.emitLater({\n  type: 'myModule.myEvent',\n  details: {\n    accountId: 1234,\n    image: 'https://example.com/images/2020-01-01.png'\n  }\n});\n\n// handle generic even and send email\nbedrock.events.on('myModule.myEvent', async event =\u003e {\n  const account = await getAccount(event.accountId);\n  brMail.send({\n    template: 'myModule.myEvent',\n    message: {\n      to: account.email\n    },\n    locals: {\n      image: event.image\n    }\n  });\n});\n```\n\nExample [EJS][] subject template `events/myModule.myEvent/subject.ejs`:\n```ejs\nHere's your daily image from \u003c%= service.name %\u003e!\n```\n\nExample [EJS][] html template `events/myModule.myEvent/html.ejs`:\n```ejs\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cp\u003eHello \u003c%= account.name %\u003e,\u003c/p\u003e\n    \u003cp\u003eHere's your daily image:\u003c/p\u003e\n    \u003cp\u003e\u003cimg src=\"\u003c%= image %\u003e\"\u003e\u003c/p\u003e\n    \u003chr/\u003e\n    \u003cp\u003e\u003ca href=\"\u003c%= service.url %\u003e\"\u003e\u003c%= service.name %\u003e\u003c/a\u003e\u003c/p\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nExample [EJS][] text template if the auto-generated one from HTML is not\nsufficient `events/myModule.myEvent/text.ejs`:\n```ejs\nHello \u003c%= account.name %\u003e,\n\nHere's a link to your daily image:\n\u003c%= image %\u003e\n\n-- \n\u003c%= service.name %\u003e\n\u003c%= service.url %\u003e\n```\n\nThis template depends on the `service` object and properties to be setup on a\nglobal level. See the [nodemailer][] docs if you want to add attachments,\nembedded images, or use other features.\n\n[EJS][] includes work with file paths relative to the template. For example,\nthe text template `example` that includes a text footer:\n\n`example/text.ejs`:\n```ejs\nWelcome to our service!\n\n\u003c%- include('../common/footer.text.ejs') %\u003e\n```\n\n`common/footer.text.ejs`:\n```ejs\n-- \nExample Service\nhttps://example.com/\n```\n\nSee the [test](./test) directory for a full example.\n\n## Configuration\n\nFor documentation on configuration, see [config.js](./lib/config.js), the\nexample above, the [test](./test) example, and the [nodemailer][] and\n[email-templates][] documentation.\n\n## API\n\n### async use('transport', transport)\n\nConfigure at runtime to use a specific transport configuration. Transport is\nthe same format as `bedrock.config.mail.transport`.\n\n### async verify()\n\nCall the transport `verify()` method, if supported. See the [nodemailer][]\ndocumentation. Useful to check a SMTP connection works.\n\n### async send({template, message, locals})\n\nSend mail using a specific template (name or path), message options, and local\nvars.\n\n```js\nawait brMail.send('my-template', {to: 'someone@example.com'}, {foo: 'bar'});\n```\n\n## Testing\n\nThe [test](./test) directory example tool can be used to test transports and\ntemplates.\n\n## CLI Overrides\n\nThis library adds global CLI options that can be useful during development to\noverride config values.  Boolean options are case-insensitve: `default`,\n`false`, `f`, `0`, `true`, `t`, `1`.\n\n- `--mail-to ADDRESS`: Override mail target address for **all** emails.\n- `--mail-preview BOOLEAN`: Override previewing mail mode.\n- `--mail-send BOOLEAN`: Override sending mail mode.\n- `--mail-log BOOLEAN`: Override logging mode to print headers and text body.\n\n[Bedrock]: https://github.com/digitalbazaar/bedrock\n[EJS]: https://ejs.co/\n[email-templates]: https://email-templates.js.org/\n[nodemailer]: https://nodemailer.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fbedrock-mail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fbedrock-mail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fbedrock-mail/lists"}