{"id":23602799,"url":"https://github.com/lzwme/node-exchange-mailer","last_synced_at":"2025-05-08T21:49:08.337Z","repository":{"id":71816393,"uuid":"329858909","full_name":"lzwme/node-exchange-mailer","owner":"lzwme","description":"基于 node-ews 封装的 EWS 邮件发送 API 方法。","archived":false,"fork":false,"pushed_at":"2024-07-30T07:19:48.000Z","size":50,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T22:08:49.012Z","etag":null,"topics":["ews","ews-api","exchange","mailer","nodemailer","send","sendmail"],"latest_commit_sha":null,"homepage":"https://lzw.me/a/nodejs-stmp-exchange-email-send.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lzwme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","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":"2021-01-15T08:55:33.000Z","updated_at":"2025-03-31T01:29:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"f371277c-0616-4ab7-88a8-b6e46cc9803d","html_url":"https://github.com/lzwme/node-exchange-mailer","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"fccda68978cdf07739cc9ae3c69f3b315c325b5e"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fnode-exchange-mailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fnode-exchange-mailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fnode-exchange-mailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lzwme%2Fnode-exchange-mailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lzwme","download_url":"https://codeload.github.com/lzwme/node-exchange-mailer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252392506,"owners_count":21740523,"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":["ews","ews-api","exchange","mailer","nodemailer","send","sendmail"],"created_at":"2024-12-27T12:13:18.657Z","updated_at":"2025-05-08T21:49:08.308Z","avatar_url":"https://github.com/lzwme.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Code Climate](https://lzw.me/images/logo.png)](https://lzw.me)\n[![@lzwme/node-exchange-mailer](https://nodei.co/npm/@lzwme/node-exchange-mailer.png)][npm-url]\n\n# node-exchange-mailer\n\n[![NPM version][npm-badge]][npm-url]\n[![node version][node-badge]][node-url]\n[![npm download][download-badge]][download-url]\n[![GitHub issues][issues-badge]][issues-url]\n[![GitHub forks][forks-badge]][forks-url]\n[![GitHub stars][stars-badge]][stars-url]\n[![minzipped size][bundlephobia-badge]][bundlephobia-url]\n\n使用 nodejs 发送基于 EWS(Microsoft Exchange Web Serveice) 邮件服务的邮件。\n\n基于 `node-ews` 封装的 EWS 邮件发送 API 方法。\n\n## 安装\n\n```bash\n# use npm\nnpm add @lzwme/node-exchange-mailer\n# or use yarn\nyarn add @lzwme/node-exchange-mailer\n```\n\n## 使用示例\n\n### 1. 示例一：使用账号和密码发送邮件\n\n```js\nconst { sendMailByEws } = require('@lzwme/node-exchange-mailer');\n\nconst options = {\n  subject: '[ews]邮件主题测试',\n  html: 'HTML 格式内容，\u003cb\u003e优先级高于 text\u003c/b\u003e',\n  /** TEXT 文本格式邮件正文内容(优先级低于 html 参数) */\n  text: 'text',\n  /** 收件人列表 */\n  to: 'xa@lzw.me',\n  /** 抄送人列表 */\n  cc: 'xb@lzw.me, xc@lzw.me',\n  /** 密送人列表 */\n  bcc: 'xd@lzw.me, xe@lzw.me',\n  // text: '纯文本格式内容',\n  ewsConfig: {\n    username: 'myuser@lzw.me',\n    password: 'mypassword',\n    host: 'https://ews.lzw.me',\n  },\n};\nsendMailByEws(options).then((result) =\u003e console.log(result));\n```\n\n### 2. 示例二：使用 `ntlm` 授权模式发送邮件，避免明文密码被直接泄漏\n\n根据明文密码生成 `ntlm` 认证模式所需的密钥：\n\n```js\nconst { genNtlmHashedPwd } = require('@lzwme/node-exchange-mailer');\n\nconst password = 'mypassword'; // process.argv.slice(2)[0];\nconst { nt_password, lm_password } = genNtlmHashedPwd(password, true);\n// =\u003e password: mypassword\n// =\u003e nt_password: a991ae45aa987a1a48c8bdc1209ff0e7\n// =\u003e lm_password: 74ac99ca40ded420dc1a73e6cea67ec5\n```\n\n配置 `nt_password` 和 `lm_password` 字段，基于 ntlm 认证模式发送邮件：\n\n```js\nconst { sendMailByEws } = require('@lzwme/node-exchange-mailer');\n\nconst options = {\n  subject: '[ews]邮件 ntlm 测试',\n  to: 'xa@lzw.me',\n  html: 'HTML 格式内容，\u003cb\u003e优先级高于 text\u003c/b\u003e',\n  ewsConfig: {\n    host: 'https://ews.lzw.me',\n    username: 'myuser@lzw.me',\n    /** 密码加密后的秘钥(NTLMAuth.nt_password)。为字符串时，应为 hex 编码结果 */\n    nt_password: 'a991ae45aa987a1a48c8bdc1209ff0e7',\n    /** 密码加密后的秘钥(NTLMAuth.lm_password)。为字符串时，应为 hex 编码结果 */\n    lm_password: '74ac99ca40ded420dc1a73e6cea67ec5',\n  },\n};\n\nsendMailByEws(options).then((result) =\u003e console.log(result));\n```\n\n### 示例三：发送带附件的邮件\n\n```js\nconst { sendMailByEws } = require('@lzwme/node-exchange-mailer');\nconst path = require('path');\n\nconst options = {\n  subject: '[ews]邮件附件测试',\n  html: [\n    `HTML 格式内容，\u003cb\u003e包含附件\u003c/b\u003e: \u003ca href=\"https://lzw.me\"\u003ehttps://lzw.me\u003c/a\u003e`,\n    `\u003cimg src='cid:png01' style='width:144px;height:auto'\u003e`,\n  ].join('\u003cbr\u003e'),\n  to: 'xa@lzw.me',\n  ewsConfig: {\n    host: 'https://ews.lzw.me',\n    username: 'myuser@lzw.me',\n    nt_password: 'a991ae45aa987a1a48c8bdc1209ff0e7',\n    lm_password: '74ac99ca40ded420dc1a73e6cea67ec5',\n  },\n  soapHeader: {\n    't:RequestServerVersion': {\n      attributes: {\n        Version: 'Exchange2013_SP1', // Exchange2007\u003c_SP1\u003e, Exchange2010\u003c_SP1\u003e, , Exchange2013\u003c_SP1\u003e\n      },\n    },\n  },\n  /**\n   * 附件列表\n   * {@link https://github.com/CumberlandGroup/node-ews/issues/40 | 发送附件参考 }\n   */\n  attachments: [\n    {\n      /** 附件名称 */\n      Name: 'lzw.me.txt',\n      /** 附件类型(如文本： text/plain) */\n      ContentType: 'text/plain',\n      /** 附件内容(请使用 base64 编码) */\n      Content: 'ZmlsZSBhdHRhY2htZW50LiAtIHRlc3QgYnkgaHR0cHM6Ly9sencubWU=',\n      IsInline: false,\n    },\n    {\n      /** 附件名称 */\n      Name: 'lzwme.png',\n      /** 附件类型(如文本： text/plain) */\n      ContentType: 'image/png',\n      /** 附件内容(使用 base64 编码) */\n      Content: readFileSync(path.resolve(__dirname, './lzwme-144x144.png'), {\n        encoding: 'base64',\n      }),\n      IsContactPhoto: false,\n      IsInline: true,\n      ContentId: 'png01',\n    },\n  ],\n};\n\nsendMailByEws(options).then((result) =\u003e console.log(result));\n```\n\n### 示例四：发送 smtp 协议的邮件\n\n本仓库基于 `nodemailer` 简单封装了一个 smtp 协议发送邮件的方法。用法如下：\n\n安装 `nodemailer` 依赖：\n\n```bash\nyarn add nodemailer\n```\n\n发送 smtp 协议的邮件示例：\n\n```js\nconst { sendMailBySmtp } = require('@lzwme/node-exchange-mailer');\nconst path = require('path');\n\nconst options = {\n  subject: '[smtp]Subject for test',\n  /** HTML 格式邮件正文内容 */\n  html: [\n    `email content for test: \u003ca href=\"https://lzw.me\"\u003ehttps://lzw.me\u003c/a\u003e`,\n    `\u003cimg src='cid:png01' style='width:144px;height:auto'\u003e`,\n  ].join('\u003cbr\u003e'),\n  /** TEXT 文本格式邮件正文内容 */\n  text: '',\n  to: 'l@lzw.me',\n  /** 附件列表 */\n  attachments: [\n    {\n      filename: 'lzwme.png',\n      cid: 'png01',\n      path: path.resolve(__dirname, 'lzwme-144x144.png'),\n    },\n    {\n      filename: 'lzwme.txt',\n      content: '邮件内容，test by \u003cb\u003elzw.me\u003c/b\u003e',\n    },\n  ],\n};\nconst smtpConfig = {\n  // service: 'qq',\n  host: 'smtp.qq.com', // QQ: smtp.qq.com; 网易: smtp.163.com\n  port: 465, // 端口号。QQ邮箱  465，网易邮箱 25\n  secure: true,\n  auth: {\n    user: 'xxx@qq.com', // 邮箱账号\n    pass: 'xxxxxx', // 邮箱的授权码\n  },\n};\nsendMailBySmtp(options, smtpConfig).then((result) =\u003e console.log(result));\n```\n\n## 扩展参考\n\n- [使用 node.js 发送基于 STMP 与 MS Exchange 邮件的方法](https://lzw.me/a/nodejs-stmp-exchange-email-send.html)\n- [EWS reference for Exchange](https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/ews-reference-for-exchange)\n- [createitem-operation-email-message](https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem-operation-email-message)\n\n## License\n\n`@lzwme/node-exchange-mailer` is released under the MIT license.\n\n该插件由[志文工作室](https://lzw.me)开发和维护。\n\n[stars-badge]: https://img.shields.io/github/stars/lzwme/node-exchange-mailer.svg\n[stars-url]: https://github.com/lzwme/node-exchange-mailer/stargazers\n[forks-badge]: https://img.shields.io/github/forks/lzwme/node-exchange-mailer.svg\n[forks-url]: https://github.com/lzwme/node-exchange-mailer/network\n[issues-badge]: https://img.shields.io/github/issues/lzwme/node-exchange-mailer.svg\n[issues-url]: https://github.com/lzwme/node-exchange-mailer/issues\n[npm-badge]: https://img.shields.io/npm/v/@lzwme/node-exchange-mailer.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@lzwme/node-exchange-mailer\n[node-badge]: https://img.shields.io/badge/node.js-%3E=_10.0.0-green.svg?style=flat-square\n[node-url]: https://nodejs.org/download/\n[download-badge]: https://img.shields.io/npm/dm/@lzwme/node-exchange-mailer.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@lzwme/node-exchange-mailer\n[bundlephobia-url]: https://bundlephobia.com/result?p=@lzwme/node-exchange-mailer@latest\n[bundlephobia-badge]: https://badgen.net/bundlephobia/minzip/@lzwme/node-exchange-mailer@latest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flzwme%2Fnode-exchange-mailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flzwme%2Fnode-exchange-mailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flzwme%2Fnode-exchange-mailer/lists"}