pvWay.MailJetClientNuGet.Core 1.0.3

dotnet add package pvWay.MailJetClientNuGet.Core --version 1.0.3                
NuGet\Install-Package pvWay.MailJetClientNuGet.Core -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="pvWay.MailJetClientNuGet.Core" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add pvWay.MailJetClientNuGet.Core --version 1.0.3                
#r "nuget: pvWay.MailJetClientNuGet.Core, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install pvWay.MailJetClientNuGet.Core as a Cake Addin
#addin nuget:?package=pvWay.MailJetClientNuGet.Core&version=1.0.3

// Install pvWay.MailJetClientNuGet.Core as a Cake Tool
#tool nuget:?package=pvWay.MailJetClientNuGet.Core&version=1.0.3                

MailJet API Client for .Net Core by pvWay

Preconditions

For using this nuGet you should obviously dispose of a MailJet account.

Usage

Interfaces

	
    public interface IMailJetClient
    {
        /// <summary>
        /// Post a mail using a template via the MailJet REST interface
        /// </summary>
        /// <param name="templateId">The unique id of you MailJet template</param>
        /// <param name="fromEmail">The email of the sender</param>
        /// <param name="fromName">The name of the sender</param>
        /// <param name="toEmail">The email of the addressee</param>
        /// <param name="toName">The name of the addressee</param>
        /// <param name="variables">key value dictionary with your MailJet template variables</param>
        /// <param name="subject"></param>
        /// <returns>IMailJetSendResult or null on failure</returns>
        Task<IMailJetSendResult> SendTemplateAsync(
            int templateId,
            string fromEmail, string fromName,
            string toEmail, string toName,
            IDictionary<string, string> variables = null,
            string subject = null);
    }

Constructor

From the business layer of your application you start by instanciating the MailJet client

	
            var mjClient = new MailJetClient(
                apiKey: "******", // replace with your own MailJet ApiKey
                apiSecret:"******", // replace with your own MailJet ApiSecret
                logError: Console.WriteLine); // using Console as Logger

Posting an email using a MailJet template

	
            IMailJetSendResult res = mjClient.SendTemplateAsync(
                templateId: 12345678,
                fromEmail: "invoicing@pvway.com",
                fromName: "pvWay SRL",
                toEmail: "someOne@someDomain",
                toName: "Mr someOne",
                variables: new Dictionary<string, string>
                {
                    {"invoiceNumber", "202015436"},
                    {"invoiceDate", "2020 Dec 25"},
                    {"product", "Merry Christmas Gift"},
                    {"price", "$ 125.33"}
                },
                // use the default template subject
                subject: null)
                .Result; 
            if (res.Success)
            {
                foreach (var resMessage in res.Messages)
                {
                    Console.WriteLine($"status: {resMessage.Status}");
                    foreach (var recipientRes in resMessage.To)
                    {
                        Console.WriteLine(
                            $"{recipientRes.Email} - {recipientRes.MessageUuid}");
                    }
                }
            }
            else
            {
                Console.WriteLine(res.Exception);
            }

Happy coding 😃

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.3 1,025 4/7/2023
1.0.2 1,225 7/12/2022
1.0.1 3,147 12/28/2020
1.0.0 1,339 12/27/2020 1.0.0 is deprecated because it has critical bugs.

upgrade Newtonsoft.Json version