From 7125b8713233cde760bf1a43a38fa91eb2b8e9c1 Mon Sep 17 00:00:00 2001 From: Wilko van der Veen Date: Tue, 26 Apr 2022 15:17:55 +0200 Subject: [PATCH] Fix missing inline option for smtp mailer and added some unit tests for this change. --- src/Senders/FluentEmail.Smtp/SmtpSender.cs | 8 ++- .../Attachments/fluentemail_logo_64x64.png | Bin 0 -> 20822 bytes .../FluentEmail.Core.Tests.csproj | 3 + .../FluentEmail.Core.Tests/SmtpSenderTests.cs | 57 ++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/FluentEmail.Core.Tests/Attachments/fluentemail_logo_64x64.png diff --git a/src/Senders/FluentEmail.Smtp/SmtpSender.cs b/src/Senders/FluentEmail.Smtp/SmtpSender.cs index 4b13d288..6d214370 100644 --- a/src/Senders/FluentEmail.Smtp/SmtpSender.cs +++ b/src/Senders/FluentEmail.Smtp/SmtpSender.cs @@ -3,6 +3,7 @@ using FluentEmail.Core.Models; using System; using System.Net.Mail; +using System.Net.Mime; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -146,9 +147,12 @@ private MailMessage CreateMailMessage(IFluentEmail email) data.Attachments.ForEach(x => { - System.Net.Mail.Attachment a = new System.Net.Mail.Attachment(x.Data, x.Filename, x.ContentType); + System.Net.Mail.Attachment a = new System.Net.Mail.Attachment(x.Data, x.Filename, x.ContentType) + { + ContentId = x.ContentId + }; - a.ContentId = x.ContentId; + a.ContentDisposition.Inline = x.IsInline; message.Attachments.Add(a); }); diff --git a/test/FluentEmail.Core.Tests/Attachments/fluentemail_logo_64x64.png b/test/FluentEmail.Core.Tests/Attachments/fluentemail_logo_64x64.png new file mode 100644 index 0000000000000000000000000000000000000000..1aab18dc4cbc1380fdf9f5c4057f28a3878416f3 GIT binary patch literal 20822 zcmeI42{_bW+sA*F>>*3aQe$bcjG19(WE(QpY}vAvjF~aUHp5JIHAK;3%^oS0B1%dL zHB^LBR4RKRslO#EZFom&^6%gOdFOeb=Y8Jmy{?(-V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&j=!0R=Gu`ttbNkf_R_o{5`U#`Yw^?8w<5^p#_t zHN6>1#YK(@@!T?}+`OM(ZB-17v(E!)Qm0xUBKIMN>6A_5ouA#k&e{TEE#3);9%+n+ z@&&P`=;G^wNCcPreserveNewest + + Always + PreserveNewest diff --git a/test/FluentEmail.Core.Tests/SmtpSenderTests.cs b/test/FluentEmail.Core.Tests/SmtpSenderTests.cs index 8fca3c39..64625d90 100644 --- a/test/FluentEmail.Core.Tests/SmtpSenderTests.cs +++ b/test/FluentEmail.Core.Tests/SmtpSenderTests.cs @@ -90,6 +90,63 @@ public async Task CanSendEmailWithAttachments() Assert.IsNotEmpty(files); } + [Test] + public async Task CanSendEmailWithInlineImageAndAttachments() + { + var stream = File.OpenRead(@"C:\Users\wilko.vanderveen\source\repos\FluentEmail\test\FluentEmail.Core.Tests\Attachments\fluentemail_logo_64x64.png"); + + stream.Seek(0, SeekOrigin.Begin); + + var attachment = new Attachment + { + IsInline = true, + Data = stream, + ContentType = "image/png", + Filename = "fluentemail-logo.png", + ContentId = "MyVeryCoolContentId" + }; + + var email = TestEmail + .Attach(attachment); + + email.Body("