Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodemailer发送邮件 #46

Open
AlexZ33 opened this issue May 19, 2021 · 0 comments
Open

nodemailer发送邮件 #46

AlexZ33 opened this issue May 19, 2021 · 0 comments

Comments

@AlexZ33
Copy link
Member

AlexZ33 commented May 19, 2021


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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant