A .NET client for Mailjet: simple, yet customisable
Currently supports sending transactional and template emails, and sending SMS messages. You can easily customise the behaviour.
Contributions are very welcome, in any form or shape!
- Mailjet account, with public/private key and/or token for SMS API (V4). How to get API keys
- Targets
.NET Standard 2.0
, meaning it works on- .NET Core >= 2.0
- .NET Framework 4.6.1
- and more...
Currently in prelease
Package Manager Console
Install-Package Mailjet.SimpleClient –IncludePrerelease
Nuget Package Manager
Search for Mailjet.SimpleClient
, ensure to tick "Include prerelease"
Generally, if you're working with one type of request, e.g. only sending emails, then it's usually better to use a specific client for it.
If you're working with multiple types of requests, e.g. sending an email and updating a template, then it's better to use the generic IMailjetSimpleClient.SendRequeststAsync()
.
See Clients and Working with multiple types of requests
Register clients
public void ConfigureServices(IServiceCollection services)
{
services.AddMailjetClients(opt =>
{
//Set up settings
opt.EmailOptions.SandboxMode = true;
opt.PrivateKey = "";
opt.Token = "";
});
}
Inject into controller/action
AddMailjetClient()
creates three services: IMailjetOptions
, IMailjetEmailClient
, and IMailjetSimpleClient
, which can be injected as any other service throuh your controller's constructor or action parameters.
var emailClient = new MailjetEmailClient(new MailjetSimpleClient(), new MailjetOptions());
var smsClient = new MailjetSmsClient(new MailjetSimpleClient(), new MailjetOptions());
var simpleClient = new MailjetSimpleClient();
Add your own implementations to the DI container as below.
services.AddMailjetOptions(IMailjetOptions)
services.AddMailjetSimpleClient<YourMailjetSimpleClient>()
services.AddMailjetSmsClient<YourMailjetSmsClient>()
services.AddMailjetEmailClient<YourMailjetEmailClient>();
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details