static void SetOOF(ExchangeService service)
        {
            OofSettings userOOF = new OofSettings();

            // Select the OOF status to be a set time period.
            userOOF.State = OofState.Scheduled;

            // Select the time period to be OOF
            userOOF.Duration = new TimeWindow(DateTime.Now.AddDays(4), DateTime.Now.AddDays(5));

            // Select the external audience that will receive OOF messages.
            userOOF.ExternalAudience = OofExternalAudience.All;

            // Select the OOF reply for your internal audience.
            userOOF.InternalReply = new OofReply("I'm currently out of office. Please contact my manager for critical issues. Thanks!");

            // Select the OOF reply for your external audience.
            userOOF.ExternalReply = new OofReply("I am currently out of the office but will reply to emails when I return. Thanks!");

            // Set the selected values. This method will result in a call to the Exchange Server.
            service.SetUserOofSettings(UserDataFromConsole.GetUserData().EmailAddress, userOOF);

            // Retrieve the user status and print to the console
            Ex15_GetOOF_CS.GetOOF(service);
        }
        public static void GetOOF(ExchangeService service)
        {
            // Return the Out Of Office object that contains OOF state for the user whose credendials were supplied at the console.
            // This method will result in a call to the Exchange Server.
            OofSettings userOOFSettings = service.GetUserOofSettings(UserDataFromConsole.GetUserData().EmailAddress);

            // Get the (read-only) audience of email message senders outside a client's organization who will receive automatic Out Of Office replies ("All", "Known", or "None").
            OofExternalAudience allowedExternalAudience = userOOFSettings.AllowExternalOof;

            // Get the duration for a scheduled Out Of Office reply.
            TimeWindow OOFDuration = userOOFSettings.Duration;

            // Get the ExternalAudience of email message senders outside a client's organization who will receive automatic Out OF Office replies (All/Known/None).
            OofExternalAudience externalAudience = userOOFSettings.ExternalAudience;

            // Get the reply to be sent to email message senders outside a client's organization.
            OofReply externalReply = userOOFSettings.ExternalReply;

            // Get the reply to be sent to email message senders inside a client's organization.
            OofReply internalReply = userOOFSettings.InternalReply;

            // Get the (Disabled/Enabled/Scheduled) state of the Out Of Office automatic reply feature.
            OofState userOofState = userOOFSettings.State;

            // Print user status information to the console
            Console.WriteLine("Allowed External Audience: {0}", allowedExternalAudience);
            Console.WriteLine("Out of Office duration: {0}", OOFDuration);
            Console.WriteLine("External Audience: {0}", externalAudience);
            Console.WriteLine("External Reply: {0}", externalReply);
            Console.WriteLine("Internal Reply: {0}", internalReply);
            Console.WriteLine("User OOF state: {0}", userOofState);
        }
Example #3
0
        public void Design(IActivityDesigner designer)
        {
            OofSettings newOofSettings = new OofSettings();

            designer.AddInput("Mailbox Email Address").WithDefaultValue("*****@*****.**");
            designer.AddInput("External Audiance").WithListBrowser(new string[] { "All", "Known", "None" }).WithDefaultValue("All").NotRequired();
            designer.AddInput("Start Time").WithDateTimeBrowser().WithDefaultValue(DateTime.Now.ToString()).NotRequired();
            designer.AddInput("End Time").WithDateTimeBrowser().WithDefaultValue(DateTime.Now.AddDays(1).ToString()).NotRequired();
            designer.AddInput("External Reply").WithDefaultValue("I'm currently out of office. Please contact my manager for critical issues. Thanks!").NotRequired();
            designer.AddInput("Internal Reply").WithDefaultValue("I am currently out of the office but will reply to emails when I return. Thanks!").NotRequired();
            designer.AddInput("State").WithListBrowser(new string[] { "Disabled", "Enabled", "Scheduled" }).WithDefaultValue("Enabled").NotRequired();
            designer.AddCorellatedData(typeof(OutOfOffice));
        }
