Pages

Saturday 9 April 2016

Send Email with Meteor using Gmail SMTP

Meteor is new framework based on Node.js  for fast building and development of web application. In all web application there is a always need of sending email for many purpose.

Following code snippet show basic email functionality. Further i show different emails with MUP settings.

Adding package

First you need to add email package in your application

in current application folder write following line your terminal

meteor add email

this will add new package in your application, you can also add it directly in meteor application's package file by adding new line as follows

email

Setup the MAIL_URL

Create new file smtp.js under server directory. Meteor itself understand file's accessibility whether it is server side file or client side file as you put it in to server or client directory.

Add following code into smtp.js, here we are using Gmail's SMTP to send email.

Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://email_username:email_password@smtp.gmail.com:587';
});


Add following code where you want to send email.

if (Meteor.isServer) {
Email.send({
from: "from@fornfromgeeks.com",
to: "me@myid.com",
subject: "Subject",
text: "Hello, Geeks"
});
}

No comments:

Post a Comment