public void SimpleTest() { container.Register(Component.For(typeof(SimpleLoggingComponent)).Named("component1")); SimpleLoggingComponent test = container.Resolve <SimpleLoggingComponent>("component1"); test.DoSomething(); String expectedLogOutput = String.Format("[INFO ] [{0}] - Hello world" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName); MemoryAppender memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender; TextWriter actualLogOutput = new StringWriter(); PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline"); patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]); Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString()); container.Register(Component.For(typeof(SmtpServer)).Named("component2")); ISmtpServer smtpServer = container.Resolve <ISmtpServer>("component2"); smtpServer.Start(); smtpServer.InternalSend("*****@*****.**", "*****@*****.**", "We're looking for a few good porgrammars."); smtpServer.Stop(); expectedLogOutput = String.Format("[DEBUG] [Castle.Facilities.Logging.Tests.Classes.SmtpServer] - Stopped" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName); memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender; actualLogOutput = new StringWriter(); patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline"); Assert.AreEqual(memoryAppender.GetEvents().Length, 4); patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[3]); Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString()); }
public Initialiser(IDatabaseInitialiser databaseInitialiser, IWebServer webServer, ISmtpServer smtpServer, IEmailRecorder emailRecorder) { _databaseInitialiser = databaseInitialiser; _webServer = webServer; _smtpServer = smtpServer; _emailRecorder = emailRecorder; }
public void SimpleTest() { container.Register(Component.For(typeof(SimpleLoggingComponent)).Named("component1")); SimpleLoggingComponent test = container.Resolve <SimpleLoggingComponent>("component1"); test.DoSomething(); String expectedLogOutput = String.Format("|INFO|{0}|Hello world", typeof(SimpleLoggingComponent).FullName); String actualLogOutput = (NLog.LogManager.Configuration.FindTargetByName("memory") as MemoryTarget).Logs[0].ToString(); actualLogOutput = actualLogOutput.Substring(actualLogOutput.IndexOf('|')); Assert.AreEqual(expectedLogOutput, actualLogOutput); container.Register(Component.For(typeof(SmtpServer)).Named("component2")); ISmtpServer smtpServer = container.Resolve <ISmtpServer>("component2"); smtpServer.Start(); smtpServer.InternalSend("*****@*****.**", "*****@*****.**", "We're looking for a few good porgrammars."); smtpServer.Stop(); expectedLogOutput = String.Format("|INFO|Castle.Facilities.Logging.Tests.Classes.SmtpServer|InternalSend [email protected] [email protected] We're looking for a few good porgrammars.", typeof(SmtpServer).FullName); actualLogOutput = (NLog.LogManager.Configuration.FindTargetByName("memory") as MemoryTarget).Logs[1].ToString(); actualLogOutput = actualLogOutput.Substring(actualLogOutput.IndexOf('|')); Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString()); }
public EmailRecorder(ISmtpServer smtpServer, IEmailRepository emailRepository, IGroupRepository groupRepository) { _smtpServer = smtpServer; _emailRepository = emailRepository; _groupRepository = groupRepository; RecordMail(); }
/// <summary> /// Initializes a new instance of the <see cref="DirectorySmtpServer"/> class. /// </summary> /// <param name="name"> </param> /// <param name="successor">The successor.</param> public DirectorySmtpServer(string name, ISmtpServer successor = null) { Name = name; SmtpClient = new SmtpClient() { DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = ConfigurationManager.AppSettings["PickupDirectory"], }; Successor = successor; }
/// <summary> /// Initializes a new instance of the <see cref="GmailSmtpServer"/> class. /// </summary> /// <param name="name"> </param> /// <param name="successor">The successor.</param> public GmailSmtpServer(string name, ISmtpServer successor = null) { Name = name; SmtpClient = new SmtpClient("smtp.gmail.com"); SmtpClient.UseDefaultCredentials = false; SmtpClient.EnableSsl = true; SmtpClient.Credentials = new NetworkCredential("*****@*****.**", "Thi@Email@Service"); SmtpClient.Port = 587; Successor = successor; }
/// <summary> /// Initializes a new instance of the <see cref="Connection"/> class. /// </summary> /// <param name="server">The server.</param> /// <param name="session">The session.</param> /// <param name="connectionChannel">The connection channel.</param> /// <param name="verbMap">The verb map.</param> /// <param name="extensionProcessors">The extension processors.</param> internal Connection(ISmtpServer server, IEditableSession session, IConnectionChannel connectionChannel, IVerbMap verbMap, Func <IConnection, IExtensionProcessor[]> extensionProcessors) { this.id = $"[RemoteIP={connectionChannel.ClientIPAddress}]"; this.ConnectionChannel = connectionChannel; this.ConnectionChannel.ClosedEventHandler += this.OnConnectionChannelClosed; this.VerbMap = verbMap; this.Session = session; this.Server = server; this.ExtensionProcessors = extensionProcessors(this).ToArray(); }
/// <summary> /// Creates the a connection for the specified server and channel.. /// </summary> /// <param name="server">The server.</param> /// <param name="connectionChannel">The connection channel.</param> /// <param name="verbMap">The verb map.</param> /// <returns>An <see cref="Task{T}"/> representing the async operation.</returns> internal static async Task <Connection> Create(ISmtpServer server, IConnectionChannel connectionChannel, IVerbMap verbMap) { IEditableSession session = await server.Behaviour.OnCreateNewSession(connectionChannel).ConfigureAwait(false); var extensions = await server.Behaviour.GetExtensions(connectionChannel).ConfigureAwait(false); IExtensionProcessor[] CreateConnectionExtensions(IConnection c) => extensions.Select(e => e.CreateExtensionProcessor(c)).ToArray(); Connection result = new Connection(server, session, connectionChannel, verbMap, CreateConnectionExtensions); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="LocalSmtpServer"/> class. /// </summary> /// <param name="successor">The successor.</param> /// <param name="name"> </param> public LocalSmtpServer(string name, ISmtpServer successor = null) { Name = name; SmtpClient = new SmtpClient { Host = ConfigurationManager.AppSettings["SmtpServerLocal"], Port = 25, EnableSsl = false, DeliveryMethod = SmtpDeliveryMethod.Network }; Successor = successor; }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation(FormattableString.Invariant($"Starting...")); try { var options = new SmtpServerOptionsBuilder() .ServerName("localhost") .Port(25, 587) .Build(); var serviceProvider = new ServiceProvider(); var messageStore = _messageStoreFactory.Create(_logger, _messageQueue); serviceProvider.Add(messageStore); _smtpServer = _smtpServerFactory.Create(options, serviceProvider); var messageProcessingTask = Task.Factory.StartNew(async() => await ProcessMessages(stoppingToken), stoppingToken).ContinueWith(a => { }, stoppingToken); var serverTask = _smtpServer.StartAsync(stoppingToken); await Task.WhenAll(messageProcessingTask, serverTask); } finally { _logger.LogInformation(FormattableString.Invariant($"Stopped")); } }
/// <summary> /// Initializes a new instance of the <see cref="LocalSmtpServer"/> class. /// </summary> /// <param name="successor">The successor.</param> /// <param name="name"> </param> public DefaultSmtpServer(string name, ISmtpServer successor = null) { Name = name; SmtpClient = new SmtpClient(); Successor = successor; }
public EmailSender( ISmtpServer smtpServer, EmailTaskModel emailTaskModel ) { EmailTaskModel = emailTaskModel; SmtpServer = smtpServer; }
public ExceptionEmailSender(ISmtpServer smptServer) { EmailSender = new EmailSender(smptServer); }
public EmailSender(ISmtpServer smtpServer) { _SmtpServer = smtpServer; }
private EmailService() { _mEmailServices = SetSmtpServer(_mSmtpServers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()); }
public EmailSender(ISmtpServer server, EmailAddress _from, IList <EmailAddress> to) { this.server = server; From = _from; To = to; }
public EmailService(ISmtpServer _smtpService) { smtpService = _smtpService; }