Skip to content

Commit 4fdb239

Browse files
authored
Merge branch 'master' into fix/420-exception-cron-entry-00-is-malformed
2 parents a12031a + bd68505 commit 4fdb239

File tree

10 files changed

+48
-44
lines changed

10 files changed

+48
-44
lines changed

.github/workflows/dotnet.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,6 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
build_and_tests_on_dotnet_6:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v3
14-
- name: Setup .NET
15-
uses: actions/setup-dotnet@v3
16-
with:
17-
dotnet-version: 6.0.x
18-
- name: Restore dependencies
19-
run: dotnet restore ./Src/All.sln
20-
- name: Build
21-
run: dotnet build ./Src/All.sln
22-
- name: Mailer Tests
23-
run: dotnet test ./Src/UnitTests/MailerUnitTests/MailerUnitTests.csproj
24-
- name: Unit Tests
25-
run: dotnet test ./Src/UnitTests/CoravelUnitTests/CoravelUnitTests.csproj
26-
- name: Integration Tests
27-
run: dotnet test ./Src/IntegrationTests/Tests/Tests.csproj
28-
build_and_tests_on_dotnet_7:
29-
runs-on: ubuntu-latest
30-
steps:
31-
- uses: actions/checkout@v3
32-
- name: Setup .NET
33-
uses: actions/setup-dotnet@v3
34-
with:
35-
dotnet-version: 7.0.x
36-
- name: Restore dependencies
37-
run: dotnet restore ./Src/All.sln
38-
- name: Build
39-
run: dotnet build ./Src/All.sln
40-
- name: Mailer Tests
41-
run: dotnet test ./Src/UnitTests/MailerUnitTests/MailerUnitTests.csproj
42-
- name: Unit Tests
43-
run: dotnet test ./Src/UnitTests/CoravelUnitTests/CoravelUnitTests.csproj
44-
- name: Integration Tests
45-
run: dotnet test ./Src/IntegrationTests/Tests/Tests.csproj
4610
build_and_tests_on_dotnet_8:
4711
runs-on: ubuntu-latest
4812
steps:

Demo/Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
66
<AddRazorSupportForMvc>True</AddRazorSupportForMvc>
77
</PropertyGroup>

DocsV2/docs/Mailing/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,36 @@ Sender("test@test.com")
345345

346346
Attach multiple files by passing an `Attachment` to the `Attach()` method.
347347

348+
Each attachment has a few fields to assign:
349+
350+
- `Bytes`: The `byte[]` of the file you are attaching.
351+
- `Name`: The name of the file to attach.
352+
- `ContentId`: Often used for embedding images into emails. Assign a value that is unique within your email template.
353+
354+
##### Embedding Images
355+
356+
To embed images into your email you can assign the `ContentId` field with a unique value that will also be used in your email.
357+
358+
For example:
359+
360+
```csharp
361+
emailMessage
362+
.Attach(new Attachment
363+
{
364+
Name = "My Image",
365+
Bytes = myBytes,
366+
ContentId = "my-image"
367+
});
368+
```
369+
370+
```html
371+
<html>
372+
<img src="cid:my-image" />
373+
</html>
374+
```
375+
376+
Coravel will automatically link the embedded resources to the email properly for you.
377+
348378
#### Auto-Detect Email Address And Name
349379

350380
Using an `object` that has a `public` field or property `Email` and `Name`, you can pass it to the `To()` method.

Src/Coravel.Mailer/Coravel.Mailer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>.net6.0</TargetFramework>
55
<AddRazorSupportForMvc>True</AddRazorSupportForMvc>
66
<PackageId>Coravel.Mailer</PackageId>
7-
<Version>7.0.0</Version>
7+
<Version>7.1.0</Version>
88
<Authors>James Hickey</Authors>
99
<Company>-</Company>
1010
<Title>Coravel.Mailer</Title>

Src/Coravel.Mailer/Mail/Attachment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Coravel.Mailer.Mail
33
public class Attachment
44
{
55
public byte[] Bytes { get; set; }
6-
public string Name { get; set; }
6+
public string Name { get; set; }
7+
public string ContentId { get; set; }
78
}
89
}

Src/Coravel.Mailer/Mail/Mailers/SmtpMailer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ private static void SetMailBody(MessageBody message, IEnumerable<Attachment> att
8989
{
9090
foreach (var attachment in attachments)
9191
{
92-
bodyBuilder.Attachments.Add(attachment.Name, attachment.Bytes);
92+
if (string.IsNullOrWhiteSpace(attachment.ContentId) == false)
93+
{
94+
var image = bodyBuilder.LinkedResources.Add(attachment.Name, attachment.Bytes);
95+
// We do this instead of using their value because RFC states the Content-Id value MUST be in the message id format.
96+
image.ContentId = MimeKit.Utils.MimeUtils.GenerateMessageId();
97+
// Now replace where they applied it in the html template with the updated correct version
98+
bodyBuilder.HtmlBody = bodyBuilder.HtmlBody.Replace($"\"cid:{attachment.ContentId}\"", $"\"cid:{image.ContentId}\"", System.StringComparison.OrdinalIgnoreCase);
99+
}
100+
else
101+
bodyBuilder.Attachments.Add(attachment.Name, attachment.Bytes);
93102
}
94103
}
95104

Src/IntegrationTests/TestMvcApp/TestMvcApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>.net6.0</TargetFramework>
4+
<TargetFramework>.net8.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

Src/IntegrationTests/Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>.net6.0</TargetFramework>
4+
<TargetFramework>.net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

Src/UnitTests/CoravelUnitTests/CoravelUnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>.net6.0</TargetFramework>
4+
<TargetFramework>.net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

Src/UnitTests/MailerUnitTests/MailerUnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>.net6.0</TargetFramework>
4+
<TargetFramework>.net8.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

0 commit comments

Comments
 (0)