Search code examples
javascriptoutlookoutlook-addin

Outlook appointment using ActiveX


I would like to set up outlook appointment using ActiveX.

Following code is working. Other than the part where I have setup the timezone. which i cant seem to find how to set. Is there any API reference available to setup timezone ?

 var sub = "Test";
                var stDate = "01-01-2020";
                var endDate = "01-01-2020";
                var sBody1 = ".....";
                var sBody2 = "hello ";
                var sBody3 = ".....world";
                if (confirm("Are you sure that you want to send an outlook invite for the meeting? Click OK to send invite.")) {
                    try {
                        outlookApp = new ActiveXObject("outlook.application");
                    }
                    catch (Error) {
                        alert("Please verify if your browser is enabled to run ActiveX scripts and try again!");
                        return false;
                    }

                    try {
                        nameSpace = outlookApp.getNameSpace("MAPI");
                        mailFolder = nameSpace.getDefaultFolder(6);
                        mailItem = mailFolder.Items.Add("IPM.Appointment.ConfRmReq");
                        mailItem.MeetingStatus = 1;
                        mailItem.Subject = sub;
                        mailItem.Start = stDate;
                        mailItem.End = endDate;

                        mailItem.TimeZones = ["Eastern Standard Time"];
                        //var tzEastern = tzs["Eastern Standard Time"];

                        mailItem.StartTimeZone = tzEastern;
                        mailItem.EndTimeZone = tzEastern;

                        var sBody = sBody1;
                        mailItem.Body = sBody;

                        sEmailList.push('Email Address');
                        mailItem.RequiredAttendees = sEmailList.join(';');
                        mailItem.Display();

Solution

  • You will need to retrieve the timezone from the Application.Iimezones collection. I never had luck retrieving the tz by its name, so you'd need to enumerate the time zones and check their ID / Name / StandardDesignation / DaylightDesignation properties.