GraphEmailClient 1.0.4
dotnet add package GraphEmailClient --version 1.0.4
NuGet\Install-Package GraphEmailClient -Version 1.0.4
<PackageReference Include="GraphEmailClient" Version="1.0.4" />
<PackageVersion Include="GraphEmailClient" Version="1.0.4" />
<PackageReference Include="GraphEmailClient" />
paket add GraphEmailClient --version 1.0.4
#r "nuget: GraphEmailClient, 1.0.4"
#:package GraphEmailClient@1.0.4
#addin nuget:?package=GraphEmailClient&version=1.0.4
#tool nuget:?package=GraphEmailClient&version=1.0.4
GraphEmailClient
GraphEmailClient is a .NET library that provides methods to interact with Microsoft Graph for email operations. This library allows you to send, read, move, and manage emails seamlessly using the Microsoft Graph API.
Features
- Send emails asynchronously
- Read emails asynchronously
- Move emails to specified folders
- Mark emails as read or unread
- Delete emails
- List and create mail folders
- Move emails to the Junk folder
- Reply to and forward emails
Installation
You can install the GraphEmailClient NuGet package using one of the following methods:
.NET CLI
Run the following command in your terminal:
dotnet add package GraphEmailClient
NuGet Package Manager Console
If you prefer using the NuGet Package Manager Console, run the following command:
Install-Package GraphEmailClient
Usage
Here’s a quick example of how to use the GraphEmailClient:
using Microsoft.Extensions.Logging;
using GraphEmailClient;
var loggerFactory = LoggerFactory.Create(builder => {
builder.AddConsole();
});
ILogger<EmailClient> logger = loggerFactory.CreateLogger<EmailClient>();
var emailClient = new EmailClient("clientId", "tenantId", "clientSecret", logger);
// Send an email
await emailClient.SendEmailAsync("Hello", "This is a test email.", new List<string> { "example@example.com" });
// Read emails
var emails = await emailClient.ReadEmailsAsync(5);
// Move an email
await emailClient.MoveEmailAsync("message-id", "folder-id");
// Mark an email as read
await emailClient.MarkEmailAsReadAsync("message-id", true);
// Delete an email
await emailClient.DeleteEmailAsync("message-id");
// List mail folders
var folders = await emailClient.ListFoldersAsync();
// Create a new folder
await emailClient.CreateFolderAsync("New Folder");
// Move an email to Junk
await emailClient.MoveEmailToJunkAsync("message-id");
// Reply to an email
await emailClient.ReplyToEmailAsync("message-id", "This is a reply.");
// Forward an email
await emailClient.ForwardEmailAsync("message-id", "Check this out!", new List<string> { "recipient@example.com" });
Method Descriptions
SendEmailAsync
- Description: Sends an email asynchronously.
- Parameters:
subject
: The subject of the email.body
: The body content of the email.recipients
: A list of recipient email addresses.
- Exceptions: Throws
ArgumentNullException
if any parameter is null or empty.
ReadEmailsAsync
- Description: Reads emails asynchronously.
- Parameters:
top
: The number of emails to retrieve (default is 10).
- Returns: A list of retrieved emails.
- Exceptions: Throws
ServiceException
if there is an error retrieving emails.
MoveEmailAsync
- Description: Moves an email to a specified folder asynchronously.
- Parameters:
messageId
: The ID of the email to move.destinationFolderId
: The ID of the destination folder.
- Exceptions: Throws
ArgumentNullException
orServiceException
if parameters are invalid.
MarkEmailAsReadAsync
- Description: Marks an email as read or unread asynchronously.
- Parameters:
messageId
: The ID of the email to mark.isRead
: True to mark as read; false to mark as unread.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
DeleteEmailAsync
- Description: Deletes an email asynchronously.
- Parameters:
messageId
: The ID of the email to delete.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
ListFoldersAsync
- Description: Lists mail folders asynchronously.
- Returns: A list of mail folders.
- Exceptions: Throws
ServiceException
.
CreateFolderAsync
- Description: Creates a new mail folder asynchronously.
- Parameters:
folderName
: The name of the folder to create.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
MoveEmailToJunkAsync
- Description: Moves an email to the Junk folder asynchronously.
- Parameters:
messageId
: The ID of the email to move.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
ReplyToEmailAsync
- Description: Replies to an email asynchronously.
- Parameters:
messageId
: The ID of the email to reply to.replyBody
: The body content of the reply.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
ForwardEmailAsync
- Description: Forwards an email asynchronously.
- Parameters:
messageId
: The ID of the email to forward.forwardBody
: The body content of the forwarded email.recipients
: A list of recipient email addresses for the forwarded email.
- Exceptions: Throws
ArgumentNullException
orServiceException
.
Documentation
For detailed documentation on the available methods and their usage, please refer to the XML comments in the code. Each method is documented with its parameters, return types, and exceptions. You can also find usage examples in the Usage section above.
XML Documentation
The library includes XML documentation comments that provide additional context and examples for each method. You can view this documentation directly in your IDE or by generating documentation files.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Author
Created by Yaseer Arafat.
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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Graph (>= 4.5.0)
- Microsoft.Identity.Client (>= 4.66.2)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.2.1)
- System.IdentityModel.Tokens.Jwt (>= 8.2.1)
- System.Text.Json (>= 8.0.5)
-
net9.0
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Graph (>= 4.5.0)
- Microsoft.Identity.Client (>= 4.66.2)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.2.1)
- System.IdentityModel.Tokens.Jwt (>= 8.2.1)
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.