diff --git a/src/administration/Administration.Service/appsettings.json b/src/administration/Administration.Service/appsettings.json index 47c6302efe..16aff9ac0c 100644 --- a/src/administration/Administration.Service/appsettings.json +++ b/src/administration/Administration.Service/appsettings.json @@ -388,7 +388,8 @@ "SmtpHost": "", "SmtpPort": 587, "SmtpUser": "", - "SmtpPassword": "" + "SmtpPassword": "", + "SenderEmail": "" } }, "IdentityProviderAdmin": { diff --git a/src/mailing/Mailing.SendMail/MailSettings.cs b/src/mailing/Mailing.SendMail/MailSettings.cs index 0af2d13846..8c6be9c45c 100644 --- a/src/mailing/Mailing.SendMail/MailSettings.cs +++ b/src/mailing/Mailing.SendMail/MailSettings.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using MimeKit; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail @@ -33,13 +34,16 @@ public class MailSettings public int SmtpPort { get; set; } = 0; public string? HttpProxy { get; set; } public int HttpProxyPort { get; set; } + public string SenderEmail { get; set; } = null!; public bool Validate() { var validation = new ConfigurationValidation() .NotNullOrWhiteSpace(SmtpHost, () => nameof(SmtpHost)) .NotNullOrWhiteSpace(SmtpUser, () => nameof(SmtpUser)) - .NotNullOrWhiteSpace(SmtpPassword, () => nameof(SmtpPassword)); + .NotNullOrWhiteSpace(SmtpPassword, () => nameof(SmtpPassword)) + .NotNullOrWhiteSpace(SenderEmail, () => nameof(SenderEmail)); + if (HttpProxy != null) { validation.NotNullOrWhiteSpace(HttpProxy, () => nameof(HttpProxy)); @@ -48,7 +52,7 @@ public bool Validate() } } - public static class MailSettingsExtention + public static class MailSettingsExtension { public static IServiceCollection ConfigureMailSettings( this IServiceCollection services, diff --git a/src/mailing/Mailing.SendMail/Mailing.SendMail.csproj b/src/mailing/Mailing.SendMail/Mailing.SendMail.csproj index d5c8bbc549..666cbc4089 100644 --- a/src/mailing/Mailing.SendMail/Mailing.SendMail.csproj +++ b/src/mailing/Mailing.SendMail/Mailing.SendMail.csproj @@ -22,6 +22,7 @@ Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail + Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail net7.0 enable enable diff --git a/src/mailing/Mailing.SendMail/MailingService.cs b/src/mailing/Mailing.SendMail/MailingService.cs index 71a4e23805..98cfd71da9 100644 --- a/src/mailing/Mailing.SendMail/MailingService.cs +++ b/src/mailing/Mailing.SendMail/MailingService.cs @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Mailing.Template; namespace Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail; @@ -26,11 +27,13 @@ public class MailingService : IMailingService { private readonly ITemplateManager _templateManager; private readonly ISendMail _sendMail; + private readonly MailSettings _settings; - public MailingService(ITemplateManager templateManager, ISendMail sendMail) + public MailingService(ITemplateManager templateManager, ISendMail sendMail, IOptions options) { _templateManager = templateManager; _sendMail = sendMail; + _settings = options.Value; } public async Task SendMails(string recipient, IDictionary parameters, IEnumerable templates) @@ -38,7 +41,7 @@ public async Task SendMails(string recipient, IDictionary parame foreach (var temp in templates) { var email = await _templateManager.ApplyTemplateAsync(temp, parameters).ConfigureAwait(false); - await _sendMail.Send("Notifications@catena-x.net", recipient, email.Subject, email.Body, email.isHtml).ConfigureAwait(false); + await _sendMail.Send(_settings.SenderEmail, recipient, email.Subject, email.Body, email.isHtml).ConfigureAwait(false); } } } diff --git a/src/marketplace/Apps.Service/appsettings.json b/src/marketplace/Apps.Service/appsettings.json index 9829f23e18..9d053cb9aa 100644 --- a/src/marketplace/Apps.Service/appsettings.json +++ b/src/marketplace/Apps.Service/appsettings.json @@ -113,7 +113,8 @@ "SmtpHost": "", "SmtpPort": 587, "SmtpUser": "", - "SmtpPassword": "" + "SmtpPassword": "", + "SenderEmail": "" } }, "Provisioning": { diff --git a/src/marketplace/Services.Service/appsettings.json b/src/marketplace/Services.Service/appsettings.json index 10e292f808..643fa17725 100644 --- a/src/marketplace/Services.Service/appsettings.json +++ b/src/marketplace/Services.Service/appsettings.json @@ -107,7 +107,8 @@ "SmtpHost": "", "SmtpPort": 587, "SmtpUser": "", - "SmtpPassword": "" + "SmtpPassword": "", + "SenderEmail": "" } }, "Provisioning": { diff --git a/src/processes/Processes.Worker/appsettings.json b/src/processes/Processes.Worker/appsettings.json index 6f2a97080f..a7b58544b9 100644 --- a/src/processes/Processes.Worker/appsettings.json +++ b/src/processes/Processes.Worker/appsettings.json @@ -366,7 +366,8 @@ "SmtpHost": "", "SmtpPort": 587, "SmtpUser": "", - "SmtpPassword": "" + "SmtpPassword": "", + "SenderEmail": "" } }, "OfferSubscriptionProcess": { diff --git a/src/registration/Registration.Service/appsettings.json b/src/registration/Registration.Service/appsettings.json index febad90859..ca89b648f1 100644 --- a/src/registration/Registration.Service/appsettings.json +++ b/src/registration/Registration.Service/appsettings.json @@ -71,7 +71,8 @@ "SmtpHost": "", "SmtpPort": 587, "SmtpUser": "", - "SmtpPassword": "" + "SmtpPassword": "", + "SenderEmail": "" } }, "Keycloak": { diff --git a/tests/administration/Administration.Service.Tests/appsettings.IntegrationTests.json b/tests/administration/Administration.Service.Tests/appsettings.IntegrationTests.json index 1ac30245e6..9bb405b5d3 100644 --- a/tests/administration/Administration.Service.Tests/appsettings.IntegrationTests.json +++ b/tests/administration/Administration.Service.Tests/appsettings.IntegrationTests.json @@ -385,7 +385,8 @@ "SmtpHost": "test", "SmtpPort": 587, "SmtpUser": "test", - "SmtpPassword": "test" + "SmtpPassword": "test", + "SenderEmail": "test@example.org" } }, "IdentityProviderAdmin": { diff --git a/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json b/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json index 0b0e18cfbc..5744096c82 100644 --- a/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json +++ b/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json @@ -245,7 +245,8 @@ "SmtpHost": "test", "SmtpPort": 587, "SmtpUser": "test", - "SmtpPassword": "test" + "SmtpPassword": "test", + "SenderEmail": "test@example.org" } } } diff --git a/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json b/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json index b757ace250..6a81beed98 100644 --- a/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json +++ b/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json @@ -156,7 +156,8 @@ "SmtpHost": "test", "SmtpPort": 587, "SmtpUser": "test", - "SmtpPassword": "test" + "SmtpPassword": "test", + "SenderEmail": "test@example.org" } } }