Aspose.Email.Examples.CSharp.Email.IMAP.LoadSmtpConfigFile.Run C# (CSharp) Метод

Run() публичный статический Метод

public static Run ( ) : void
Результат void
        public static void Run()
        {
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_SMTP();
            string dstEmail = dataDir + "EmbeddedImage.msg";

            // Declare msg as MailMessage instance
            MailMessage msg = new MailMessage();

            // Use MailMessage properties like specify sender, recipient and message
            msg.To = "[email protected]";
            msg.From = "[email protected]";
            msg.Subject = "Test Email";
            msg.Body = "Hello World!";

            // Create an instance of SmtpClient class and load SMTP Authentication settings from Config file
            SmtpClient client = new SmtpClient(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Client.Send will send this message
                client.Send(msg);
                Console.WriteLine("Message sent");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            Console.WriteLine(Environment.NewLine + "Message sent after loading configuration from config file.");
        }
    }
LoadSmtpConfigFile