Project Entry 5: Node.js Mailer — Project Weekly Progress Report

This week is Week 5, let’s make our contact form work!!

It is Week 5, we already finished creating the skeleton of the front-end. And it is time to make some functions work. My weekly task is creating a server side mailer function and an endpoint for contact form in front-end.

Nodemailer

Nodemailer is a module for Node.js applications to allow easy as cake email sending.

I follow their documentation with the SMTP configuration

nodemailer.createTransport({
  host: "smtp.example.com",
  port: 587,
  secure: false, // upgrade later with STARTTLS
  auth: {
    user: "username",
    pass: "password"
  }
});

And use verify method to valid my setting

// verify connection configuration
transporter.verify(function(error, success) {
  if (error) {
    console.log(error);
  } else {
    console.log("Server is ready to take our messages");
  }
});

Use sendMail method to make the function work

transporter.sendMail({
    from: 'sender@example.com',
    to: 'recipient@example.com',
    subject: 'Message',
    text: 'I hope this message gets delivered!'
}, (err, info) => {
    console.log(info.envelope);
    console.log(info.messageId);
});

Done!

Now I just need to create a endpoint for this function, so that Karla can request it in the front end.