Sending iCal invite using Node Js

12 / Jun / 2015 by Sakshi Tyagi 3 comments

Sending event invites through an email is a common use case nowadays in applications. In this blog, we will briefly cover the steps to accomplish this using Node.js.

Node.js provide various npm modules for sending iCal invite. We have customized one of the modules and used it according to our use case. You can find the module here .

Let’s say we have an object called “eventObj” which contains all the required information related to an event like start time, end time, title, organiser details etc. We will use this information to create our “.ics” file and send it to the receiver as an email attachment.

Step1: In your js file, require the module.

var ical = require(‘my-ical-generator’);

Step2: Now we need that event object which looks like:

var eventObj = {
	'start' : new Date(),
	'end' : new Date("13 June,2015"),
	'title' : 'Annual trip',
	'description' : 'Lets enjoy and relax'
	'id' : 'wdcwe76234e127eugb', //Some unique identifier
	'organiser' : {'name' : 'Sakshi Tyagi', 'email':''},
	'location' : 'Goa'

var cal = ical();
Now set the domain which is your application’s weburl and give a name to the event.
cal.setDomain(‘’).setName(‘My ical invite’);

Now, we actually add the event details to the iCal object using method addEvent()

	start: eventObj.start,
	end: eventObj.end,
	summary: eventObj.title,
	uid:, // Some unique identifier
	sequence: 0,
	description: eventObj.description,
	location: eventObj.location,
	organizer: {
	method: 'request'

Some of the fields are optional.

Step 3: Now that our event is ready, we need to save the ‘.ics’ file created. Here in this example, we save it on our server, in the ‘uploads’ directory.

 var path = __dirname + '/uploads/'+ + '.ics';

Step 4: Last step is to send the mail with the .ics file. We can use classic “nodemailer” module for this.

Just require the module and use its “sendMail” method to send the attachment in the email.

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
    service: "yourEmailProvider",
    auth: {
        user: "yourEmail" ,
        pass: "yourPassword"
var mailObj = {
	from: "Sender email Id",
    to: "Receiver email Id",
    subject: "Your Subject",
    text: "Some text in the body",
	attachments : [path]

transporter.sendMail(mailObj, function(err, info){

There you go! We successfully sent an email with iCal invite.

Hope this helps. 🙂


comments (3)

  1. Mohit Mathur

    Can we send a meeting invitation wit accept , reject and decline buttons without the attachment? Means email itself act as an invite.

    1. Muhammad Umar

      I know I am replying too late but it will help others.
      Yes, you can send an invite with Accept and Reject buttons using nodemailer.
      Check the complete code here,

      change content with path: “your ics file path”
      var message = {
      from: ‘”Sender Name” ‘,
      to: ‘”Receiver Name” ‘,
      subject: ‘Calendar invite’,
      text: ‘This message contains a calendar event’,
      icalEvent: {
      method: ‘request’,
      // content can be a string, a buffer or a stream
      // alternatively you could use `path` that points to a file or an url
      content: ‘BEGIN:VCALENDAR\r\nPRODID:-//ACME/DesktopCalendar//EN\r\nMETHOD:REQUEST\r\nVERSION:2.0\r\n…’


Leave a Reply

Your email address will not be published. Required fields are marked *