@@ -138,11 +138,12 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
138138 _ => 3
139139 } ) . ToString ( ) ) ;
140140
141+ string messageId = null ;
141142
142143 try
143144 {
144145 EmailSendOperation sendOperation = await _emailClient . SendAsync ( WaitUntil . Started , emailMessage , token ?? CancellationToken . None ) ;
145- var messageId = sendOperation . Id ;
146+ messageId = sendOperation . Id ;
146147 if ( string . IsNullOrWhiteSpace ( messageId ) )
147148 {
148149 return new SendResponse
@@ -153,10 +154,10 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
153154
154155 // We want to verify that the email was sent.
155156 // The maximum time we will wait for the message status to be sent/delivered is 2 minutes.
156- var cancellationToken = new CancellationTokenSource ( TimeSpan . FromMinutes ( 2 ) ) ;
157- var sendStatusResult = sendOperation . WaitForCompletion ( cancellationToken . Token ) . Value ;
157+ using var cancellationToken = new CancellationTokenSource ( TimeSpan . FromMinutes ( 2 ) ) ;
158+ var sendStatusResult = await sendOperation . WaitForCompletionAsync ( cancellationToken . Token ) ;
158159
159- if ( sendStatusResult . Status == EmailSendStatus . Succeeded )
160+ if ( sendStatusResult . Value . Status == EmailSendStatus . Succeeded )
160161 {
161162 return new SendResponse
162163 {
@@ -168,19 +169,22 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
168169 {
169170 return new SendResponse
170171 {
172+ MessageId = messageId ,
171173 ErrorMessages = new List < string > { "Failed to send email, timed out while getting status." }
172174 } ;
173175 }
174176
175177 return new SendResponse
176178 {
179+ MessageId = messageId ,
177180 ErrorMessages = new List < string > { "Failed to send email." }
178181 } ;
179182 }
180183 catch ( Exception ex )
181184 {
182185 return new SendResponse
183186 {
187+ MessageId = messageId ,
184188 ErrorMessages = new List < string > { ex . Message }
185189 } ;
186190 }
0 commit comments