Example #4
0
 public static void UpdateOOO(TimeWindow duration)
 {
     var email_user = Environment.GetEnvironmentVariable("email_user");
     var email = Environment.GetEnvironmentVariable("email");
     var ews_url = Environment.GetEnvironmentVariable("ews_url");
     string clientId = Environment.GetEnvironmentVariable("akvClientId");
     string clientSecret = Environment.GetEnvironmentVariable("akvClientSecret");
     string tenantId = Environment.GetEnvironmentVariable("akvTenantId");
     string subscriptionId = Environment.GetEnvironmentVariable("akvSubscriptionId");
     string kvURL = Environment.GetEnvironmentVariable("akvName");
     string secretName = Environment.GetEnvironmentVariable("akvSecret");
     AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud).WithDefaultSubscription(subscriptionId);
     var keyClient = new KeyVaultClient(async (authority, resource, scope) =>
     {
         var adCredential = new ClientCredential(clientId, clientSecret);
         var authenticationContext = new AuthenticationContext(authority, null);
         return (await authenticationContext.AcquireTokenAsync(resource, adCredential)).AccessToken;
     });
     KeyVaultCache keyVaultCache = new KeyVaultCache(kvURL, clientId, clientSecret);
     var cacheSecret = keyVaultCache.GetCachedSecret(secretName);
     string email_pass = cacheSecret.Result;
     // Create the binding.
     ExchangeService service = new ExchangeService();
     service.TraceEnabled = false;
     service.TraceFlags = TraceFlags.All;
     // Set the credentials for the on-premises server.
     service.Credentials = new WebCredentials(email_user, email_pass);
     // Set the URL.
     service.Url = new Uri(ews_url);
     // Return the Out Of Office object that contains OOF state for the user whose credendials were supplied at the console. 
     // This method will result in a call to the Exchange Server.
     OofSettings userOOFSettings = service.GetUserOofSettings(email);
     OofSettings userOOF = new OofSettings();
     // Select the OOF status to be a set time period.
     userOOF.State = OofState.Scheduled;
     // Select the time period to be OOF
     userOOF.Duration = duration;
     // Select the external audience that will receive OOF messages.
     userOOF.ExternalAudience = OofExternalAudience.All;
     // Select the OOF reply for your internal audience.
     userOOF.InternalReply = userOOFSettings.InternalReply;
     // Select the OOF reply for your external audience.
     userOOF.ExternalReply = userOOFSettings.ExternalReply;
     service.SetUserOofSettings(email, userOOF);
     Console.WriteLine("Updated OOF");
     Console.WriteLine("StartDate {0:MM/dd/yy H:mm:ss zzz}", duration.StartTime);
     Console.WriteLine("EndDate {0:MM/dd/yy H:mm:ss zzz}", duration.EndTime);
     return;
 }
Example #5
0
        //gavdcodeend 14

        //gavdcodebegin 15
        static void SetOutOfOfficeConfig(ExchangeService ExService)
        {
            OofSettings myOOFConfig = new OofSettings
            {
                State    = OofState.Enabled,
                Duration = new TimeWindow(
                    DateTime.Now.AddDays(4), DateTime.Now.AddDays(2)),
                ExternalAudience = OofExternalAudience.All,
                InternalReply    = new OofReply("Out of office internal reply"),
                ExternalReply    = new OofReply("Out of the office external reply")
            };

            myOOFConfig.ExternalAudience = OofExternalAudience.Known;

            ExService.SetUserOofSettings("*****@*****.**", myOOFConfig);
        }
Example #6
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            userName        = settings.UserName;
            password        = settings.Password;
            domain          = settings.Domain;
            serviceURL      = settings.ServiceUrl;
            exchangeVersion = settings.ExchangeVersion;

            userEmailAddr = request.Inputs["Mailbox Email Address"].AsString();

            ExchangeService service = new ExchangeService();

            switch (exchangeVersion)
            {
            case "Exchange2007_SP1":
                service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                break;

            case "Exchange2010":
                service = new ExchangeService(ExchangeVersion.Exchange2010);
                break;

            case "Exchange2010_SP1":
                service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                break;

            default:
                service = new ExchangeService();
                break;
            }

            service.Credentials = new WebCredentials(userName, password, domain);
            String AccountUrl = userName + "@" + domain;

            if (serviceURL.Equals("Autodiscover"))
            {
                service.AutodiscoverUrl(userEmailAddr, (a) => { return(true); });
            }
            else
            {
                service.Url = new Uri(serviceURL);
            }

            OofSettings userOOFSettings = service.GetUserOofSettings(userEmailAddr);

            response.WithFiltering().PublishRange(getOOF(userOOFSettings));
        }
Example #7
0
        internal OutOfOffice(OofSettings outofOfficeSetting, String emailAddress)
        {
            try { this.StartTime = outofOfficeSetting.Duration.StartTime; }
            catch { }

            try { this.EndTime = outofOfficeSetting.Duration.EndTime; }
            catch { }
            try { this.State = outofOfficeSetting.State.ToString(); }
            catch { }
            try { this.ExternalAudience = outofOfficeSetting.ExternalAudience.ToString(); }
            catch { }
            try { this.InternalReply = outofOfficeSetting.InternalReply.Message.ToString(); }
            catch { }
            try { this.ExternalReply = outofOfficeSetting.ExternalReply.Message.ToString(); }
            catch { }
            try { this.AllowExternalOof = Convert.ToBoolean(outofOfficeSetting.AllowExternalOof); }
            catch { }
            try { this.UserEmail = emailAddress; }
            catch { }
        }
