Can I create an appointment request for Outlook using nodeJS?

I am developing a very simple calendar with Angular and Node and I have not found any code on this.

The workflow is as follows: create an event, enter the recipient's email address, check the event. This causes an email to be sent to the recipient. Mail must be in meeting request format (not attached item).

This means that when received in Outlook, the meeting is automatically added to the calendar.

Is it possible? If so, is this only possible with javascript on the Node side?

+3


source to share


3 answers


For those still looking for an answer, here's how I managed to get the perfect solution for me. I used iCalToolkit to create a calendar object.

It is important that all relevant fields are configured (host and attendees with RSVP).

I originally used the Postmark API service to send my emails, but this solution only worked when the ics.file app was sent.

I switched to SMTP Postmark service where you can insert iCal data inside a post and I used nodemailer for that.



It looks like this:

        var icalToolkit = require('ical-toolkit');
        var postmark = require('postmark');
        var client = new postmark.Client('xxxxxxxKeyxxxxxxxxxxxx');
        var nodemailer = require('nodemailer');
        var smtpTransport = require('nodemailer-smtp-transport');

        //Create a iCal object
        var builder = icalToolkit.createIcsFileBuilder();
        builder.method = meeting.method;
        //Add the event data

        var icsFileContent = builder.toString();
        var smtpOptions = {
            host:'smtp.postmarkapp.com',
            port: 2525,
            secureConnection: true,
            auth:{
               user:'xxxxxxxKeyxxxxxxxxxxxx',
               pass:'xxxxxxxPassxxxxxxxxxxx'
            }
        };

        var transporter = nodemailer.createTransport(smtpTransport(smtpOptions));

        var mailOptions = {
            from: 'message@domain.com',
            to: meeting.events[0].attendees[i].email,
            subject: 'Meeting to attend',
            html: "Anything here",
            text: "Anything here",
            alternatives: [{
              contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
              content: icsFileContent.toString()
            }]
        };

        //send mail with defined transport object 
        transporter.sendMail(mailOptions, function(error, info){
            if(error){
                console.log(error);
            }
            else{
                console.log('Message sent: ' + info.response);  
            }
        });

      

This sends the actual meeting request with the Accept, Decline and Decline buttons.

It's no wonder how much work you have to go through for such a trivial function and how poorly documented it all is. Hope this helps.

+4


source


If you don't want to use an SMTP server in the previous solution, you have an Exchange-centric solution. What's wrong in the current accepted answer? it does not create an appointment in the sender's calendar, you do not have ownership of the meeting item for further editing by the Outlook / OWA sender.

here's a code snippet in javascript using the npm package ews-javascript-api



var ews = require("ews-javascript-api");
var credentials = require("../credentials");
ews.EwsLogging.DebugLogEnabled = false;

var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);

exch.Credentials = new ews.ExchangeCredentials(credentials.userName, credentials.password);

exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx");

var appointment = new ews.Appointment(exch);

appointment.Subject = "Dentist Appointment";
appointment.Body = new ews.TextBody("The appointment is with Dr. Smith.");
appointment.Start = new ews.DateTime("20170502T130000");
appointment.End = appointment.Start.Add(1, "h");
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1@constoso.com");
appointment.RequiredAttendees.Add("user2@constoso.com");
appointment.OptionalAttendees.Add("user3@constoso.com");

appointment.Save(ews.SendInvitationsMode.SendToAllAndSaveCopy).then(function () {
    console.log("done - check email");
}, function (error) {
    console.log(error);
});

      

+1


source


This should be possible if you can use SOAP in Node and also if you can use NTLM authentication for Exchange with Node. I believe there are modules for every module.

I found this blog very helpful when developing a similar system using PHP

0


source







All Articles