YGGraphMail 1.0.0
See the version list below for details.
dotnet add package YGGraphMail --version 1.0.0
NuGet\Install-Package YGGraphMail -Version 1.0.0
<PackageReference Include="YGGraphMail" Version="1.0.0" />
paket add YGGraphMail --version 1.0.0
#r "nuget: YGGraphMail, 1.0.0"
// Install YGGraphMail as a Cake Addin #addin nuget:?package=YGGraphMail&version=1.0.0 // Install YGGraphMail as a Cake Tool #tool nuget:?package=YGGraphMail&version=1.0.0
YGSendMail
A simple email sending functionality that uses Microsoft Graph to connect, authenticate, build and send the emails
Installation
Include this package in the project file
Be sure to setup your Corporate email in Azure Portal, obtain Graph TenantId and ClientId,
and enable "Mail.Send" scope in App Registration
Usage
Console:
OAuth2DTO oauth2DTO = new OAuth2DTO()
{
ClientId = clientId,
TenantId = tenantId,
UserName = username,
Password = password
};
IGraphEmail ge = new GraphEmail(oauth2DTO, tokenFile);
ge.OnError += Ge_OnError;
void Ge_OnError(string c, string m, Exception ex)
{
Console.WriteLine($"Error at {c}.{m}. Error message: {ex.Message}");
}
GraphSendEmailDTO eml = new GraphSendEmailDTO()
{
To = new string[] { recipient },
Subject = subject,
Body = body
};
string result = await ge.SendEmailAsync(eml);
Console.WriteLine($"Email result: {result}");
Web:
OAuth2DTO oauth2DTO = new OAuth2DTO()
{
ClientId = clientId,
TenantId = tenantId,
UserName = username,
Password = password
};
IGraphEmailWeb ge = new GraphEmailWeb(oauth2DTO, new string[] { "Mail.Send" });
ge.OnGEWebError += Ge_OnError;
GraphSendEmailDTO eml = new GraphSendEmailDTO()
{
To = new string[] { recipient },
Subject = subject,
Body = body
};
result = await ge.SendEmailAsync(eml);
return Ok($"Email send result: {result}");
void Ge_OnError(string c, string m, Exception ex)
{
_logger.LogError($"Error at {c}.{m}. Error message: {ex.Message}");
}
Attachments and LinkedResources can be added in eml object Attachments and LinkedResources can be filenames or filenames and byte[] contents
Examples
Test project is provided in the solution to illustrate how instantiate and invoke the email sending functionality
Output:
The output is a string. If there is any error, the output will show the error
Dependencies
Microsoft.Graph
Microsoft.Identity.Client
MimeKit
Newtonsoft.Json
Contributing
Any new ideas on how to enhance this class without adding much complexity, please adhere to SOLID principle
License
This project is licensed under the MIT License(LICENSE).
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Graph (>= 5.53.0)
- Microsoft.Identity.Client (>= 4.61.0)
- MimeKit (>= 4.5.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial Release