diff --git a/src/FluentEmail.Core/Models/Attachment.cs b/src/FluentEmail.Core/Models/Attachment.cs index deb1fa1d..292adddd 100644 --- a/src/FluentEmail.Core/Models/Attachment.cs +++ b/src/FluentEmail.Core/Models/Attachment.cs @@ -8,6 +8,10 @@ namespace FluentEmail.Core.Models { public class Attachment { + /// + /// Gets or sets whether the attachment is intended to be used for inline images (changes the paramater name for providers such as MailGun) + /// + public bool IsInline { get; set; } public string Filename { get; set; } public Stream Data { get; set; } public string ContentType { get; set; } diff --git a/src/Senders/FluentEmail.Mailgun/MailgunSender.cs b/src/Senders/FluentEmail.Mailgun/MailgunSender.cs index 07f0b26c..15db549c 100644 --- a/src/Senders/FluentEmail.Mailgun/MailgunSender.cs +++ b/src/Senders/FluentEmail.Mailgun/MailgunSender.cs @@ -63,9 +63,16 @@ public async Task SendAsync(Email email, CancellationToken? token var files = new List(); email.Data.Attachments.ForEach(x => { + string param; + + if (x.IsInline) + param = "inline"; + else + param = "attachment"; + files.Add(new HttpFile() { - ParameterName = "attachment", + ParameterName = param, Data = x.Data, Filename = x.Filename, ContentType = x.ContentType diff --git a/test/FluentEmail.Mailgun.Tests/FluentEmail.Mailgun.Tests.csproj b/test/FluentEmail.Mailgun.Tests/FluentEmail.Mailgun.Tests.csproj index 307b28db..aea73549 100644 --- a/test/FluentEmail.Mailgun.Tests/FluentEmail.Mailgun.Tests.csproj +++ b/test/FluentEmail.Mailgun.Tests/FluentEmail.Mailgun.Tests.csproj @@ -6,6 +6,14 @@ FluentEmail.Mailgun.Tests + + + + + + + + diff --git a/test/FluentEmail.Mailgun.Tests/MailgunSenderTests.cs b/test/FluentEmail.Mailgun.Tests/MailgunSenderTests.cs index 103b400e..ac45a795 100644 --- a/test/FluentEmail.Mailgun.Tests/MailgunSenderTests.cs +++ b/test/FluentEmail.Mailgun.Tests/MailgunSenderTests.cs @@ -3,6 +3,7 @@ using FluentEmail.Core; using FluentEmail.Core.Models; using NUnit.Framework; +using System.Reflection; namespace FluentEmail.Mailgun.Tests { @@ -61,5 +62,35 @@ public async Task CanSendEmailWithAttachments() Assert.IsTrue(response.Successful); } + + [Test] + public async Task CanSendEmailWithInlineImages() + { + var assembly = Assembly.GetExecutingAssembly(); + var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".logotest.png"); + stream.Flush(); + + stream.Seek(0, SeekOrigin.Begin); + + var attachment = new Attachment() + { + IsInline = true, + Data = stream, + ContentType = "image/png", + Filename = "logotest.png" + }; + + var email = Email + .From(fromEmail) + .To(toEmail) + .Subject(subject) + .Body("Inline image here: " + + "

You should see an image without an attachment, or without a download prompt, dependig on the email client.

", true) + .Attach(attachment); + + var response = await email.SendAsync(); + + Assert.IsTrue(response.Successful); + } } } \ No newline at end of file diff --git a/test/FluentEmail.Mailgun.Tests/logotest.png b/test/FluentEmail.Mailgun.Tests/logotest.png new file mode 100644 index 00000000..c8261fce Binary files /dev/null and b/test/FluentEmail.Mailgun.Tests/logotest.png differ