npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lzwme/node-exchange-mailer

v1.1.0

Published

使用 nodejs 发送基于 EWS(Microsoft Exchange Web Serveice) 邮件服务的邮件。

Downloads

7

Readme

Code Climate @lzwme/node-exchange-mailer

node-exchange-mailer

NPM version node version npm download GitHub issues GitHub forks GitHub stars minzipped size

使用 nodejs 发送基于 EWS(Microsoft Exchange Web Serveice) 邮件服务的邮件。

基于 node-ews 封装的 EWS 邮件发送 API 方法。

安装

# use npm
npm add @lzwme/node-exchange-mailer
# or use yarn
yarn add @lzwme/node-exchange-mailer

使用示例

1. 示例一:使用账号和密码发送邮件

const { sendMailByEws } = require('@lzwme/node-exchange-mailer');

const options = {
  subject: '[ews]邮件主题测试',
  html: 'HTML 格式内容,<b>优先级高于 text</b>',
  /** TEXT 文本格式邮件正文内容(优先级低于 html 参数) */
  text: 'text',
  /** 收件人列表 */
  to: '[email protected]',
  /** 抄送人列表 */
  cc: '[email protected], [email protected]',
  /** 密送人列表 */
  bcc: '[email protected], [email protected]',
  // text: '纯文本格式内容',
  ewsConfig: {
    username: '[email protected]',
    password: 'mypassword',
    host: 'https://ews.lzw.me',
  },
};
sendMailByEws(options).then((result) => console.log(result));

2. 示例二:使用 ntlm 授权模式发送邮件,避免明文密码被直接泄漏

根据明文密码生成 ntlm 认证模式所需的密钥:

const { genNtlmHashedPwd } = require('@lzwme/node-exchange-mailer');

const password = 'mypassword'; // process.argv.slice(2)[0];
const { nt_password, lm_password } = genNtlmHashedPwd(password, true);
// => password: mypassword
// => nt_password: a991ae45aa987a1a48c8bdc1209ff0e7
// => lm_password: 74ac99ca40ded420dc1a73e6cea67ec5

配置 nt_passwordlm_password 字段,基于 ntlm 认证模式发送邮件:

const { sendMailByEws } = require('@lzwme/node-exchange-mailer');

const options = {
  subject: '[ews]邮件 ntlm 测试',
  to: '[email protected]',
  html: 'HTML 格式内容,<b>优先级高于 text</b>',
  ewsConfig: {
    host: 'https://ews.lzw.me',
    username: '[email protected]',
    /** 密码加密后的秘钥(NTLMAuth.nt_password)。为字符串时,应为 hex 编码结果 */
    nt_password: 'a991ae45aa987a1a48c8bdc1209ff0e7',
    /** 密码加密后的秘钥(NTLMAuth.lm_password)。为字符串时,应为 hex 编码结果 */
    lm_password: '74ac99ca40ded420dc1a73e6cea67ec5',
  },
};

sendMailByEws(options).then((result) => console.log(result));

示例三:发送带附件的邮件

const { sendMailByEws } = require('@lzwme/node-exchange-mailer');
const path = require('path');

const options = {
  subject: '[ews]邮件附件测试',
  html: [
    `HTML 格式内容,<b>包含附件</b>: <a href="https://lzw.me">https://lzw.me</a>`,
    `<img src='cid:png01' style='width:144px;height:auto'>`,
  ].join('<br>'),
  to: '[email protected]',
  ewsConfig: {
    host: 'https://ews.lzw.me',
    username: '[email protected]',
    nt_password: 'a991ae45aa987a1a48c8bdc1209ff0e7',
    lm_password: '74ac99ca40ded420dc1a73e6cea67ec5',
  },
  soapHeader: {
    't:RequestServerVersion': {
      attributes: {
        Version: 'Exchange2013_SP1', // Exchange2007<_SP1>, Exchange2010<_SP1>, , Exchange2013<_SP1>
      },
    },
  },
  /**
   * 附件列表
   * {@link https://github.com/CumberlandGroup/node-ews/issues/40 | 发送附件参考 }
   */
  attachments: [
    {
      /** 附件名称 */
      Name: 'lzw.me.txt',
      /** 附件类型(如文本: text/plain) */
      ContentType: 'text/plain',
      /** 附件内容(请使用 base64 编码) */
      Content: 'ZmlsZSBhdHRhY2htZW50LiAtIHRlc3QgYnkgaHR0cHM6Ly9sencubWU=',
      IsInline: false,
    },
    {
      /** 附件名称 */
      Name: 'lzwme.png',
      /** 附件类型(如文本: text/plain) */
      ContentType: 'image/png',
      /** 附件内容(使用 base64 编码) */
      Content: readFileSync(path.resolve(__dirname, './lzwme-144x144.png'), {
        encoding: 'base64',
      }),
      IsContactPhoto: false,
      IsInline: true,
      ContentId: 'png01',
    },
  ],
};

sendMailByEws(options).then((result) => console.log(result));

示例四:发送 smtp 协议的邮件

本仓库基于 nodemailer 简单封装了一个 smtp 协议发送邮件的方法。用法如下:

安装 nodemailer 依赖:

yarn add nodemailer

发送 smtp 协议的邮件示例:

const { sendMailBySmtp } = require('@lzwme/node-exchange-mailer');
const path = require('path');

const options = {
  subject: '[smtp]Subject for test',
  /** HTML 格式邮件正文内容 */
  html: [
    `email content for test: <a href="https://lzw.me">https://lzw.me</a>`,
    `<img src='cid:png01' style='width:144px;height:auto'>`,
  ].join('<br>'),
  /** TEXT 文本格式邮件正文内容 */
  text: '',
  to: '[email protected]',
  /** 附件列表 */
  attachments: [
    {
      filename: 'lzwme.png',
      cid: 'png01',
      path: path.resolve(__dirname, 'lzwme-144x144.png'),
    },
    {
      filename: 'lzwme.txt',
      content: '邮件内容,test by <b>lzw.me</b>',
    },
  ],
};
const smtpConfig = {
  // service: 'qq',
  host: 'smtp.qq.com', // QQ: smtp.qq.com; 网易: smtp.163.com
  port: 465, // 端口号。QQ邮箱  465,网易邮箱 25
  secure: true,
  auth: {
    user: '[email protected]', // 邮箱账号
    pass: 'xxxxxx', // 邮箱的授权码
  },
};
sendMailBySmtp(options, smtpConfig).then((result) => console.log(result));

扩展参考

License

@lzwme/node-exchange-mailer is released under the MIT license.

该插件由志文工作室开发和维护。