From 31d24034d1f033d58e7cf9eacfd279cc482c5877 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 18 Apr 2023 22:14:18 +0200 Subject: [PATCH] Update Email module Fixes #3711 --- docker-compose.yml | 6 ++++++ .../Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj | 1 + src/bundles/Elsa.AllInOne.Web/Program.cs | 1 + src/bundles/Elsa.AllInOne.Web/appsettings.json | 5 +++++ .../Elsa.WorkflowServer.Web.csproj | 1 + src/bundles/Elsa.WorkflowServer.Web/Program.cs | 1 + .../Elsa.WorkflowServer.Web/appsettings.json | 5 +++++ src/modules/Elsa.Email/Activities/SendEmail.cs | 15 ++++++++++++++- src/modules/Elsa.Email/Features/EmailFeature.cs | 14 +++++++++++--- .../docker-compose.yaml | 12 ------------ 10 files changed, 45 insertions(+), 16 deletions(-) delete mode 100644 src/samples/aspnet/Elsa.Samples.WorkflowContexts/docker-compose.yaml diff --git a/docker-compose.yml b/docker-compose.yml index 1187a3048..cc8ceca33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -85,6 +85,12 @@ services: - "5601:5601" depends_on: - elasticsearch + + smtp4dev: + image: rnwood/smtp4dev:3.1.3-ci20211206101 + ports: + - "3000:80" + - "2525:25" networks: consul: diff --git a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj index 09f5989da..7cbb09fd8 100644 --- a/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj +++ b/src/bundles/Elsa.AllInOne.Web/Elsa.AllInOne.Web.csproj @@ -10,6 +10,7 @@ + diff --git a/src/bundles/Elsa.AllInOne.Web/Program.cs b/src/bundles/Elsa.AllInOne.Web/Program.cs index 99c1bb470..bdef94e27 100644 --- a/src/bundles/Elsa.AllInOne.Web/Program.cs +++ b/src/bundles/Elsa.AllInOne.Web/Program.cs @@ -40,6 +40,7 @@ services .UseJavaScript() .UseLiquid() .UseHttp() + .UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options)) ); services.AddHealthChecks(); diff --git a/src/bundles/Elsa.AllInOne.Web/appsettings.json b/src/bundles/Elsa.AllInOne.Web/appsettings.json index 2b88e1078..a485a8f0e 100644 --- a/src/bundles/Elsa.AllInOne.Web/appsettings.json +++ b/src/bundles/Elsa.AllInOne.Web/appsettings.json @@ -17,5 +17,10 @@ "Tokens": { "SigningKey": "secret-signing-key" } + }, + "Smtp": { + "Host": "localhost", + "Port": 2525, + "DefaultSender": "noreply@crmservices.com" } } diff --git a/src/bundles/Elsa.WorkflowServer.Web/Elsa.WorkflowServer.Web.csproj b/src/bundles/Elsa.WorkflowServer.Web/Elsa.WorkflowServer.Web.csproj index 782f236dd..b93d2e1d4 100644 --- a/src/bundles/Elsa.WorkflowServer.Web/Elsa.WorkflowServer.Web.csproj +++ b/src/bundles/Elsa.WorkflowServer.Web/Elsa.WorkflowServer.Web.csproj @@ -10,6 +10,7 @@ + diff --git a/src/bundles/Elsa.WorkflowServer.Web/Program.cs b/src/bundles/Elsa.WorkflowServer.Web/Program.cs index d71d2e5e8..c08110052 100644 --- a/src/bundles/Elsa.WorkflowServer.Web/Program.cs +++ b/src/bundles/Elsa.WorkflowServer.Web/Program.cs @@ -47,6 +47,7 @@ services .UseJavaScript() .UseLiquid() .UseHttp() + .UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options)) ); services.Configure(options => options.AllowClrAccess = true); diff --git a/src/bundles/Elsa.WorkflowServer.Web/appsettings.json b/src/bundles/Elsa.WorkflowServer.Web/appsettings.json index f5baa3a1a..018a929e9 100644 --- a/src/bundles/Elsa.WorkflowServer.Web/appsettings.json +++ b/src/bundles/Elsa.WorkflowServer.Web/appsettings.json @@ -15,6 +15,11 @@ "ConnectionStrings": { "Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;" }, + "Smtp": { + "Host": "localhost", + "Port": 2525, + "DefaultSender": "noreply@crmservices.com" + }, "Identity": { "Tokens": { "SigningKey": "secret-signing-key", diff --git a/src/modules/Elsa.Email/Activities/SendEmail.cs b/src/modules/Elsa.Email/Activities/SendEmail.cs index fa323b1b4..96d0b9fdc 100644 --- a/src/modules/Elsa.Email/Activities/SendEmail.cs +++ b/src/modules/Elsa.Email/Activities/SendEmail.cs @@ -1,6 +1,8 @@ using System.Collections; +using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization; using Elsa.Email.Contracts; using Elsa.Email.Models; using Elsa.Email.Options; @@ -20,11 +22,22 @@ namespace Elsa.Email.Activities; [Activity("Email", "Send an email message.", Kind = ActivityKind.Task)] public class SendEmail : Activity { + /// + public SendEmail([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) + { + } + + /// + [JsonConstructor] + public SendEmail() + { + } + /// /// The sender's email address. /// [Input(Description = "The sender's email address.")] - public Input From { get; set; } + public Input From { get; set; } = default!; [Input(Description = "The recipients email addresses.", UIHint = InputUIHints.MultiText)] public Input> To { get; set; } = default!; diff --git a/src/modules/Elsa.Email/Features/EmailFeature.cs b/src/modules/Elsa.Email/Features/EmailFeature.cs index 04ae3cda2..b70311904 100644 --- a/src/modules/Elsa.Email/Features/EmailFeature.cs +++ b/src/modules/Elsa.Email/Features/EmailFeature.cs @@ -1,6 +1,7 @@ using Elsa.Email.Contracts; using Elsa.Email.Options; using Elsa.Email.Services; +using Elsa.Extensions; using Elsa.Features.Abstractions; using Elsa.Features.Services; using Microsoft.Extensions.DependencyInjection; @@ -27,11 +28,18 @@ public class EmailFeature : FeatureBase /// public Action ConfigureDownloaderHttpClient { get; set; } = (_, _) => { }; + /// + public override void Configure() + { + Module.AddActivitiesFrom(); + } + /// public override void Apply() { - Services.Configure(ConfigureOptions); - Services.AddSingleton(); - Services.AddHttpClient(ConfigureDownloaderHttpClient); + Services + .Configure(ConfigureOptions) + .AddSingleton() + .AddHttpClient(ConfigureDownloaderHttpClient); } } \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.WorkflowContexts/docker-compose.yaml b/src/samples/aspnet/Elsa.Samples.WorkflowContexts/docker-compose.yaml deleted file mode 100644 index 452ce9877..000000000 --- a/src/samples/aspnet/Elsa.Samples.WorkflowContexts/docker-compose.yaml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3.9' - -services: - - smtp4dev: - image: rnwood/smtp4dev:3.1.3-ci20211206101 - ports: - - "3000:80" - - "2525:25" - -volumes: - mssql-azuresql-edge-data: \ No newline at end of file