{"id":19935,"date":"2015-06-12T15:05:57","date_gmt":"2015-06-12T09:35:57","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=19935"},"modified":"2015-12-10T18:39:20","modified_gmt":"2015-12-10T13:09:20","slug":"sending-ical-invite-using-node-js","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/","title":{"rendered":"Sending iCal invite using Node Js"},"content":{"rendered":"<p>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.<\/p>\n<p>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 <a title=\"my-ical-generator\" href=\"https:\/\/github.com\/sakshityagi\/my-ical-generator\" target=\"_blank\">here<\/a>\u00a0.<\/p>\n<p>Let&#8217;s say we have an object called &#8220;eventObj&#8221; which contains all the required information related to an event like start time, end time, title, organiser details etc. We will use this\u00a0information to create our &#8220;.ics&#8221; file and send it to the receiver as an email attachment.<\/p>\n<p><strong>Step1:<\/strong> In your js file, require the module.<\/p>\n<p>[js]<br \/>\nvar ical = require(&#8216;my-ical-generator&#8217;);<br \/>\n[\/js]<\/p>\n<p><strong>Step2:<\/strong> Now we need that event object which looks like:<\/p>\n<pre>var eventObj = {\r\n\t'start' :\u00a0new Date(),\r\n\t'end' :\u00a0new Date(\"13 June,2015\"),\r\n\t'title' : 'Annual trip',\r\n\t'description' : 'Lets enjoy and relax'\r\n\t'id' : 'wdcwe76234e127eugb', \/\/Some unique identifier\r\n\t'organiser' : {'name' : 'Sakshi Tyagi', 'email':'sakshi.tyagi@tothenew.com'},\r\n\t'location' : 'Goa'\r\n}\r\n<\/pre>\n<p>var cal = ical();<br \/>\nNow set the domain which is your application&#8217;s weburl and give a name to the event.<br \/>\ncal.setDomain(&#8216;http:\/\/www.tothenew.com\/&#8217;).setName(&#8216;My ical invite&#8217;);<\/p>\n<p>Now, we actually add the event details to the iCal object using method <strong>addEvent()<\/strong><\/p>\n<pre>cal.addEvent({\r\n\tstart: eventObj.start,\r\n\tend: eventObj.end,\r\n\tsummary: eventObj.title,\r\n\tuid: eventObj.id, \/\/ Some unique identifier\r\n\tsequence: 0,\r\n\tdescription: eventObj.description,\r\n\tlocation: eventObj.location,\r\n\torganizer: {\r\n                name: eventObj.owner.name,\r\n                email: eventObj.owner.email\r\n      \t\t},\r\n\tmethod: 'request'\r\n});\r\n<\/pre>\n<p>Some of the fields are optional.<\/p>\n<p><strong>Step 3:<\/strong> Now that our event is ready, we need to save the &#8216;.ics&#8217; file created. Here in this example, we save it on our server, in the &#8216;uploads&#8217; directory.<\/p>\n<pre> var path = __dirname + '\/uploads\/'+ eventObj.id + '.ics';\r\n cal.saveSync(path);\r\n<\/pre>\n<p><strong>Step 4:<\/strong> Last step is to send the mail with the .ics file. We can use classic &#8220;nodemailer&#8221; module for this.<\/p>\n<p>Just require the module and use its &#8220;sendMail&#8221; method to send the attachment in the email.<\/p>\n<pre>var nodemailer = require('nodemailer');\r\nvar transporter = nodemailer.createTransport({\r\n    service: \"yourEmailProvider\",\r\n    auth: {\r\n        user: \"yourEmail\" ,\r\n        pass: \"yourPassword\"\r\n    }\r\n});\r\n<\/pre>\n<pre>var mailObj = {\r\n\tfrom: \"Sender email Id\",\r\n    to: \"Receiver email Id\",\r\n    subject: \"Your Subject\",\r\n    text: \"Some text in the body\",\r\n\tattachments : [path]\r\n};\r\n\r\ntransporter.sendMail(mailObj, function(err, info){\r\n       console.log(err,info);\r\n});\r\n\r\n<\/pre>\n<p>There you go! We successfully sent an email with iCal invite.<\/p>\n<p>Hope this helps. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":65,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":62,"footnotes":""},"categories":[1185],"tags":[1864,55,1124,1863],"class_list":["post-19935","post","type-post","status-publish","format-standard","hentry","category-node-js-2","tag-ical","tag-javascript","tag-node-js","tag-nodemailer"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"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.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sakshi Tyagi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Sending ical invite using Node Js | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"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.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Sending ical invite using Node Js | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"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.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#article\",\"name\":\"Sending ical invite using Node Js | TO THE NEW Blog\",\"headline\":\"Sending iCal invite using Node Js\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2015-06-12T15:05:57+05:30\",\"dateModified\":\"2015-12-10T18:39:20+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":3,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#webpage\"},\"articleSection\":\"Node.js, ical, javascript, node.js, nodemailer\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"name\":\"Node.js\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"position\":2,\"name\":\"Node.js\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#listItem\",\"name\":\"Sending iCal invite using Node Js\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#listItem\",\"position\":3,\"name\":\"Sending iCal invite using Node Js\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/node-js-2\\\/#listItem\",\"name\":\"Node.js\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/\",\"name\":\"Sakshi Tyagi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sakshi Tyagi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/\",\"name\":\"Sending ical invite using Node Js | TO THE NEW Blog\",\"description\":\"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.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/sending-ical-invite-using-node-js\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"datePublished\":\"2015-06-12T15:05:57+05:30\",\"dateModified\":\"2015-12-10T18:39:20+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Sending ical invite using Node Js | TO THE NEW Blog","description":"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.","canonical_url":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#article","name":"Sending ical invite using Node Js | TO THE NEW Blog","headline":"Sending iCal invite using Node Js","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2015-06-12T15:05:57+05:30","dateModified":"2015-12-10T18:39:20+05:30","inLanguage":"en-US","commentCount":3,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#webpage"},"articleSection":"Node.js, ical, javascript, node.js, nodemailer"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","name":"Node.js"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","position":2,"name":"Node.js","item":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#listItem","name":"Sending iCal invite using Node Js"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#listItem","position":3,"name":"Sending iCal invite using Node Js","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/#listItem","name":"Node.js"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/","name":"Sakshi Tyagi","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sakshi Tyagi"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/","name":"Sending ical invite using Node Js | TO THE NEW Blog","description":"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.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"datePublished":"2015-06-12T15:05:57+05:30","dateModified":"2015-12-10T18:39:20+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Sending ical invite using Node Js | TO THE NEW Blog","og:description":"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.","og:url":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Sending ical invite using Node Js | TO THE NEW Blog","twitter:description":"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.","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"19935","title":"Sending ical invite using Node Js | #site_title","description":"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.","keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 14:23:49","updated":"2024-02-29 09:10:23","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/\" title=\"Node.js\">Node.js<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tSending iCal invite using Node Js\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Node.js","link":"https:\/\/www.tothenew.com\/blog\/category\/node-js-2\/"},{"label":"Sending iCal invite using Node Js","link":"https:\/\/www.tothenew.com\/blog\/sending-ical-invite-using-node-js\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=19935"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19935\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=19935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=19935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=19935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}