Example #8
0
        /// <summary>
        /// Display the given OofSettings in the form controls.
        /// </summary>
        /// <param name="settings">OofSettings to display in the form</param>
        private void DisplayOofSettings(OofSettings settings)
        {
            // Convert the OOF settings to control values
            switch (this.originalOofSettings.State)
            {
            case OofState.Disabled:
                this.OofDisabledOption.Checked = true;
                this.OofEnabledOption.Checked  = false;
                this.OofScheduledCheck.Checked = false;
                break;

            case OofState.Enabled:
                this.OofEnabledOption.Checked  = true;
                this.OofDisabledOption.Checked = false;
                this.OofScheduledCheck.Checked = false;
                break;

            case OofState.Scheduled:
                this.OofEnabledOption.Checked  = true;
                this.OofScheduledCheck.Checked = true;
                this.OofDisabledOption.Checked = false;
                break;
            }

            this.EnableControlsForOofState(settings.State);

            this.externalAudienceCombo.SelectedItem = this.originalOofSettings.ExternalAudience;

            this.ScheduledStartTime.Value = this.originalOofSettings.Duration.StartTime;
            this.ScheduledEndTime.Value   = this.originalOofSettings.Duration.EndTime;

            this.ExternalReplyCulture.Text = this.originalOofSettings.ExternalReply.Culture;
            this.ExternalReplyText.Text    = this.originalOofSettings.ExternalReply.Message;

            this.InternalReplyCulture.Text = this.originalOofSettings.InternalReply.Culture;
            this.InternalReplyText.Text    = this.originalOofSettings.InternalReply.Message;

            // Display the target mailbox address in the group box text
            this.OofSettingsGroup.Text = string.Format("OOF Settings for '{0}'", this.TargetMailbox.Address);
        }
Example #9
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         _ews = ConnectEWS();
         Console.WriteLine(Environment.NewLine);
         Console.WriteLine("Checking Privileged Connection...");
         try
         {
             OofSettings oof = _ews.GetUserOofSettings(input_calendar.Text);
             Console.WriteLine("Allowed Out of Office...");
             Console.WriteLine($"{oof.State}\r\n{oof.InternalReply}\r\n{oof.ExternalReply}\r\n");
         }
         catch (Exception)
         {
             Console.WriteLine("Denied Out of Office...");
         }
         Console.WriteLine("Checking Appointment Connection...");
         try
         {
             var folder = GetFolders();
             Console.WriteLine("Allowed Calendar Views...");
             PrintFolders(folder);
             List <Appointment>     list             = GetAppointments(folder);
             List <JSONAppointment> jsonAppointments = WriteJSON(list);
             Console.WriteLine(@"Writing to JSON File...");
             File.WriteAllText("appointments.json", JsonConvert.SerializeObject(jsonAppointments.ToArray()));
         }
         catch (Exception ex)
         {
             Console.WriteLine("Denied Calendar Views...");
         }
         Console.WriteLine("EWS SUCCEEDED - OPEN THE WEB SOCKET!");
     }
     catch (Exception)
     {
         Console.WriteLine("EWS FAILED - CHECK SETTINGS!");
     }
 }
Example #10
0
        //gavdcodeend 13

        //gavdcodebegin 14
        static void GetOutOfOfficeConfig(ExchangeService ExService)
        {
            OofSettings myOOFConfig = ExService.GetUserOofSettings("*****@*****.**");

            OofExternalAudience myAllowedExternalAudience = myOOFConfig.AllowExternalOof;

            Console.WriteLine(myAllowedExternalAudience.ToString());

            TimeWindow myOOFDuration = myOOFConfig.Duration;

            if (myOOFDuration != null)
            {
                Console.WriteLine(myOOFDuration.StartTime.ToLocalTime() + " - " +
                                  myOOFDuration.EndTime.ToLocalTime());
            }

            OofExternalAudience myExternalAudience = myOOFConfig.ExternalAudience;

            Console.WriteLine(myExternalAudience.ToString());

            OofReply myExternalReply = myOOFConfig.ExternalReply;

            if (myExternalReply != null)
            {
                Console.WriteLine(myExternalReply.ToString());
            }

            OofReply myInternalReply = myOOFConfig.InternalReply;

            if (myInternalReply != null)
            {
                Console.WriteLine(myInternalReply.ToString());
            }

            OofState myOofState = myOOFConfig.State;

            Console.WriteLine(myOofState.ToString());
        }
