Skip to content

Commit

Permalink
fix: 🔊 Add email Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaneu committed Jan 13, 2024
1 parent 07c8459 commit cb97df6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions function/Service/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Newtonsoft.Json.Linq;
using Azure;
using Azure.Communication.Email;
using Microsoft.Extensions.Logging;
using System.Linq;

[assembly: InternalsVisibleTo("Surfrider.PlasticOrigins.Backend.Mobile.Tests")]
namespace Surfrider.PlasticOrigins.Backend.Mobile.Service
Expand All @@ -31,6 +33,8 @@ public interface IUserService

internal class UserService : IUserService
{
private readonly ILogger _log;

private readonly IUserStore _userStore;
private readonly int _defaultTokenValidityPeriod;
private readonly string _jwtTokenKey;
Expand All @@ -43,8 +47,9 @@ internal class UserService : IUserService
// TODO This is a hack. We should have something like a "FilesystemService"
public string BaseFunctionDirectory { get; set; }

public UserService(IUserStore userStore, IConfigurationService configurationService)
public UserService(IUserStore userStore, IConfigurationService configurationService, ILogger log)
{
_log = log;
_userStore = userStore ?? throw new ArgumentNullException(nameof(userStore));
_defaultTokenValidityPeriod = 60 * 48;
_jwtTokenKey = configurationService.GetValue(ConfigurationServiceWellKnownKeys.JwtTokenSignatureKey);
Expand Down Expand Up @@ -189,10 +194,11 @@ private string GenerateUserToken(string email, DateTime validityDate, string use

private async Task SendEmail(string to, string content, string textContent, string subject)
{

_log.LogInformation("Sending email: {subject}. Destination: {to}", subject, to.Take(4));
// If Azure ACS is configured, use this instead of Mailjet
if(!string.IsNullOrEmpty(_azureAcsConnectionString))
{
_log.LogInformation(" - Sending with Azure ACS");
await SendEmailAzureAcs(to, content, textContent, subject);
return;
}
Expand All @@ -203,6 +209,7 @@ private async Task SendEmail(string to, string content, string textContent, stri
return;
}

_log.LogInformation(" - Sending with Mailjet");
MailjetClient client = new MailjetClient(_mailJetApiKey,_mailjetApiSecret)
{
Version = ApiVersion.V3_1,
Expand Down Expand Up @@ -262,6 +269,8 @@ private async Task SendEmailAzureAcs(string to, string content, string textConte
to,
subject,
content);

_log.LogInformation(" - Mail Sent. OperationID: {}", emailSendOperation.Id);
}

internal static string InternalGenerateUserToken(string email, DateTime validityDate, string userId, string signatureKey, bool isValidationEmail)
Expand Down

0 comments on commit cb97df6

Please sign in to comment.