11using CCE . Application . Common . Interfaces ;
2+ using CCE . Infrastructure . Email ;
23using CCE . Integration . Communication ;
34using Microsoft . Extensions . Logging ;
5+ using Microsoft . Extensions . Options ;
46
57namespace CCE . Infrastructure . Communication ;
68
@@ -11,20 +13,31 @@ namespace CCE.Infrastructure.Communication;
1113public sealed class GatewayEmailSender : IEmailSender
1214{
1315 private readonly ICommunicationGatewayClient _client ;
16+ private readonly IOptions < EmailOptions > _options ;
1417 private readonly ILogger < GatewayEmailSender > _logger ;
1518
16- public GatewayEmailSender ( ICommunicationGatewayClient client , ILogger < GatewayEmailSender > logger )
19+ public GatewayEmailSender (
20+ ICommunicationGatewayClient client ,
21+ IOptions < EmailOptions > options ,
22+ ILogger < GatewayEmailSender > logger )
1723 {
1824 _client = client ;
25+ _options = options ;
1926 _logger = logger ;
2027 }
2128
22- public async Task SendAsync ( string to , string subject , string htmlBody , CancellationToken ct = default )
29+ public async Task SendAsync ( string to , string subject , string htmlBody , string ? templateId = null , CancellationToken ct = default )
2330 {
24- var request = new SendEmailRequest ( to , subject , htmlBody ) ;
31+ var request = new SendEmailRequest (
32+ To : to ,
33+ From : _options . Value . FromAddress ,
34+ Subject : subject ,
35+ Html : htmlBody ,
36+ TemplateId : templateId ) ;
37+
2538 var response = await _client . SendEmailAsync ( request , ct ) . ConfigureAwait ( false ) ;
2639
27- if ( ! response . Success )
40+ if ( ! "success" . Equals ( response . Status , StringComparison . OrdinalIgnoreCase ) )
2841 {
2942 _logger . LogError (
3043 "Gateway email send failed for {To} with subject {Subject}: {Error}" ,
@@ -33,7 +46,7 @@ public async Task SendAsync(string to, string subject, string htmlBody, Cancella
3346 }
3447
3548 _logger . LogInformation (
36- "Sent email via gateway to {To} with subject {Subject} (messageId {MessageId })" ,
37- to , subject , response . MessageId ) ;
49+ "Sent email via gateway to {To} with subject {Subject} (id {Id })" ,
50+ to , subject , response . Id ) ;
3851 }
3952}
0 commit comments