/mailjet-simple-client

A simple, yet customisable, .NET standard client for interacting with Mailjet

Primary LanguageC#MIT LicenseMIT

Mailjet Simple Client Mailjet Logo

A .NET client for Mailjet: simple, yet customisable

Nuget package Nuget package - stable Nuget package - latest Nuget package

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!

Prerequisites

  • 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

Installing

Currently in prelease

Package Manager Console

Install-Package Mailjet.SimpleClient –IncludePrerelease

Nuget Package Manager

Search for Mailjet.SimpleClient, ensure to tick "Include prerelease"

Usage

Types of clients

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

Dependency injection

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.

Manual

Email client

var emailClient = new MailjetEmailClient(new MailjetSimpleClient(), new MailjetOptions());

SMS client

var smsClient = new MailjetSmsClient(new MailjetSimpleClient(), new MailjetOptions());

Low level client

var simpleClient = new MailjetSimpleClient();

Customise

Add your own implementations to the DI container as below.

services.AddMailjetOptions(IMailjetOptions)
services.AddMailjetSimpleClient<YourMailjetSimpleClient>()
services.AddMailjetSmsClient<YourMailjetSmsClient>()
services.AddMailjetEmailClient<YourMailjetEmailClient>();

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details