服务器centos中的Nodemailer,电子邮件发送但不接收

Nodemailer in server centos,email send but not receive

我在centos服务器上有一个代码,有一个使用nodemailer发送电子邮件的代码,响应是200但没有收到电子邮件

这是我的代码

var transporter = nodemailer.createTransport({
  host: "smtp.gmail.com",
  port: 465,
  secure: true,
  auth: {
    user: 'xxx@gmail.com',
   pass: 'xxx'
  }
});

var mailOptions = {
  from: 'xxxgmail.com',
  to: email,
  subject: 'Blablabla',
  // text: 'That was easy!'
  html: html_export,
  attachments: [
   { // utf-8 string as an attachment
      filename: 'logo.png',
      path: path_logo,
      cid: 'unique@kreata.ee'
    },
    { // binary buffer as an attachment
      filename: 'logo.pdf',
      path: 'uploads/' + outpath
    }
  ]
};

transporter.sendMail(mailOptions, (err, info) => {
  if (err) {
    return res.send({ status: 404, message: 'Send Email Failed' });
  } else {
    return res.send({ status: 200, message: 'Send Email Success' });
  }
});

试试这个:

import * as nodemailer from 'nodemailer';

export const sendEmail = async () => {
  const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
      user: your_email,
      pass: your_password
    }
  });
  const mailContent = {
    from: '"johndoe.com" <johndoe@gmail.com>', // sender address
    to: some.email@gmail.com, // list of receivers
    subject: 'subject', // Subject line
    text: '', // plain text body
    html: `
    <html>
      <body style="text-align: center;">
       <p>some text</p>
      </body>
    </html>` // html body
  };

  // send mail with defined transport object
  try {
    const info = await transporter.sendMail(mailContent);
    console.log('Message sent: %s', info.messageId);
    console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  } catch (err) {
    console.log(err);
  }
};

这段代码不久前对我有效....