pxl-for-emails icon indicating copy to clipboard operation
pxl-for-emails copied to clipboard

{ TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object at validChunk

Open rahulsavsani opened this issue 6 years ago • 7 comments

var nodemailer = require('nodemailer');
var csv = require('csv');
var fs = require('fs');
let Pxl = require('pxl-mongodb');
let express = require('express');
let PxlMongodb = require('pxl-mongodb')
let msg = '<img src = "https://drive.google.com/file/d/1cToTGU25lbKG2yX9Bmhew6tM9vZYLOxP/view?usp=sharing" /> Hey man'


let pxl = new Pxl();
pxl.connect('mongodb://......', {})

let app = express()
 
app.use(pxl.trackPxl)
app.get('/shortly/:linkId', pxl.redirect)
let PxlForEmails = require('pxl-for-emails')
 
let pxlForEmails = new PxlForEmails({
    pxl,
    getFullShortenedLink(linkId) {
        return `https://localhost:3000/shortly/${ linkId }`
    }
})


    let newmsg = pxlForEmails.addTracking(msg, {recipient: "[email protected]"})
    


var mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Do you need a professional Website for your business?',
    html: newmsg
};


var transporter = nodemailer.createTransport({
    service: 'gmail',
    auth:{
        user: '[email protected]',
        pass: 'xxxx'
    }
});


        
transporter.sendMail(mailOptions,function(error,info){
            if(error){
                console.log(error);
            }
            else{
                console.log('Email sent : ' + info.response);
            }
        });

Error log:

{ TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object
    at validChunk (_stream_writable.js:258:10)
    at PassThrough.Writable.write (_stream_writable.js:292:21)
    at PassThrough.Writable.end (_stream_writable.js:579:10)
    at Immediate.setImmediate [as _onImmediate] (D:\Marketing\Mailer\node_modules\nodemailer\lib\mime-node\index.js:978:46)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5) code: 'ESTREAM', command: 'API' }

It gets connected to the database but not updating the database. I think I'm having trouble with 'addTracking' method. Any kind of help will be appreciated. Thank you.

rahulsavsani avatar Oct 31 '19 18:10 rahulsavsani

same issue

sfajer avatar Apr 15 '20 01:04 sfajer

I have the same issue. Have you found a solution?

dunawayk avatar May 27 '20 04:05 dunawayk

Hi guys, I got it solved by adding an await in front of addTracking:

let newmsg = await pxlForEmails.addTracking(msg, {recipient: "[email protected]"});

var mailOptions = {
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Do you need a professional Website for your business?',
    html: newmsg
};
...

mryraghi avatar Jul 29 '20 15:07 mryraghi

Even after adding await, I still get the error TypeError: this.options.pxl.createPxl is not a function. Any suggestions ?

BasselFouad avatar Jul 24 '21 10:07 BasselFouad

@BasselFouad I assume your setup is not correct. Please check the Usage section in the readme again. Your error seems to be caused by passing something incorrect as the pxl parameter to the PxlForEmails constructor.

analog-nico avatar Jul 24 '21 15:07 analog-nico

Yes thank you I have now fixed my error and am successfully sending emails. However, nothing is happening in my database in terms of tracking the sent emails, my email markup is a string of html, and I am then using this : html = await pxlForEmails.addTracking(html,{ recipient: req.body.recipients[i].email }) It is worth noting that my clicks on buttons are redirecting correctly.

BasselFouad avatar Jul 24 '21 17:07 BasselFouad

@BasselFouad Please double check the Usage section in the readme to verify that you did all setup steps. For starters, check that your emails contain the pxl=... additions and that external links are shortened. If you face further hurdles, please open a separate issue for that since this doesn’t belong into this issue here anymore. Thanks!

analog-nico avatar Jul 29 '21 08:07 analog-nico