Monday, 13 June 2016

How to send email using NodeJS.

Sometimes we may need an email form or contact form for our website
Scenario-1: We wish our users to be able to communicate to the admin, author, managers of our website.
Scenario-2: We wish to send emails to our users regarding
  • Signup success
  • Forgot password
  • Reset password success
  • Invalid activity

Run

  1. Download and extract the zip file
  2. Open command prompt and browse to the extracted folder
  3. write the command node .
  4. Open Chrome browser and point to http://localhost:8080/

Tutorial

We will be creating a simple AngularJS web application which will send an email to the website administrator when any users wish to contact regarding any issue.
We are going to implement the above functionality in just 3 steps
  1. Craft the user interface (front end client side)
  2. Configure the email client (Sendgrid)
  3. Create the server and make the server talk to Sendgrid and AngularJS frontend (Using NodeJS)

Step-1

Let’s build the user interface using google’s material design and our friend AngularJS
Let’s use the material design CSS library provided by materializecss.com

Step-2

To send email we will use some node libraries
  • nodemailer
  • nodemailer-sendgrid-transport
For this we need to create a sendgrid account and generate a api key and use in index.js

Project Structure

client
– style css
– app.js
– index.html
index.js
package.json
 

index.js (NodeJS)

package.json

index.html

app.js (AngularJS)

No comments:

Post a Comment