Skip to content

Commit ea5b87a

Browse files
πŸ”€ ✨ feat: add support for passing headers (#175)
* ✨ feat: add support for passing headers * codeql * update targets * test app * update packages * minver * minver * update action
1 parent 6d479fd commit ea5b87a

File tree

10 files changed

+37
-16
lines changed

10 files changed

+37
-16
lines changed

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
steps:
1818
- name: ☁ Checkout
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
2020
with:
2121
fetch-depth: 0
2222

β€Ž.github/workflows/codeql-analysis.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
steps:
4141
- name: Checkout repository
42-
uses: actions/checkout@v2
42+
uses: actions/checkout@v3
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL

β€Ž.github/workflows/publish.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: ☁ Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717
with:
1818
fetch-depth: 0
1919

β€Žsample/SendMailTestApp/Program.csβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static async Task Main(string[] args)
4747
.To(destinationAddress)
4848
.Subject("Test Email Graph API")
4949
.Body("This is the <b>body</b> of the mail.");
50+
email.Header("X-CustomHeader", "Some value");
5051
email.Data.IsHtml = true;
5152

5253
if (addAttachment)

β€Žsample/SendMailTestApp/README.mdβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Set up the config:
22

33
```
4+
cd sample
5+
cd SendMailTestApp
6+
47
dotnet user-secrets init
58
69
dotnet user-secrets set "GraphSenderOptions:TenantId" "your value"

β€Žsample/SendMailTestApp/SendMailTestApp.csprojβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<UserSecretsId>4eba8463-a290-440f-b079-62d74334211a</UserSecretsId>
9+
<LangVersion>latestmajor</LangVersion>
910
</PropertyGroup>
1011

1112
<ItemGroup>

β€Žsrc/FluentEmail.Graph/FluentEmail.Graph.csprojβ€Ž

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
<Version>0.0.1</Version>
2121
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2222
<MinVerVerbosity>detailed</MinVerVerbosity>
23-
<MinVerDefaultPreReleasePhase>preview</MinVerDefaultPreReleasePhase>
24-
<MinVerMinimumMajorMinor>2.0</MinVerMinimumMajorMinor>
23+
<MinVerMinimumMajorMinor>2.3</MinVerMinimumMajorMinor>
24+
<PackageReleaseNotes>v2.2 Added support for Headers
25+
v2.1 Added support for Inline images</PackageReleaseNotes>
2526
</PropertyGroup>
2627

2728
<ItemGroup>
@@ -43,15 +44,15 @@
4344
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4445
</PackageReference>
4546
<PackageReference Include="FluentEmail.Core" Version="3.0.2" />
46-
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0">
47+
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1">
4748
<PrivateAssets>all</PrivateAssets>
4849
</PackageReference>
4950
<PackageReference Include="Microsoft.Graph" Version="4.39.0" />
5051
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
5152
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5253
<PrivateAssets>all</PrivateAssets>
5354
</PackageReference>
54-
<PackageReference Include="MinVer" Version="4.2.0">
55+
<PackageReference Include="MinVer" Version="4.3.0">
5556
<PrivateAssets>all</PrivateAssets>
5657
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5758
</PackageReference>

β€Žsrc/FluentEmail.Graph/GraphSender.csβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
6464
}
6565
}
6666

67+
private static byte[] GetAttachmentBytes(Stream stream)
68+
{
69+
using var m = new MemoryStream();
70+
stream.CopyTo(m);
71+
72+
return m.ToArray();
73+
}
74+
6775
private async Task<Message> SendWithoutAttachments(IFluentEmail email)
6876
{
6977
// https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http
@@ -89,14 +97,6 @@ await this.graphClient.Users[email.Data.FromAddress.EmailAddress]
8997
return draftMessage;
9098
}
9199

92-
private static byte[] GetAttachmentBytes(Stream stream)
93-
{
94-
using var m = new MemoryStream();
95-
stream.CopyTo(m);
96-
97-
return m.ToArray();
98-
}
99-
100100
private async Task<Message> CreateDraftMessage(IFluentEmail email)
101101
{
102102
var template = MessageCreation.CreateGraphMessageFromFluentEmail(email);

β€Žsrc/FluentEmail.Graph/MessageCreation.csβ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ internal static Message CreateGraphMessageFromFluentEmail(IFluentEmail email)
2929
};
3030

3131
SetPriority(email, message);
32+
AddHeaders(email, message);
3233

3334
return message;
3435
}
@@ -82,4 +83,17 @@ private static void SetPriority(IFluentEmail email, Message draftMessage)
8283
break;
8384
}
8485
}
86+
87+
private static void AddHeaders(IFluentEmail email, Message message)
88+
{
89+
if (!email.Data.Headers.Any())
90+
{
91+
return;
92+
}
93+
94+
var headers = email.Data.Headers
95+
.Select(header => new InternetMessageHeader { Name = header.Key, Value = header.Value, })
96+
.ToList();
97+
message.InternetMessageHeaders = headers;
98+
}
8599
}

β€Žtests/FluentEmail.Graph.Tests/FluentEmail.Graph.Tests.csprojβ€Ž

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

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<EnableNETAnalyzers>true</EnableNETAnalyzers>
77
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
8+
<LangVersion>latestmajor</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>

0 commit comments

Comments
Β (0)