Gmail-dan foydalangan holda Nodemailer, "SMTP" satrida 'mailer' xususiyatini yaratib bo'lmadi

Men har doim bir xil xatolikka ega bo'lgan sumbit tugmasini bosgandan so'ng, men yaratgan formani o'zimning gmail hisobimga jo'natishga harakat qilaman. Nodemailer haqida ko'plab savollarni topdim, ammo ularning hech biri men yashayotganim bilan bir xil muammo kabi ko'rinadi.

Ofcourse Men clientId deb yozgan edim, lekin bu xabar uchun faqat o'chirildi.

TypeError: Cannot create property 'mailer' on string 'SMTP'
at Mail (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\nodemailer\lib\mailer\index.js:45:33)
   at Object.module.exports.createTransport (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\nodemailer\lib\nodemailer.js:46:14)
   at C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\src\app.js:39:26
   at Layer.handle [as handle_request] (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\layer.js:95:5)
   at next (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\route.js:131:13)
   at Route.dispatch (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\route.js:112:3)
   at Layer.handle [as handle_request] (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\layer.js:95:5)
   at C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:277:22
   at Function.process_params (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:330:12)
   at next (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:271:10)
   at serveStatic (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\node_modules\serve-static\index.js:75:16)
   at Layer.handle [as handle_request] (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\layer.js:95:5)
   at trim_prefix (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:312:13)
   at C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:280:7
   at Function.process_params (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:330:12)
   at next (C:\Users\snowr\Documents\dev\zorgkaartnl\zorgkaartnl\node_modules\express\lib\router\index.js:271:10)

Bu mening app.js:

// require modules
const express = require('express');
const app = express();
const pug = require('pug');
const fs = require('fs')
const bodyParser = require('body-parser');
const pg = require('pg');
const nodemailer = require('nodemailer');
const xoauth2 = require('xoauth2');


//set view engine and views
app.set('views', 'src/views');
app.set('view engine', 'pug');

app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static('./resources/'));





//display index page
app.get('/', function ( req, res ){
  console.log('Index is displayed on localhost');
    res.render('index');
});

app.post('/zorginstelling/ziekenhuis-olvg-locatie-west-voorheen-sint-lucas-andreas-ziekenhuis-amsterdam-109428/waardeer', function (req, res) {
  var mailOpts, smtpTrans;
  console.log('form word gepost')
  //Setup Nodemailer transport, I chose gmail. 
  smtpTrans = nodemailer.createTransport('SMTP', {
      service: 'Gmail',
      auth: {
        xoauth2: xoauth2.createXOAuth2Generator({
            user: '[email protected]',
            clientId: '-' ,
            clientSecret: '-' ,
            refreshToken: '-'
        })
       }
  });

   //Mail options
  mailOpts = {
      from: req.body.rating[name] + ' <' + req.body.rating[email][first] + '>', 
      to: '[email protected]',
      subject: 'Test',
      text: req.body.rating[comment] + req.body.rating[questions][behandeling] + req.body.rating[name]
  };

    smtpTrans.sendMail(mailOpts, function (error, response) {
      //Email not sent
      if (error) {
          console.log('There was a problem')
      }
      //Yay!! Email sent
      else {
          console.log('Email sent!')
      }
  });
});



var server = app.listen(4000, function() {
        console.log('Example app listening on port: ' + server.address().port);
    });
11

6 javoblar

Nodemailer qayta ishlangan, shuning uchun eski kod tuzilishi bunday xatoni olib tashlashi mumkin. Quyidagi strukturadan foydalaning:

var xoauth2 = require('xoauth2');


