예제 #1
0
        public void loadInfo_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.Visibility = Visibility.Visible));
            this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.BeginInit()));
            this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.UpdateLayout()));



            try
            {
                // Connect to Exchange Web Services as user1 at contoso.com.
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
                service.Credentials = new WebCredentials(ConfigurationSettings.AppSettings["EWSuser"], ConfigurationSettings.AppSettings["EWSpassword"]);
                service.Url         = new System.Uri("https://outlook.office365.com/ews/exchange.asmx");
                // service.AutodiscoverUrl("*****@*****.**");

                int sendcounter = 0;


                foreach (recipient _recipient in RecipientsList)
                {
                    // Create the e-mail message, set its properties, and send it to [email protected], saving a copy to the Sent Items folder.
                    SendEmail(service, _recipient);

                    sendcounter++;
                    // Write confirmation message to console window.
                    Console.WriteLine("Message " + sendcounter.ToString() + " of " + RecipientsList.Count.ToString() + " sent.");

                    this.Dispatcher.BeginInvoke((Action)(() =>
                                                         UpdateLabelRunning(sendcounter.ToString(), RecipientsList.Count.ToString())
                                                         ));
                }



                Thread.Sleep(500);
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.Visibility = Visibility.Hidden));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.EndInit()));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.UpdateLayout()));
                this.Dispatcher.BeginInvoke((Action)(() => label1.Content = "done."));

                //label1.Content = "done.";
                //Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }
        }
예제 #2
0
        public void loadInfo2_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.Visibility = Visibility.Visible));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.BeginInit()));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.UpdateLayout()));

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
                service.Credentials = new WebCredentials(ConfigurationSettings.AppSettings["EWSuser"], ConfigurationSettings.AppSettings["EWSpassword"]);
                service.Url         = new System.Uri("https://outlook.office365.com/ews/exchange.asmx");
                // service.AutodiscoverUrl("*****@*****.**");


                int sendcounter = 0;

                foreach (recipient _recipient in SelectedRecipientsList)
                {
                    SendEmail(service, _recipient);
                    sendcounter++;

                    Console.WriteLine("Message " + sendcounter.ToString() + " of " + SelectedRecipientsList.Count.ToString() + " sent (selection)");


                    this.Dispatcher.BeginInvoke((Action)(() =>
                                                         UpdateLabelRunning(sendcounter.ToString(), SelectedRecipientsList.Count.ToString())
                                                         ));
                    //Thread.Sleep(1000);
                }
                Thread.Sleep(500);
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.Visibility = Visibility.Hidden));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.EndInit()));
                this.Dispatcher.BeginInvoke((Action)(() => Cogwheel1.UpdateLayout()));
                this.Dispatcher.BeginInvoke((Action)(() => label1.Content = "done."));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }
        }