-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f77710
commit 582a178
Showing
7 changed files
with
1,248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ations/20230913185146_Initial.Designer.cs → ...ations/20230921212309_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Azure; | ||
using Microsoft.AspNetCore.Identity.UI.Services; | ||
using Azure.Communication.Email; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace MixyBoos.Api.Services.Helpers; | ||
|
||
public class ARMMailSender : IEmailSender { | ||
private readonly IConfiguration _config; | ||
private readonly ILogger<ARMMailSender> _logger; | ||
|
||
public ARMMailSender(IConfiguration config, ILogger<ARMMailSender> logger) { | ||
_config = config; | ||
_logger = logger; | ||
} | ||
|
||
public async Task SendEmailAsync(string email, string subject, string htmlMessage) { | ||
try { | ||
var connectionString = _config["Email:ARMKey"]; | ||
if (string.IsNullOrEmpty(connectionString)) { | ||
throw new InvalidOperationException("ARM key is missing"); | ||
} | ||
|
||
var client = new EmailClient(connectionString); | ||
var operation = await client.SendAsync( | ||
wait: WaitUntil.Completed, | ||
senderAddress: _config["Email:FromAddress"].ToString(), | ||
recipientAddress: email, | ||
subject: subject, | ||
htmlContent: htmlMessage | ||
); | ||
_logger.LogDebug( | ||
"Send email to {Email} with subject {Subject} with tracking id {TrackingId}", | ||
email, | ||
subject, | ||
operation?.Id); | ||
} catch (Exception e) { | ||
_logger.LogError("Error sending email {Error}", e.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters