Skip to content

nodemailer发送邮件 #46

Description

@AlexZ33

mport nodemailer from 'nodemailer';
 
const sender = {
  user: 'xxx', // 发送者的邮箱地址
  pass: 'xxx', // 发送者的邮箱密码或smtp授权码(qq邮箱要求)
};
const receiver = 'xxx'; // 接受者的邮箱地址
 
const smtpConfig = {
  host: 'smtp.qq.com', // 根据所用服务填写
  port: 465,
  secure: true, // use SSL
  auth: {
    user: sender.user,
    pass: sender.pass,
  },
};
 
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport(smtpConfig);
 
// setup e-mail data with unicode symbols
const mailOptions = {
  from: sender.user, // sender name
  to: receiver, // list of receivers
  subject: 'xxx', // Subject line
  text: '', // plaintext body
  html: '', // html body
};
 
function sendMail(options) {
  return new Promise((resolve, reject) => {
    transporter.sendMail(Object.assign({}, mailOptions, options), (error, info) => {
      if (error) {
        reject(error);
      } else {
        resolve(info.response);
      }
    });
  });
}
 
export default sendMail;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions