Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js send meeting/calendar invite for gmail

I am trying to send calendar invite using node js.

I have tried nodemailer library and is sending mail with calendar invite

Like in reference to this question

but this is sending invite like check add to calendar link

but I want send invite like enter image description here

suggest some help if anyone knows better approach.

[update] using google-calendar api the output is showing like enter image description here

like image 599
Sam Avatar asked Jul 21 '17 13:07

Sam


People also ask

How do I send a calendar invite in node JS?

If we need to send calendar invites just create a calendar object from the above-mentioned function and then send its return object to the below sendemail function. sendemail, };

Can you send a calendar invite via Gmail?

Add people to your event On your computer, open Google Calendar. On the right, under "Guests," start typing the name of the person and choose someone from your contacts. You can also type an email address to invite people who aren't in your contacts list.

How do I send a calendar invite in Nodemailer?

You can simply send the link to the Google calendar for example from where the user can simply click & join the event. The "Content-Type": "text/calendar" is making the mail sender / client belive that there is an actual file attached or associated with the email. The attach the . ics file.


2 Answers

I would use the Google Calendar API: https://developers.google.com/google-apps/calendar/create-events, you can do this using a library such as https://www.npmjs.com/package/google-calendar. It also has the benefit that you won't have to send emails from your server.

In this way you can add attendees and the invite will be the same as if you sent the request directly from the calendar instead of Google interpreting your email as a calendar event.

The event you create appears on all the primary Google Calendars of the attendees you included with the same event ID. If you set sendNotifications to true on your insert request, the attendees will also receive an email notification for your event. See the events with multiple attendees guide for more information.

like image 126
Peter Grainger Avatar answered Sep 21 '22 12:09

Peter Grainger


sendNotifications is deprecated, use sendUpdates. Notice it isn't boolean but string.

calendar.events.insert({
    auth: auth,
    calendarId: 'primary',
    resource: event,
    sendUpdates: 'all',
  }, function(err, event) {
    if (err) {
      console.log('There was an error contacting the Calendar service: ' + err);
      return;
    }
    console.log('Event created: %s', event.htmlLink);
  });

From typescript signatures:

     * @param {boolean=} params.sendNotifications Deprecated. Please use sendUpdates instead.  Whether to send notifications about the creation of the new event. Note that some emails might still be sent even if you set the value to false. The default is false.
     * @param {string=} params.sendUpdates Whether to send notifications about the creation of the new event. Note that some emails might still be sent. The default is false.
like image 34
Alexandr Shevchenko Avatar answered Sep 20 '22 12:09

Alexandr Shevchenko