From 61a59b4591cd0924d3e160ef4a67690d6cf81fa6 Mon Sep 17 00:00:00 2001 From: Aaron Sherber Date: Fri, 29 Mar 2024 19:54:33 -0400 Subject: [PATCH 1/2] Dispose of file stream in AttachFromFilename --- src/FluentEmail.Core/Email.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FluentEmail.Core/Email.cs b/src/FluentEmail.Core/Email.cs index 57142656..b13ed12c 100644 --- a/src/FluentEmail.Core/Email.cs +++ b/src/FluentEmail.Core/Email.cs @@ -461,7 +461,7 @@ public IFluentEmail Attach(IEnumerable attachments) public IFluentEmail AttachFromFilename(string filename, string contentType = null, string attachmentName = null) { - var stream = File.OpenRead(filename); + using var stream = File.OpenRead(filename); Attach(new Attachment { Data = stream, From 65317200059e185b7bdb482ea526b0fddfbd9dd3 Mon Sep 17 00:00:00 2001 From: Aaron Sherber Date: Sat, 30 Mar 2024 08:59:00 -0400 Subject: [PATCH 2/2] Use MemoryStream, which doesn't need to be disposed --- src/FluentEmail.Core/Email.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FluentEmail.Core/Email.cs b/src/FluentEmail.Core/Email.cs index b13ed12c..c066a94e 100644 --- a/src/FluentEmail.Core/Email.cs +++ b/src/FluentEmail.Core/Email.cs @@ -461,7 +461,7 @@ public IFluentEmail Attach(IEnumerable attachments) public IFluentEmail AttachFromFilename(string filename, string contentType = null, string attachmentName = null) { - using var stream = File.OpenRead(filename); + var stream = new MemoryStream(File.ReadAllBytes(filename)); Attach(new Attachment { Data = stream,