Muhammad Danish
Muhammad Danish

Reputation: 335

Sending email by using maildrill

I am trying to send email through maildrillapp but unable to send. I install related packages and take this code from Here.

My Code for app.js is:

var nodemailer = require("nodemailer");
var mandrillTransport = require('nodemailer-mandrill-transport');

/*
* Configuring mandrill transport.
* Copy your API key here.
*/

var smtpTransport = nodemailer.createTransport(mandrillTransport({
    auth: {
      apiKey : 'xxxxxxxxxxxxxxxxxxx'
    }
}));

// Put in email details.

let mailOptions={
   from : '[email protected]',
   to : '[email protected]',
   subject : "This is from Mandrill",
   html : "Hello,<br>Sending this email using Node and Mandrill"
};

// Sending email.
smtpTransport.sendMail(mailData,function(error, response){
  if(error) {
     throw new Error("Error in sending email");
  }
  console.log("Message sent: " + JSON.stringify(response));
});

when I run this it throws following error

'C:\office\new 3\maildrill\app.js:23 smtpTransport.sendMail(mailData,function(error, response){ ^

ReferenceError: mailData is not defined at Object. (C:\office\new 3\maildrill\app.js:23:24) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Function.Module.runMain (module.js:694:10) at startup (bootstrap_node.js:204:16) at bootstrap_node.js:625:3 PS C:\office\new 3\maildrill>'

Upvotes: 1

Views: 403

Answers (2)

Dave Compton
Dave Compton

Reputation: 11

I know this is old, but I found the same issue using the same example I found online so am posting an answer for general reference.
The problem is that the author defines 'mailOptions' but references it as 'mailData' instead. I'm guessing they decided to rename the variable but only did half the job!

Update the sendMail command accordingly and it'll work.

smtpTransport.sendMail(mailOptions,function(error, response){

Upvotes: 1

Malik Asad
Malik Asad

Reputation: 461

Here is the some demo for sending emails with nodemailer nodemailer

Upvotes: 1

Related Questions