Error on console with Nodemailer : Uncaught TypeError: Cannot read property 'createTransport' of und

1,564 views
Skip to first unread message

mourad zamoun

unread,
Nov 22, 2014, 8:10:34 PM11/22/14
to meteo...@googlegroups.com
Hi All,

I am using mrt:meteor-nodemailer package to tryning to send email with attachement.

I adapt my code from this one :

var smtpTransport = nodemail.createTransport("SMTP", {
    service : "Gmail",
    maxConnections : 1,
    maxMessages : 1,
    auth : {
        user : "to...@gmail.com",
        pass : "mypass"
    }
});
function email(adresse, subject, content) {
 
    // setup e-mail data with unicode symbols
    var mailOptions = {
        from : "to...@gmail.com"// sender address
        to : adresse, // list of receivers
        subject : subject, // Subject line
        html : content // html body
    };
 
    // send mail with defined transport object
    smtpTransport.sendMail(mailOptions, function(error, response) {
        if (error) {
            console.log(error);
        else {
            console.log("Message sent: " + response.message);
        }
        smtpTransport.close();
    });
 
}


Th error on loading the page : Uncaught TypeError: Cannot read property 'createTransport' of undefined 

so what is the problem ?

See you soon; thank you :)


mourad zamoun

unread,
Nov 22, 2014, 8:13:06 PM11/22/14
to meteo...@googlegroups.com
before this code :
var nodemailer = Nodemailer;
console.log(nodemailer);

and the console print : undefined

!!???

Luca Mussi (@splendido)

unread,
Nov 24, 2014, 3:13:33 AM11/24/14
to meteo...@googlegroups.com
I've managed to use it via meteorhacks:npm which lets you specify which npm packages to require.

simply:

meteor add meteorhacks:npm
echo '{ "nodemailer": "1.3.0" }' > packages.json

then in the code:


            var mailOptions = {
                from: "Sender <in...@sender.com>",
                to: "em...@example.com",
                subject: " Some Results",
                text: 'Please find results in attachment.',
                html: '<b>Please find results in attachment.</b>',
                attachments: [
                    {   // utf-8 string as an attachment
                        filename: "results.txt",
                        content: "this is the content of the txt file",
                    },
                ],
            };

            var nodemailer = Meteor.npmRequire('nodemailer');
            var transporter = nodemailer.createTransport({
                host: "smtp.results.com",
                port: 587,
                auth: {
                    user: "sm...@results.com",
                    pass: "password",
                },
                tls: {
                    rejectUnauthorized:false
                }
            });
            transporter.sendMail(mailOptions, function(error, info){
                if (error)
                    throw new Meteor.Error("An error occured!", error);
            });


Hope this can help!
Reply all
Reply to author
Forward
0 new messages