将Webmail与Nodemailer一起使用

问题描述

我使用gmail和node mailer来在js节点中创建登录系统。 在开发模式下,我使用了gmail。

const sendEmail = async options =>{
//1)Create a transporter
// const transporter = nodemailer.createTransport({
    service: 'gmail',auth: {
         user: process.env.EMAIL_SEND_SESSION,pass: process.env.EMAIL_SEND_PASSWORD,}
});
//2) Define the mail options
const mailOptions = {
    from:'Creative Point <test764@gmail.com>',to:options.email,subject:options.subject,html:options.message
}
//3) Actually send the email
await transporter.sendMail(mailOptions);
};

但是在生产模式下,我想使用网络邮件,当我在cpanel上创建数据和端口帐户时收到。

const transporter = nodemailer.createTransport({
    service:'smtp.specialsoft.ro ',port: 465,auth: {
        user: process.env.EMAIL_SEND_SESSIONCPANEL,pass: process.env.EMAIL_SEND_PASSWORDCPANEL,}
});

但这给了我下一个错误

Error: There was an error sending the email.Try again later!Error: Invalid login: 535-5.7.8 Username 
and Password not accepted. Learn more at
 535 5.7.8  https://support.google.com/mail/?p=BadCredentials g20sm3266545ejz.88 - gsmtp
at C:\Users\Cosmin\Desktop\Authentification System  Node 
 JS,Express,JsonWebToken\controllers\sessionController.js:56:21
at processticksAndRejections (internal/process/task_queues.js:93:5)

我没有在互联网上找到与此错误相关的任何信息。

解决方法

我按照以下步骤解决了这个问题。

  1. 我安装了一个模块: nodemailer-smtp-transport

     const smtpTransport = require('nodemailer-smtp-transport');
    
  2. 我更正了主机名和一些选项。

    host:'mail.mydomani.ro'
    secureConnection: false,tls: {
       rejectUnauthorized: false
     }
    

3)我将模块 nodemailer-smtp-transport 集成到了运输机中。

 const transporter = nodemailer.createTransport(smtpTransport({
    host:'mail.mydomanin.ro',secureConnection: false,tls: {
      rejectUnauthorized: false
    },port: 587,auth: {
        user: process.env.EMAIL_SEND_SESSION,pass: process.env.EMAIL_SEND_PASSWORD,}
}));

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...