diff --git a/Rnwood.Smtp4dev/CommandLineParser.cs b/Rnwood.Smtp4dev/CommandLineParser.cs index e3d4b93e8..c04f618a5 100644 --- a/Rnwood.Smtp4dev/CommandLineParser.cs +++ b/Rnwood.Smtp4dev/CommandLineParser.cs @@ -53,7 +53,7 @@ public static MapOptions TryParseCommandLine(IEnumerable { }); options.Add( - "urls=", "The URLs the web interface should listen on. For example, http://localhost:123. Use `*` in place of hostname to listen for requests on any IP address or hostname using the specified port and protocol (for example, http://*:5000)", data => map.Add(data, x => x.Urls)); + "urls=", "The URLs the web interface should listen on. For example, http://localhost:123. Use `*` in place of hostname to listen for requests on any IP address or hostname using the specified port and protocol (for example, http://*:5000). Separate multiple values with ;", data => map.Add(data, x => x.Urls)); options.Add( "basepath=", "Specifies the virtual path from web server root where SMTP4DEV web interface will be hosted. e.g. \"/\" or \"/smtp4dev\"", data => map.Add(data, x => x.ServerOptions.BasePath)); diff --git a/Rnwood.Smtp4dev/Program.cs b/Rnwood.Smtp4dev/Program.cs index c3fce7721..c07443870 100644 --- a/Rnwood.Smtp4dev/Program.cs +++ b/Rnwood.Smtp4dev/Program.cs @@ -190,7 +190,7 @@ private static IHost BuildWebHost(string[] args, CommandLineOptions cmdLineOptio if (!string.IsNullOrEmpty(cmdLineOptions.Urls)) { - c.UseUrls(cmdLineOptions.Urls); + c.UseUrls(cmdLineOptions.Urls.Split(';', StringSplitOptions.RemoveEmptyEntries).Select(u => u.Trim()).ToArray()); } }); diff --git a/Rnwood.Smtp4dev/Properties/launchSettings.json b/Rnwood.Smtp4dev/Properties/launchSettings.json index 3f0a598c8..a1f5e2041 100644 --- a/Rnwood.Smtp4dev/Properties/launchSettings.json +++ b/Rnwood.Smtp4dev/Properties/launchSettings.json @@ -18,7 +18,7 @@ }, "Rnwood.Smtp4dev": { "commandName": "Project", - "commandLineArgs": "--imapport=0", + "commandLineArgs": "--imapport=0 --urls=http://localhost:5000;http://localhost:5001", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/Rnwood.Smtp4dev/Server/Smtp4devServer.cs b/Rnwood.Smtp4dev/Server/Smtp4devServer.cs index b566a5757..9bedffa64 100644 --- a/Rnwood.Smtp4dev/Server/Smtp4devServer.cs +++ b/Rnwood.Smtp4dev/Server/Smtp4devServer.cs @@ -73,7 +73,7 @@ private void CreateSmtpServer() { if (this.smtpServer.IsRunning) return; log.Information("SMTP server stopped."); - this.notificationsHub.OnServerChanged().Wait(); + this.notificationsHub.OnServerChanged().Wait(); }); } @@ -93,8 +93,8 @@ private X509Certificate2 GetTlsCertificate() { if (!string.IsNullOrEmpty(serverOptions.CurrentValue.TlsCertificate)) { - var pfxPassword = serverOptions.CurrentValue.TlsCertificatePassword ?? ""; - + var pfxPassword = serverOptions.CurrentValue.TlsCertificatePassword ?? ""; + if (string.IsNullOrEmpty(serverOptions.CurrentValue.TlsCertificatePrivateKey)) { cert = CertificateHelper.LoadCertificate(serverOptions.CurrentValue.TlsCertificate, pfxPassword); @@ -273,10 +273,10 @@ private async Task OnMessageReceived(object sender, MessageEventArgs e) Message message = new MessageConverter().ConvertAsync(e.Message).Result; log.Information("Message received. Client address {clientAddress}, From {messageFrom}, To {messageTo}, SecureConnection: {secure}.", e.Message.Session.ClientAddress, e.Message.From, message.To, e.Message.SecureConnection); - message.IsUnread = true; + message.IsUnread = true; - await taskQueue.QueueTask(() => - { + await taskQueue.QueueTask(() => + { log.Information("Processing received message"); using var scope = serviceScopeFactory.CreateScope(); Smtp4devDbContext dbContext = scope.ServiceProvider.GetService(); @@ -284,9 +284,9 @@ await taskQueue.QueueTask(() => var relayResult = TryRelayMessage(message, null); message.RelayError = string.Join("\n", relayResult.Exceptions.Select(e => e.Key + ": " + e.Value.Message)); - ImapState imapState = dbContext.ImapState.Single(); + ImapState imapState = dbContext.ImapState.Single(); imapState.LastUid = Math.Max(0, imapState.LastUid + 1); - message.ImapUid = imapState.LastUid; + message.ImapUid = imapState.LastUid; message.Session = dbContext.Sessions.Find(activeSessionsToDbId[e.Message.Session]); if (relayResult.WasRelayed) { @@ -296,16 +296,16 @@ await taskQueue.QueueTask(() => } } - dbContext.Messages.Add(message); + dbContext.Messages.Add(message); - dbContext.SaveChanges(); + dbContext.SaveChanges(); - TrimMessages(dbContext); - dbContext.SaveChanges(); - notificationsHub.OnMessagesChanged().Wait(); + TrimMessages(dbContext); + dbContext.SaveChanges(); + notificationsHub.OnMessagesChanged().Wait(); log.Information("Processing received message DONE"); - }, false).ConfigureAwait(false); - } + }, false).ConfigureAwait(false); + } public RelayResult TryRelayMessage(Message message, MailboxAddress[] overrideRecipients) { @@ -338,15 +338,15 @@ public RelayResult TryRelayMessage(Message message, MailboxAddress[] overrideRec log.Information("Relaying message to {recipient}", recipient); using SmtpClient relaySmtpClient = relaySmtpClientFactory(relayOptions.CurrentValue); - var apiMsg = new ApiModel.Message(message); - MimeMessage newEmail = apiMsg.MimeMessage; - MailboxAddress sender = MailboxAddress.Parse( - !string.IsNullOrEmpty(relayOptions.CurrentValue.SenderAddress) - ? relayOptions.CurrentValue.SenderAddress - : apiMsg.From); - relaySmtpClient.Send(newEmail, sender, new[] { recipient }); + var apiMsg = new ApiModel.Message(message); + MimeMessage newEmail = apiMsg.MimeMessage; + MailboxAddress sender = MailboxAddress.Parse( + !string.IsNullOrEmpty(relayOptions.CurrentValue.SenderAddress) + ? relayOptions.CurrentValue.SenderAddress + : apiMsg.From); + relaySmtpClient.Send(newEmail, sender, new[] { recipient }); result.RelayRecipients.Add(new RelayRecipientResult() { Email = recipient.Address, RelayDate = DateTime.UtcNow }); - } + } catch (Exception e) { log.Error(e, "Can not relay message to {recipient}: {errorMessage}", recipient, e.ToString()); @@ -381,12 +381,12 @@ private void TrimSessions(Smtp4devDbContext dbContext) public bool IsRunning { get { return this.smtpServer.IsRunning; } - } + } public int PortNumber { get { return this.smtpServer.PortNumber; } - } + } public void TryStart() {