Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/FluentEmail.Core/Models/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace FluentEmail.Core.Models
{
public class Attachment
{
/// <summary>
/// Gets or sets whether the attachment is intended to be used for inline images (changes the paramater name for providers such as MailGun)
/// </summary>
public bool IsInline { get; set; }
public string Filename { get; set; }
public Stream Data { get; set; }
public string ContentType { get; set; }
Expand Down
9 changes: 8 additions & 1 deletion src/Senders/FluentEmail.Mailgun/MailgunSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public async Task<SendResponse> SendAsync(Email email, CancellationToken? token
var files = new List<HttpFile>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<PackageId>FluentEmail.Mailgun.Tests</PackageId>
</PropertyGroup>

<ItemGroup>
<None Remove="logotest.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="logotest.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170502-03" />
<PackageReference Include="NUnit" Version="3.6.1" />
Expand Down
31 changes: 31 additions & 0 deletions test/FluentEmail.Mailgun.Tests/MailgunSenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using FluentEmail.Core;
using FluentEmail.Core.Models;
using NUnit.Framework;
using System.Reflection;

namespace FluentEmail.Mailgun.Tests
{
Expand Down Expand Up @@ -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("<html>Inline image here: <img src=\"cid:logotest.png\">" +
"<p>You should see an image without an attachment, or without a download prompt, dependig on the email client.</p></html>", true)
.Attach(attachment);

var response = await email.SendAsync();

Assert.IsTrue(response.Successful);
}
}
}
Binary file added test/FluentEmail.Mailgun.Tests/logotest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.