public MailNotifier(string fromAddress, IQueue outgouingQueue, IMailingListBroker mailingListBroker, IMailTemplateEngine templateEngine, params IEmailSender[] emailSenders) { _fromAddress = fromAddress; _outgouingQueue = outgouingQueue; _mailingListBroker = mailingListBroker; _templateEngine = templateEngine; _senders = new ConcurrentQueue<IEmailSender>(emailSenders); foreach (var emailSender in emailSenders) { emailSender.Completed += SendingCompleted; } }
public MailNotifierBuilder FromConfig() { var config = EtherConfigSection.Instance; _fromAddress = config.FromAddress; _sendersPoolSize = config.PoolSize; string outgoingEmailsFolder = config.OutgoingEmailsFolder; if (string.IsNullOrEmpty(outgoingEmailsFolder)) { _outgoingQueue = new TransientQueue(); } else { _outgoingQueue = new PersistentQueue("OutgoingEmails", outgoingEmailsFolder); } Dictionary<string, MailingList> groups = config.MailingGroups .Cast<GroupConfigElement>() .ToDictionary(g => g.Name, g => MailingList.Parse(g.Participants)); _mailingListBroker = new MailingListBroker( config.MailingRules .Cast<MailingRuleConfigurationElement>() .Select( cfg => new MailingRule(cfg.Name, BuildMailingList(cfg.Recepients.SplitAndTrim(), groups))) .ToArray()); var templatesFactory = new RazorTemplatesFactory(config.TemplatesFolder); _templateEngine = new RazorMailTemplateEngine(templatesFactory, config.AutoReloadTemplates); _emailSenders = new IEmailSender[_sendersPoolSize]; for (int i = 0; i < _sendersPoolSize; i++) { _emailSenders[i] = new SmtpSender(); } return this; }