From 918cc345181a9e7ac7934bdd25b4fe8ef5d7e028 Mon Sep 17 00:00:00 2001 From: Rob Wood Date: Sat, 27 Apr 2024 07:31:47 +0100 Subject: [PATCH] Fix(relay): Fix NRE in relay (Resolves #1438) (#1440) --- .../src/components/settingsdialog.vue | 45 +++++++------------ Rnwood.Smtp4dev/Server/ScriptingHost.cs | 14 +++--- Rnwood.Smtp4dev/Server/Smtp4devServer.cs | 5 +++ Rnwood.Smtp4dev/Startup.cs | 2 +- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/Rnwood.Smtp4dev/ClientApp/src/components/settingsdialog.vue b/Rnwood.Smtp4dev/ClientApp/src/components/settingsdialog.vue index 3510e1b5d..92a15fd90 100644 --- a/Rnwood.Smtp4dev/ClientApp/src/components/settingsdialog.vue +++ b/Rnwood.Smtp4dev/ClientApp/src/components/settingsdialog.vue @@ -92,7 +92,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -244,20 +244,20 @@ - -
- - - - - -
- New Auto-Relay Recipient
+
+ + + + + +
+ New Auto-Relay Recipient + @@ -395,21 +395,6 @@ } } - relayAutomaticEmails: any[] = []; - - @Watch("server.relayAutomaticEmails") - updateAutomaticEmailsForValidation() { - - if (!this.server) { - return; - } - - this.relayAutomaticEmails = this.server.relayAutomaticEmails.map((v, i) => { - return { value: v }; - }); - - } - async save() { this.saving = true; this.error = null; diff --git a/Rnwood.Smtp4dev/Server/ScriptingHost.cs b/Rnwood.Smtp4dev/Server/ScriptingHost.cs index 7e49cc11a..30a8fbae5 100644 --- a/Rnwood.Smtp4dev/Server/ScriptingHost.cs +++ b/Rnwood.Smtp4dev/Server/ScriptingHost.cs @@ -96,7 +96,7 @@ public IReadOnlyCollection GetAutoRelayRecipients(ApiModel.Message messa { JsValue result = jsEngine.Evaluate(shouldRelayScript); - List recpients = new List(); + List relayRecipients = new List(); if (result.IsNull()) { @@ -105,22 +105,22 @@ public IReadOnlyCollection GetAutoRelayRecipients(ApiModel.Message messa { if (result.AsString() != String.Empty) { - recpients.Add(result.AsString()); + relayRecipients.Add(result.AsString()); } } else if (result.IsArray()) { - recpients.AddRange(result.AsArray().Select(v => v.AsString())); + relayRecipients.AddRange(result.AsArray().Select(v => v.AsString())); } else if (result.AsBoolean()) { - recpients.Add(recipient); + relayRecipients.Add(recipient); } - log.Information("AutomaticRelayExpression: (message: {message.Id}, recipient: {recipient}, session: {session.Id}) => {result} => {recipients}", message.Id, recipient, - session.Id, result, recpients); + log.Information("AutomaticRelayExpression: (message: {messageId}, recipient: {recipient}, session: {sessionId}) => {result} => {relayRecipients}", message.Id, recipient, + session.Id, result, relayRecipients); - return recpients; + return relayRecipients; } catch (JavaScriptException ex) diff --git a/Rnwood.Smtp4dev/Server/Smtp4devServer.cs b/Rnwood.Smtp4dev/Server/Smtp4devServer.cs index 6a201504e..eb50a6cdd 100644 --- a/Rnwood.Smtp4dev/Server/Smtp4devServer.cs +++ b/Rnwood.Smtp4dev/Server/Smtp4devServer.cs @@ -413,6 +413,11 @@ public RelayResult TryRelayMessage(Message message, MailboxAddress[] overrideRec log.Information("Relaying message to {recipient}", recipient); using SmtpClient relaySmtpClient = relaySmtpClientFactory(relayOptions.CurrentValue); + + if (relaySmtpClient == null) + { + throw new ApplicationException("Relay server options are incomplete."); + } var apiMsg = new ApiModel.Message(message); MimeMessage newEmail = apiMsg.MimeMessage; MailboxAddress sender = MailboxAddress.Parse( diff --git a/Rnwood.Smtp4dev/Startup.cs b/Rnwood.Smtp4dev/Startup.cs index 591c95757..51f35eacf 100644 --- a/Rnwood.Smtp4dev/Startup.cs +++ b/Rnwood.Smtp4dev/Startup.cs @@ -122,7 +122,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton>(relayOptions => { - if (!string.IsNullOrEmpty( relayOptions.SmtpServer)) + if (string.IsNullOrEmpty( relayOptions.SmtpServer)) { return null; }