Skip to content

Commit cd33f80

Browse files
Merge pull request #94 from yuessir/main
add sample
2 parents 80b92f1 + 60dfcc7 commit cd33f80

5 files changed

Lines changed: 116 additions & 1 deletion

File tree

FluentEmail.Graph.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
README.md = README.md
1818
EndProjectSection
1919
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{A4341B5B-E943-490B-94AE-D4637A7AF37C}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendMailSample", "sample\SendMailSample\SendMailSample.csproj", "{5C9C773B-43AF-475C-A56A-96CDA259D4D8}"
23+
EndProject
2024
Global
2125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2226
Debug|Any CPU = Debug|Any CPU
@@ -51,13 +55,26 @@ Global
5155
{B01998E7-3FE2-4A66-968A-0B7725309129}.Release|x64.Build.0 = Release|Any CPU
5256
{B01998E7-3FE2-4A66-968A-0B7725309129}.Release|x86.ActiveCfg = Release|Any CPU
5357
{B01998E7-3FE2-4A66-968A-0B7725309129}.Release|x86.Build.0 = Release|Any CPU
58+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|x64.ActiveCfg = Debug|Any CPU
61+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|x64.Build.0 = Debug|Any CPU
62+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|x86.ActiveCfg = Debug|Any CPU
63+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Debug|x86.Build.0 = Debug|Any CPU
64+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|x64.ActiveCfg = Release|Any CPU
67+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|x64.Build.0 = Release|Any CPU
68+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|x86.ActiveCfg = Release|Any CPU
69+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8}.Release|x86.Build.0 = Release|Any CPU
5470
EndGlobalSection
5571
GlobalSection(SolutionProperties) = preSolution
5672
HideSolutionNode = FALSE
5773
EndGlobalSection
5874
GlobalSection(NestedProjects) = preSolution
5975
{110F6221-F88C-44D8-B9E3-B3D1B9691DFD} = {D1C8192B-F35B-4433-9E5F-05F9E92DA58F}
6076
{B01998E7-3FE2-4A66-968A-0B7725309129} = {779D4366-494E-4582-ACDA-38D55AEC2EE5}
77+
{5C9C773B-43AF-475C-A56A-96CDA259D4D8} = {A4341B5B-E943-490B-94AE-D4637A7AF37C}
6178
EndGlobalSection
6279
GlobalSection(ExtensibilityGlobals) = postSolution
6380
SolutionGuid = {F11BF11A-54C0-49CA-B567-850A4C6AC40A}

sample/SendMailSample/Program.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using FluentEmail.Core;
3+
using FluentEmail.Core.Interfaces;
4+
using FluentEmail.Graph;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
8+
namespace SendMailSample
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
var services = new ServiceCollection();
15+
services.AddFluentEmail("user@user.com").AddGraphSender(Initial());
16+
services.AddScoped<IFluentEmail, Email>();
17+
var provider = services.BuildServiceProvider();
18+
19+
//get mail service
20+
var eamil = provider.GetRequiredService<IFluentEmail>();
21+
var sender = provider.GetRequiredService<ISender>();
22+
eamil.Sender = sender;
23+
24+
25+
eamil.SetFrom("user@user.com", "testGuy")
26+
.To("user@hotmail.com")
27+
.Subject("Test contact Email ")
28+
.Body(GetTestMailBody());
29+
eamil.Data.IsHtml = true;
30+
var response = eamil.Send();
31+
Console.ReadKey();
32+
33+
}
34+
35+
private static GraphSenderOptions Initial()
36+
{
37+
var config = new ConfigurationBuilder()
38+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
39+
40+
.Build();
41+
var graphSenderOptions = config
42+
.GetSection("GraphSenderOptions")
43+
.Get<GraphSenderOptions>();
44+
45+
return graphSenderOptions;
46+
}
47+
48+
private static string GetTestMailBody()
49+
{
50+
return @"<!DOCTYPE html>
51+
<html>
52+
<head>
53+
<meta charset=""utf-8"" />
54+
<title></title>
55+
</head>
56+
<body>
57+
Test mail ok<br/>
58+
<b>Bold text</b>
59+
</body>
60+
</html>";
61+
}
62+
}
63+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.23" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.23" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.23" />
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.23" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\src\FluentEmail.Graph\FluentEmail.Graph.csproj" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Update="appsettings.json">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"GraphSenderOptions": {
3+
"ClientId": "52b3b282-1dd8-41fe-8885-7cdb31b56bea",
4+
"TenantId": "75e18ae3-0902-4ac7-b716-7360d1282372",
5+
"Secret": "5D-7Q~rfRHqdL2m9PU_xDDgBQVtlK5i2Cznk0",
6+
"SaveSentItems": true
7+
}
8+
}

src/FluentEmail.Graph/FluentEmail.Graph.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0">
4242
<PrivateAssets>all</PrivateAssets>
4343
</PackageReference>
44-
<PackageReference Include="Microsoft.Graph" Version="4.24.0" />
44+
<PackageReference Include="Microsoft.Graph" Version="4.16.0" />
45+
<PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.7" />
46+
<PackageReference Include="Microsoft.Identity.Client" Version="4.43.0" />
4547
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
4648
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4749
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)