Example #11
0
        /// <summary>
        /// Determine if two OofSettings objects are equal
        /// </summary>
        /// <param name="oof1">First OofSettings to compare</param>
        /// <param name="oof2">Second OofSettings to compare</param>
        /// <returns>Returns true if objects are equal, false is not</returns>
        public static bool IsEqual(OofSettings oof1, OofSettings oof2)
        {
            // If both OofSettings are null they are equal and we
            // don't need to look any deeper
            if (oof1 == null && oof2 == null)
            {
                return(true);
            }

            // If only one of the OofSettings is null
            if (oof2 == null ^ oof1 == null)
            {
                return(false);
            }

            // If only one of the Duration properties is null
            if (oof1.Duration == null ^ oof2.Duration == null)
            {
                return(false);
            }

            // If Durations are set but are different
            if ((oof1.Duration != null && oof2.Duration != null) &&
                (!DateTime.Equals(oof1.Duration.StartTime, oof2.Duration.StartTime) ||
                 !DateTime.Equals(oof1.Duration.EndTime, oof2.Duration.EndTime)))
            {
                return(false);
            }

            if (oof1.ExternalAudience != oof2.ExternalAudience)
            {
                return(false);
            }

            // If only one of the ExtenalReply properties is null
            if (oof1.ExternalReply == null ^ oof2.ExternalReply == null)
            {
                return(false);
            }

            // If ExternalReply properties are set but are different
            if (((oof1.ExternalReply != null) && (oof2.ExternalReply != null)) &&
                (!String.Equals(oof1.ExternalReply.Culture, oof2.ExternalReply.Culture) ||
                 !String.Equals(oof1.ExternalReply.Message, oof2.ExternalReply.Message)))
            {
                return(false);
            }

            // If only one of the InternalReply properties is null
            if (oof1.InternalReply == null ^ oof2.InternalReply == null)
            {
                return(false);
            }

            // If InternalReply properties are set but are different
            if (((oof1.InternalReply != null) && (oof2.InternalReply != null)) &&
                (!String.Equals(oof1.InternalReply.Culture, oof2.InternalReply.Culture) ||
                 !String.Equals(oof1.InternalReply.Message, oof2.InternalReply.Message)))
            {
                return(false);
            }

            if (oof1.State != oof2.State)
            {
                return(false);
            }

            // If we got here they must be equal
            return(true);
        }
Example #12
0
 private IEnumerable <OutOfOffice> getOOF(OofSettings userSettings)
 {
     yield return(new OutOfOffice(userSettings, userEmailAddr));
 }
Example #13
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            userName        = settings.UserName;
            password        = settings.Password;
            domain          = settings.Domain;
            serviceURL      = settings.ServiceUrl;
            exchangeVersion = settings.ExchangeVersion;

            userEmailAddr = request.Inputs["Mailbox Email Address"].AsString();


            ExchangeService service = new ExchangeService();

            switch (exchangeVersion)
            {
            case "Exchange2007_SP1":
                service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                break;

            case "Exchange2010":
                service = new ExchangeService(ExchangeVersion.Exchange2010);
                break;

            case "Exchange2010_SP1":
                service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                break;

            default:
                service = new ExchangeService();
                break;
            }

            service.Credentials = new WebCredentials(userName, password, domain);
            String AccountUrl = userName + "@" + domain;

            if (serviceURL.Equals("Autodiscover"))
            {
                service.AutodiscoverUrl(userEmailAddr, (a) => { return(true); });
            }
            else
            {
                service.Url = new Uri(serviceURL);
            }

            OofSettings userOOFSettings = service.GetUserOofSettings(userEmailAddr);

            if (request.Inputs.Contains("External Audiance"))
            {
                ExternalAudience = request.Inputs["External Audiance"].AsString();
                switch (ExternalAudience)
                {
                case "All":
                    userOOFSettings.ExternalAudience = OofExternalAudience.All;
                    break;

                case "Known":
                    userOOFSettings.ExternalAudience = OofExternalAudience.Known;
                    break;

                case "None":
                    userOOFSettings.ExternalAudience = OofExternalAudience.None;
                    break;

                default:
                    response.LogWarningMessage("State must be one of the following: Disabled, Enabled, Scheduled");
                    break;
                }
            }
            if (request.Inputs.Contains("Start Time"))
            {
                try
                {
                    StartTime = Convert.ToDateTime(request.Inputs["Start Time"].AsString());
                    userOOFSettings.Duration.StartTime = StartTime;
                }
                catch
                {
                    response.LogWarningMessage("Start Time must be a valid Date Time: Entered Value was " + request.Inputs["Start Time"].AsString());
                }
            }
            if (request.Inputs.Contains("End Time"))
            {
                try
                {
                    EndTime = Convert.ToDateTime(request.Inputs["End Time"].AsString());
                    userOOFSettings.Duration.EndTime = EndTime;
                }
                catch
                {
                    response.LogWarningMessage("End Time must be a valid Date Time: Entered Value was " + request.Inputs["End Time"].AsString());
                }
            }
            if (request.Inputs.Contains("External Reply"))
            {
                ExternalReply = request.Inputs["External Reply"].AsString();
                userOOFSettings.ExternalReply = ExternalReply;
            }
            if (request.Inputs.Contains("Internal Reply"))
            {
                InternalReply = request.Inputs["Internal Reply"].AsString();
                userOOFSettings.InternalReply = InternalReply;
            }
            if (request.Inputs.Contains("State"))
            {
                State = request.Inputs["State"].AsString();
                switch (State)
                {
                case "Disabled":
                    userOOFSettings.State = OofState.Disabled;
                    break;

                case "Enabled":
                    userOOFSettings.State = OofState.Enabled;
                    break;

                case "Scheduled":
                    userOOFSettings.State = OofState.Scheduled;
                    break;

                default:
                    response.LogWarningMessage("State must be one of the following: Disabled, Enabled, Scheduled");
                    break;
                }
            }

            service.SetUserOofSettings(userEmailAddr, userOOFSettings);
            userOOFSettings = service.GetUserOofSettings(userEmailAddr);
            response.WithFiltering().PublishRange(getOOF(userOOFSettings));
        }
