static public Base CreateMailerOfType(String type, MailConfiguration configuration) { try { return(registeredMailers[type]( configuration)); } catch (KeyNotFoundException mailerNotRegistered) { Console.WriteLine("E!"); throw new SCLPME.ImplementationNotPresent( type, mailerNotRegistered); } }
void ReadMailNotificationsConfiguration() { List <String> recipientAddresses; XmlNodeList recipients = configurationFile.SelectNodes("//recipient"); XmlNode sender = configurationFile.SelectSingleNode("//Sender"); String[] senderAttributes = new String[6] { "address", "password", "server", "port", "username", "useSsl" }; SCLP.LogProxy.Log(SCLP.LogLevel.Info, "Configuring Email error notifications..."); if (recipients.Count == 0) { throw new Exception("No recipients defined."); } else if (sender == null) { throw new Exception("No sending account information specified."); } foreach (String a in senderAttributes) { if (sender.Attributes[a].Value == null) { throw new Exception(String.Format( "No Sender {0} specified.", a)); } } recipientAddresses = new List <String>(); foreach (XmlNode r in recipients) { if (r.InnerText != null) { SCLP.LogProxy.Log(SCLP.LogLevel.Info, String.Format( "Recipient \"{0}\" added.", r.InnerText)); recipientAddresses.Add(r.InnerText); } else { SCLP.LogProxy.Log(SCLP.LogLevel.Info, "Recipient defined with no address specified, ignoring..."); } } try { SCLPM.MailConfiguration configuration = new SCLPM.MailConfiguration( sender.Attributes["address"].Value, sender.Attributes["password"].Value, sender.Attributes["server"].Value, Int32.Parse(sender.Attributes["port"].Value), recipientAddresses.ToArray(), sender.Attributes["username"].Value, Boolean.Parse( sender.Attributes["useSsl"].Value)); mailer = SCLPM.Factory.CreateMailerOfType( "Smtp", configuration); } catch (Exception e) { throw new Exception( "Malformed Sender specification. Invalid Port or UseSsl setting.", e); } finally { recipientAddresses.Clear(); SCLP.LogProxy.MailerInstance = mailer; } }
static public Base Create(MailConfiguration configuration) { return(new Smtp(configuration)); }