WeNerds.Thoth
1.0.0
dotnet add package WeNerds.Thoth --version 1.0.0
NuGet\Install-Package WeNerds.Thoth -Version 1.0.0
<PackageReference Include="WeNerds.Thoth" Version="1.0.0" />
<PackageVersion Include="WeNerds.Thoth" Version="1.0.0" />
<PackageReference Include="WeNerds.Thoth" />
paket add WeNerds.Thoth --version 1.0.0
#r "nuget: WeNerds.Thoth, 1.0.0"
#:package WeNerds.Thoth@1.0.0
#addin nuget:?package=WeNerds.Thoth&version=1.0.0
#tool nuget:?package=WeNerds.Thoth&version=1.0.0
π₯ - Thoth Notifications
A library for sending messages to external channels, currently supporting SMTP and Slack. It allows for seamless integration of notifications and communication, making it easy and efficient to deliver alerts and messages across different platforms.
π¦ Features
- Sending Email ( SMTP )
- Sending message to Slack Channel
π How It Works
The basic operation is:
- The library must have its services registered
- Inject the desired service into the target service's constructor
- Trigger the alert
π οΈ Hands on
π Step 1 - Install Thoth
- Package Manager
$ Install-Package WeNerds.Thoth
- .Net CLI
$ dotnet add package WeNerds.Thoth
π Step 2 - Adding Environment Variables (Optional)
If desired, WeNerds.Thoth allows the use of environment variables for client configuration.
- The environment variables used for the SMTP service are:
TOTH_SMTP_USERNAME=postmaster@sandboxgef8ue893rt09gsgviyui63tret3.mailgun.org
TOTH_SMTP_PASSWORD=yuYTUytutyt765764&UH56u
TOTH_SMTP_HOST=smtp.mailgun.org
TOTH_SMTP_PORT=465
TOTH_SMTP_RETRIES_ON_FAILURE=3
TOTH_SMTP_EMAIL_SENDER=sender@mailCompany.com
Where:
- TOTH_SMTP_USERNAME: Username of the account used
- TOTH_SMTP_PASSWORD: Password of the account used
- TOTH_SMTP_HOST: Host of the account used
- TOTH_SMTP_PORT: Port of the account used
- TOTH_SMTP_RETRIES_ON_FAILURE: Number of retry attempts in case of failures
- TOTH_SMTP_EMAIL_SENDER: Email that will be displayed to the recipient
π Step 3 - Service register
The registration of WeNerds.Thoth services can be done in two ways:
For use with environment variables
In the Program.cs class, execute the method to register the library's services:
builder.Services.AddThothService();
For use by passing the configurations as parameters
This way, it is possible to pass a list of SMTP options, allowing multiple email clients to be used, each in a different context of the project, for example.
builder
.Services
.AddThothService(new ThothOptions
{
SmtpOptions = new List<SmtpOptions>
{
new SmtpOptions(
"MailGun",
"postmaster@sandboxgef8ue893rt09gsgviyui63tret3.mailgun.org",
"yuYTUytutyt765764&UH56u",
"smtp.mailgun.org",
465
)
}
});
Where we can specify the parameters (in the same order as the example above):
- Name: The name of the client
- Username: The username of the account used for sending emails
- Password: The password of the account used for sending emails
- Host: The host to be used for sending emails
- Port: The port to be used for sending emails. Optional, the default value is 465.
- RetriesOnFailure: The number of retry attempts in case of failure. Optional, the default value is 3.
Once the services are registered, we can start using them.
π Step 4 - Injecting the Service
Now, the WeNerds.Thoth service can be injected for use.
In the example below, the primary constructor is used.
public class MonitoringService(IThothService thothService)
π Step 5 - Using the Service
Once the service is injected, you can now use it to send alerts.
Hereβs an example using SMTP:
var result = await thothService.Smtp.SendMessageAsync(
"Subject Email,
"Content of email",
["destiny.email@emailCompany.com"],
"MailGun",
isHtml: false,
cancellationToken: cancellationToken
);
In the example above, we used only the following parameters:
- subject: The subject of the email. Required.
- content: The content of the email. Required.
- to: The recipient(s) of the email. Multiple recipients can be specified. Required.
- clientName: The client to be used for sending the email. If using the environment variable mode, this parameter should not be provided.
- isHtml: Indicates whether the email is HTML or Plain Text. If not provided, the default is true, meaning HTML.
- cancellationToken: The CancellationToken for the request.
Other accepted parameters:
- sender: If provided, this will be the email displayed instead of the one configured in the environment variables.
- blindCarbonCopy: Blind carbon copy recipients.
This is how email sending works via SMTP using WeNerds.Thoth.
Hereβs an example using Slack:
var result = await thothService.Slack.SendMessageAsync("Hello World",
"https://hooks.slack.com/services/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");
Where:
- message: The message that will be sent to the channel.
- slackUrl: Webhook URL linked to the channel where the message will be sent.
The Smtp and Slack services return a Result pattern.
To validate if the message was sent successfully, simply check result.IsSuccess. In case of failures, you can check the result.Errors property, which will contain the occurred errors.
π Happy coding!
| 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 was computed. 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
- MailKit (>= 4.11.0)
- Microsoft.Extensions.Http (>= 8.0.1)
- Polly (>= 8.5.2)
- WeNerds.Commons (>= 1.0.7)
- WeNerds.Models (>= 1.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 409 | 3/15/2025 |