Example #14
0
 /// <summary>
 /// Call GetUserOofSettings to get OOF of the target mailbox and display
 /// settings in the form controls.
 /// </summary>
 private void DisplayOofSettings()
 {
     // Get OOF settings
     this.originalOofSettings = this.CurrentService.GetUserOofSettings(this.TargetMailbox.Address);
     this.DisplayOofSettings(this.originalOofSettings);
 }
Example #15
0
        /// <summary>
        /// Convert the current form control values into OofSettings
        /// </summary>
        /// <returns> OofSettings created from the form control values</returns>
        private OofSettings GetFormOofSettings()
        {
            // Gather new OOF settings
            OofSettings newOof = new OofSettings();

            DateTime startTime = new DateTime(
                this.ScheduledStartTime.Value.Year,
                this.ScheduledStartTime.Value.Month,
                this.ScheduledStartTime.Value.Day,
                this.ScheduledStartTime.Value.Hour,
                this.ScheduledStartTime.Value.Minute,
                this.ScheduledStartTime.Value.Second);

            DateTime endTime = new DateTime(
                this.ScheduledEndTime.Value.Year,
                this.ScheduledEndTime.Value.Month,
                this.ScheduledEndTime.Value.Day,
                this.ScheduledEndTime.Value.Hour,
                this.ScheduledEndTime.Value.Minute,
                this.ScheduledEndTime.Value.Second);

            newOof.Duration = new TimeWindow(startTime, endTime);

            OofExternalAudience?audience = this.externalAudienceCombo.SelectedItem;

            if (audience.HasValue)
            {
                newOof.ExternalAudience = audience.Value;
            }

            newOof.ExternalReply = new OofReply();
            if (!String.IsNullOrEmpty(this.ExternalReplyText.Text))
            {
                newOof.ExternalReply.Culture = this.ExternalReplyCulture.Text;
                newOof.ExternalReply.Message = this.ExternalReplyText.Text;
            }

            newOof.InternalReply = new OofReply();
            if (!String.IsNullOrEmpty(this.InternalReplyText.Text))
            {
                newOof.InternalReply.Culture = this.InternalReplyCulture.Text;
                newOof.InternalReply.Message = this.InternalReplyText.Text;
            }

            // OofState can only be Disabled, Enabled, or Scheduled.  Since this is
            // displayed on the between three controls order is important here.  If
            // OofDisabledOption is checked then we are disabled, even though
            // OofScheduledCheck could be checked too.  If OofScheduledCheck is checked
            // then the state is Scheduled, even though OofEnabledOption could be
            // checked too.
            if (this.OofDisabledOption.Checked)
            {
                newOof.State = OofState.Disabled;
            }
            else if (this.OofScheduledCheck.Checked)
            {
                newOof.State = OofState.Scheduled;
            }
            else if (this.OofEnabledOption.Checked)
            {
                newOof.State = OofState.Enabled;
            }

            return(newOof);
        }