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 00000000..1aab18dc Binary files /dev/null and b/test/FluentEmail.Core.Tests/Attachments/fluentemail_logo_64x64.png differ diff --git a/test/FluentEmail.Core.Tests/FluentEmail.Core.Tests.csproj b/test/FluentEmail.Core.Tests/FluentEmail.Core.Tests.csproj index cc26ca67..fc3ed0cb 100644 --- a/test/FluentEmail.Core.Tests/FluentEmail.Core.Tests.csproj +++ b/test/FluentEmail.Core.Tests/FluentEmail.Core.Tests.csproj @@ -30,6 +30,9 @@ PreserveNewest + + 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("