Skip to content

Commit 3357ac1

Browse files
Ensure SmtpClient is disconnected after sending the email (#79)
* Ensure SmtpClient is disconnected after sending the email * Update upload-artifact to v4
1 parent 5fec1dc commit 3357ac1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

.github/workflows/check-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
--logger "trx;logfileprefix=tr"
4545

4646
- name: "Publish Solution Test Results"
47-
uses: actions/upload-artifact@v3
47+
uses: actions/upload-artifact@v4
4848
if: success() || failure()
4949
with:
5050
name: "test-results"

src/OneBeyond.Studio.EmailProviders.Smtp/EmailSender.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public void Dispose()
114114
exception,
115115
"Unable to send message via SmptClient {SmtpClientId}. Disconnecting the client before releasing it",
116116
smtpClient.Id);
117-
await smtpClient.Value.DisconnectAsync(true, cancellationToken).ConfigureAwait(false);
118117

119118
throw new EmailSenderException("Unable to send message via SmptClient { SmtpClientId }.Disconnecting the client before releasing it.", exception);
120119
}
@@ -173,12 +172,13 @@ private async Task ReleaseSmtpClientAsync(
173172
(int Id, MailKit.Net.Smtp.SmtpClient Value) smtpClient,
174173
CancellationToken cancellationToken)
175174
{
175+
await smtpClient.Value.DisconnectAsync(true, cancellationToken).ConfigureAwait(false);
176+
176177
// Only SmtpClients created before threshold are returned into the queue for later re-use,
177178
// all the others get decommissioned. Another option that SmtpClient gets returned regardless its id
178179
// provided the queue count is less than the threshold.
179180
if (smtpClient.Id > SmtpClientsMaxCount)
180181
{
181-
await smtpClient.Value.DisconnectAsync(true, cancellationToken).ConfigureAwait(false);
182182
smtpClient.Value.Dispose();
183183
}
184184
else

0 commit comments

Comments
 (0)