smtpTrans = nodemailer.createTransport({
  service: 'Gmail', 
  auth: {
    xoauth2: xoauth2.createXOAuth2Generator({
        user: '[email protected]',
        //and other stuff

Iltimos, rasmiy tafsilotlarni tekshiring:

https://community.nodemailer.com/2-0-0 -beta/using-oauth2/

12
qo'shib qo'ydi
To'liq kod parchasini qo'sha olasizmi? Bundan tashqari, "boshqa narsalar" ni qaerdan olasiz? Rahmat.
qo'shib qo'ydi muallif user1063287, manba
Men xato qilyapman, iltimos uni @KylevanTil bilan hal qilishga yordam bering
qo'shib qo'ydi muallif iwayankit, manba
Buning sababi shundaki, siz gmail xavfsizlik parametrlarini tushirishingiz va mijozlar sozlamalarida "kamroq xavfsiz ilovalar uchun ruxsat berish" kerak. So'ngra sizning arizangiz smt protokoli orqali pochta qutingizga kira oladi. Ehtimol, bu auth masalalarni hal qilishning yana bir yo'li bor, ammo men ularni topa olmadim.
qo'shib qo'ydi muallif Alexander Rulezovsky, manba
Rahmat, bitta muammo hal qilindi, lekin men o'zimning foydalanuvchi nomim va parolimning yaroqsiz ekanligini aytib, muammoga duch kelgandan so'ng. Ammo endi hamma narsa kam kod bilan ishlaydi.
qo'shib qo'ydi muallif Kyle van Til, manba
Men buni allaqachon qildim, lekin mening kodim murakkab deb o'ylayman deb o'ylagandim.
qo'shib qo'ydi muallif Kyle van Til, manba

Mavjud muammo Bugungi kunda yordam uchun ma'lumotlarning tezroq o'zgarishi va Aleksandr "nodemailer reworked" deb aytganida yaxshi edi;

Transporterni aniqlash uchun ushbu qulay liniyadan foydalanaman:

    var smtpTransport = nodemailer.createTransport("smtps://youruser%40gmail.com:"+encodeURIComponent('yourpass#123') + "@smtp.gmail.com:465"); 

i got it from here https://community.nodemailer.com/

4
qo'shib qo'ydi

Menda shunga o'xshash muammo bor edi. "nodemailer-smtp-transport" moduli uni hal qildi

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transport = nodemailer.createTransport(smtpTransport({
    service: 'Gmail',
    auth:{
        xoauth2: xoauth2.createXOAuth2Generator({
            user: '[email protected]',
   //and other stuff

nmemailer-smtp-transportni 'npm install nodemailer-smtp-transport' yordamida o'rnatish

2
qo'shib qo'ydi

Quyidagilarni sinab ko'ring:

    smtpTrans = nodemailer.createTransport({
        service: 'Gmail', 
        auth: {
            type: 'OAuth2',
            user: '[email protected]',
           //and other stuff

See: https://nodemailer.com/smtp/oauth2/

1
qo'shib qo'ydi

Bu men uchun harakat qildi, iltimos, uni sinab ko'ring

function sendEmailTechnician() {
   //Generate test SMTP service account from gmail
    nodemailer.createTestAccount((err, account) => {
       //create reusable transporter object using the default SMTP transport
        let transporter = nodemailer.createTransport({
            host: 'smtp.gmail.com',
            port: 587,
            secure: false,//true for 465, false for other ports
            auth: {
                user: '',//generated gmail user
                pass: ''//generated gmail account password
            }
        });

       //setup email data with unicode symbols
        let mailOptions = {
            from: 'text ',//sender address
            to: '[email protected]',//list of receivers 
            subject: 'text',//Subject line
            text: 'text',//plain text body
            html: 'text'//html body
        };

       //send mail with defined transport object
        transporter.sendMail(mailOptions, (error, info) => {
            if (error) {
                return console.log(error);
            }
            console.log('Message sent: %s', info.messageId);
           //Preview only available when sending through an Ethereal account
            console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

           //Message sent: 
           //Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
        });
    });
}
1
qo'shib qo'ydi

Bu men uchun ishlaydi,

sendEmail: function(account, params) {

   //create reusable transporter object using the default SMTP transport
    var smtpTransport = nodemailer.createTransport({
        service: 'Gmail',//sets automatically host, port and connection security settings
        auth: {
            user: account.user, 
            pass: account.password  
        }
    });

    var toEmail = params.to[0];
    for (var i = 1; i < params.to.length; i++) {
        toEmail += ', ' + params.to[i];
    }

   //setup email data with unicode symbols
    var mailOptions = {
        from: params.from,//sender address
        to: toEmail,//list of receivers
        subject: params.subject,//Subject line
        text: params.text,//plain text body
        html: params.html,//html body
        attachments: params.attachments
    };

   //send mail with defined transport object
    smtpTransport.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log('Error while sending mail: ' + error);
        } else {
            console.log('Message sent: %s', info.messageId);
        }
        smtpTransport.close();//shut down the connection pool, no more messages.
    });
}

Google'dan kamroq xavfsiz ilovalarni yoqish kerakligini unutmang. https://myaccount.google.com/sizsecureapps ga tashrif buyuring. Bir marta yoqilgan bo'lsa, sahifani yangilang, faqat aslida yoqilganligiga ishonch hosil qilish uchun (men uni 4 ta harakatda ishga tushirganman).

0
qo'shib qo'ydi
NodeJS Uzbekistan
NodeJS Uzbekistan
152 ishtirokchilar

Guruh NodeJS bo'yicha muloqot qilish uchun ochilgan. Sizni qiziqtirsa: @nodejs_uz @react_uz @angular_uz @yiiframework_uz @js_uzb @typescript_uzb @vuejs_uz @ngTashkent @laravel_uz @uzdevgroup Ish o'rinlari @UzDev_jobs

Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb