aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/Services/MailService.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-10-01 10:46:31 +0200
committerivarlovlie <git@ivarlovlie.no>2022-10-01 10:46:31 +0200
commite56d469e9fe865d8b423e1bdf5c3b872ee2319d8 (patch)
tree98f8efbc5812971cbac4cc547e47af14c165b6dd /server/src/Services/MailService.cs
parentdc0d24a3c556e633ec86d82730e8f04d2326c436 (diff)
downloadgreatoffice-e56d469e9fe865d8b423e1bdf5c3b872ee2319d8.tar.xz
greatoffice-e56d469e9fe865d8b423e1bdf5c3b872ee2319d8.zip
refactor: Minor changes
Diffstat (limited to 'server/src/Services/MailService.cs')
-rw-r--r--server/src/Services/MailService.cs85
1 files changed, 42 insertions, 43 deletions
diff --git a/server/src/Services/MailService.cs b/server/src/Services/MailService.cs
index a64d203..c08cb84 100644
--- a/server/src/Services/MailService.cs
+++ b/server/src/Services/MailService.cs
@@ -1,50 +1,49 @@
-using Microsoft.Extensions.Options;
-
namespace IOL.GreatOffice.Api.Services;
public class MailService
{
- private readonly ILogger<MailService> _logger;
- private static string _emailHost;
- private static int _emailPort;
- private static string _emailUser;
- private static string _emailPassword;
+ private readonly ILogger<MailService> _logger;
+ private static string _emailHost;
+ private static int _emailPort;
+ private static string _emailUser;
+ private static string _emailPassword;
- public MailService(VaultService vaultService, ILogger<MailService> logger) {
- var configuration = vaultService.GetCurrentAppConfiguration();
- _logger = logger;
- _emailHost = configuration.SMTP_HOST;
- _emailPort = Convert.ToInt32(configuration.SMTP_PORT);
- _emailUser = configuration.SMTP_USER;
- _emailPassword = configuration.SMTP_PASSWORD;
- }
+ public MailService(VaultService vaultService, ILogger<MailService> logger) {
+ var configuration = vaultService.GetCurrentAppConfiguration();
+ _logger = logger;
+ _emailHost = configuration.SMTP_HOST;
+ _emailPort = Convert.ToInt32(configuration.SMTP_PORT);
+ _emailUser = configuration.SMTP_USER;
+ _emailPassword = configuration.SMTP_PASSWORD;
+ }
- /// <summary>
- /// Send an email.
- /// </summary>
- /// <param name="message"></param>
- public void SendMail(MailMessage message) {
- using var smtpClient = new SmtpClient {
- Host = _emailHost,
- EnableSsl = _emailPort == 587,
- Port = _emailPort,
- Credentials = new NetworkCredential {
- UserName = _emailUser,
- Password = _emailPassword,
- }
- };
- var configurationString = JsonSerializer.Serialize(new {
- Host = smtpClient.Host,
- EnableSsl = smtpClient.EnableSsl,
- Port = smtpClient.Port,
- UserName = _emailUser.HasValue() ? "**REDACTED**" : "**MISSING**",
- Password = _emailPassword.HasValue() ? "**REDACTED**" : "**MISSING**",
- },
- new JsonSerializerOptions {
- WriteIndented = true
- });
- _logger.LogDebug("SmtpClient was instansiated with the following configuration\n" + configurationString);
+ /// <summary>
+ /// Send an email.
+ /// </summary>
+ /// <param name="message"></param>
+ public void SendMail(MailMessage message) {
+ using var smtpClient = new SmtpClient {
+ Host = _emailHost,
+ EnableSsl = _emailPort == 587,
+ Port = _emailPort,
+ Credentials = new NetworkCredential {
+ UserName = _emailUser,
+ Password = _emailPassword,
+ }
+ };
+ var configurationString = JsonSerializer.Serialize(new {
+ smtpClient.Host,
+ smtpClient.EnableSsl,
+ smtpClient.Port,
+ UserName = _emailUser.HasValue() ? "**REDACTED**" : "**MISSING**",
+ Password = _emailPassword.HasValue() ? "**REDACTED**" : "**MISSING**",
+ },
+ new JsonSerializerOptions {
+ WriteIndented = true
+ });
+
+ _logger.LogDebug("SmtpClient was instansiated with the following configuration\n" + configurationString);
- smtpClient.Send(message);
- }
-}
+ smtpClient.Send(message);
+ }
+} \ No newline at end of file