Skip to content
Open
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
8 changes: 6 additions & 2 deletions src/Senders/FluentEmail.Smtp/SmtpSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/FluentEmail.Core.Tests/FluentEmail.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<EmbeddedResource Include="test-embedded.txt" />
<None Update="Attachments\fluentemail_logo_64x64.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="logotest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
57 changes: 57 additions & 0 deletions test/FluentEmail.Core.Tests/SmtpSenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html><head></head><body><img src=\"cid:MyVeryCoolContentId\" /></body></html", true);


var response = await email.SendAsync();

Assert.IsTrue(response.Successful);
var files = Directory.EnumerateFiles(tempDirectory, "*.eml");
Assert.IsNotEmpty(files);
}

[Test]
public async Task CanSendEmailWithInlineImage()
{
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",
ContentId = "MyVeryCoolContentId"
};

var email = TestEmail
.Attach(attachment);

email.Body("<html><head></head><body><img src=\"cid:MyVeryCoolContentId\" /></body></html", true);


var response = await email.SendAsync();

Assert.IsTrue(response.Successful);
var files = Directory.EnumerateFiles(tempDirectory, "*.eml");
Assert.IsNotEmpty(files);
}

[Test]
public async Task CanSendAsyncHtmlAndPlaintextTogether()
{
Expand Down