Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mailing): make sender email configurable #439

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/administration/Administration.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
"SmtpHost": "",
"SmtpPort": 587,
"SmtpUser": "",
"SmtpPassword": ""
"SmtpPassword": "",
"SenderEmail": ""
}
},
"IdentityProviderAdmin": {
Expand Down
8 changes: 6 additions & 2 deletions src/mailing/Mailing.SendMail/MailSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MailSettings>()
.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));
Expand All @@ -48,7 +52,7 @@ public bool Validate()
}
}

public static class MailSettingsExtention
public static class MailSettingsExtension
{
public static IServiceCollection ConfigureMailSettings(
this IServiceCollection services,
Expand Down
80 changes: 40 additions & 40 deletions src/mailing/Mailing.SendMail/Mailing.SendMail.csproj
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<!--
- Copyright (c) 2021, 2023 BMW Group AG
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
-
- See the NOTICE file(s) distributed with this work for additional
- information regarding copyright ownership.
-
- This program and the accompanying materials are made available under the
- terms of the Apache License, Version 2.0 which is available at
- https://www.apache.org/licenses/LICENSE-2.0.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- License for the specific language governing permissions and limitations
- under the License.
-
- SPDX-License-Identifier: Apache-2.0
-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail</AssemblyName>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="MimeKit" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\Framework.ErrorHandling\Framework.ErrorHandling.csproj" />
<ProjectReference Include="..\Mailing.Template\Mailing.Template.csproj" />
</ItemGroup>
</Project>
<!--
- Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
-
- See the NOTICE file(s) distributed with this work for additional
- information regarding copyright ownership.
-
- This program and the accompanying materials are made available under the
- terms of the Apache License, Version 2.0 which is available at
- https://www.apache.org/licenses/LICENSE-2.0.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- License for the specific language governing permissions and limitations
- under the License.
-
- SPDX-License-Identifier: Apache-2.0
-->

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail</AssemblyName>
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.Mailing.SendMail</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="MimeKit" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\framework\Framework.ErrorHandling\Framework.ErrorHandling.csproj" />
<ProjectReference Include="..\Mailing.Template\Mailing.Template.csproj" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/mailing/Mailing.SendMail/MailingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,19 +27,21 @@ 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<MailSettings> options)
{
_templateManager = templateManager;
_sendMail = sendMail;
_settings = options.Value;
}

public async Task SendMails(string recipient, IDictionary<string, string> parameters, IEnumerable<string> templates)
{
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);
}
}
}
3 changes: 2 additions & 1 deletion src/marketplace/Apps.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"SmtpHost": "",
"SmtpPort": 587,
"SmtpUser": "",
"SmtpPassword": ""
"SmtpPassword": "",
"SenderEmail": ""
}
},
"Provisioning": {
Expand Down
3 changes: 2 additions & 1 deletion src/marketplace/Services.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"SmtpHost": "",
"SmtpPort": 587,
"SmtpUser": "",
"SmtpPassword": ""
"SmtpPassword": "",
"SenderEmail": ""
}
},
"Provisioning": {
Expand Down
3 changes: 2 additions & 1 deletion src/processes/Processes.Worker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@
"SmtpHost": "",
"SmtpPort": 587,
"SmtpUser": "",
"SmtpPassword": ""
"SmtpPassword": "",
"SenderEmail": ""
}
},
"OfferSubscriptionProcess": {
Expand Down
3 changes: 2 additions & 1 deletion src/registration/Registration.Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"SmtpHost": "",
"SmtpPort": 587,
"SmtpUser": "",
"SmtpPassword": ""
"SmtpPassword": "",
"SenderEmail": ""
}
},
"Keycloak": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@
"SmtpHost": "test",
"SmtpPort": 587,
"SmtpUser": "test",
"SmtpPassword": "test"
"SmtpPassword": "test",
"SenderEmail": "test@example.org"
}
},
"IdentityProviderAdmin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@
"SmtpHost": "test",
"SmtpPort": 587,
"SmtpUser": "test",
"SmtpPassword": "test"
"SmtpPassword": "test",
"SenderEmail": "test@example.org"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"SmtpHost": "test",
"SmtpPort": 587,
"SmtpUser": "test",
"SmtpPassword": "test"
"SmtpPassword": "test",
"SenderEmail": "test@example.org"
}
}
}
Loading