Aspose.Email.Examples.CSharp.Email.Exchange.SendExchangeTask.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {

            try
            {

                // The path to the File directory.
                string dataDir = RunExamples.GetDataDir_Exchange();
                string dstEmail = dataDir + "Message.eml";

                // Create instance of ExchangeClient class by giving credentials
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // load task from .eml file
                EmlLoadOptions loadOptions = new EmlLoadOptions();

                loadOptions.PrefferedTextEncoding = Encoding.UTF8;
                loadOptions.PreserveTnefAttachments = true;

                // load task from .msg file
                MailMessage eml = MailMessage.Load(dstEmail, loadOptions);
                eml.From = "[email protected]";
                eml.To.Clear();
                eml.To.Add(new MailAddress("[email protected]"));
                client.Send(eml);
                Console.WriteLine(Environment.NewLine + "Task sent on Exchange Server successfully.");
            }
            catch (Exception ex)
            {

                Console.Write(ex.Message);
            }
        }
    }
SendExchangeTask