Ejemplo n.º 1
0
        private static void SendDataDrivenEmail(MySqlConnection con)
        {
            Dictionary <string, string> dictFlareSystemConfigurationEntries = SystemConfigurationEntry.GetDictionary(con);

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerAddress))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server address is specified");
            }

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerUserName))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server user name is specified");
            }

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerPassword))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server password is specified");
            }

            string       strSMTPServerAddress  = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerAddress];
            string       strSMTPServerUserName = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerUserName];
            string       strSMTPServerPassword = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerPassword];
            const string strFrom    = @"*****@*****.**";
            const string strTo      = @"*****@*****.**";
            const string strSubject = @"Data-driven e-mail test";
            string       strBody    = string.Format(@"Hello Tom; It is now {0} Universal Time.",
                                                    MySqlUtils.DateTimeToString(DateTime.UtcNow));

            Console.WriteLine(@"About to send data-driven e-mail to {0}...", strTo);
            MailUtils.SendMail(strSMTPServerAddress, strSMTPServerUserName, strSMTPServerPassword,
                               strFrom, strTo, null, null, strSubject, strBody);
            Console.WriteLine(@"E-mail sent.");
        }