Esempio n. 1
0
        static void Main(string[] args)
        {
            // Start tracing to console and a log file.
            Tracing.OpenLog("./GetStartedWithEWS.log");
            Tracing.WriteLine("EWS sample application started.");

            var isValidEmailAddress = false;

            Console.Write("Enter an email address: ");
            var emailAddress = Console.ReadLine();

            isValidEmailAddress = (emailAddress.Contains("@") && emailAddress.Contains("."));

            if (!isValidEmailAddress)
            {
                Tracing.WriteLine("Email address " + emailAddress + " is not a valid SMTP address. Closing program.");
                return;
            }

            SecureString password = GetPasswordFromConsole();

            if (password.Length == 0)
            {
                Tracing.WriteLine("Password empty, closing program.");
            }

            NetworkCredential userCredentials = new NetworkCredential(emailAddress, password);

            // These are the sample methods that demonstrate using EWS.
            ShowNumberOfMessagesInInbox(userCredentials);
            SendTestEmail(userCredentials);

            Tracing.WriteLine("EWS sample application ends.");
            Tracing.CloseLog();

            Console.WriteLine("Press enter to exit: ");
            Console.ReadLine();
        }