{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/email-api/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Mailjet C# / .NET SDK","siteUrl":"https://dev.mailjet.com/","projectTitle":"Mailjet Developer Documentation","description":"Install and use the official Mailjet .NET wrapper: authentication, sending with Send API v3.1, REST requests, dependency injection, proxies and SMS.","image":"https://dev.mailjet.com/og-image.png","lang":"en-US","keywords":["Mailjet API","Email API","Content API","SMTP Relay","transactional email","email delivery","Send API","email templates","developer documentation"],"meta":[{"name":"og:type","content":"website"},{"name":"og:site_name","content":"Mailjet Developer Documentation"},{"name":"twitter:card","content":"summary_large_image"},{"name":"robots","content":"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"},{"name":"googlebot","content":"index, follow, max-snippet:-1, max-image-preview:large"}],"jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://dev.mailjet.com/#organization","name":"Mailjet","alternateName":"Sinch Mailjet","url":"https://www.mailjet.com","logo":"https://assets.mailjet.com/lib/images/mailjetLogo/mj_logo_with_text_color.png","parentOrganization":{"@type":"Organization","name":"Sinch","url":"https://www.sinch.com"}},{"@type":"WebSite","@id":"https://dev.mailjet.com/#website","name":"Mailjet Developer Documentation","description":"Official developer documentation for the Mailjet Email API, Content API and SMTP Relay.","url":"https://dev.mailjet.com/","inLanguage":"en-US","publisher":{"@id":"https://dev.mailjet.com/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://dev.mailjet.com/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]},"llmstxt":{"hide":false,"title":"Mailjet Developer Documentation","description":"Developer documentation for the Mailjet Email API, Content API and SMTP Relay - guides, API references and code samples for sending, templating and tracking email at scale.","details":{"content":"Mailjet (part of Sinch) provides APIs for sending and managing email.\n\nThis documentation covers four main areas:\n\n- **Email API** - the Send API (v3 and v3.1) for transactional and marketing email,\n  plus contact management, segmentation, campaigns, statistics, webhooks, the Parse API\n  and the Mailjet Templating Language.\n- **Content API** - programmatic management of email templates, template contents,\n  images, labels and authentication tokens (v1).\n- **SMTP Relay** - sending through Mailjet's SMTP servers, including custom headers.\n- **API Reference** - the complete, generated reference for every endpoint, built directly\n  from the OpenAPI specifications.\n\nBase URL for all REST APIs: `https://api.mailjet.com`.\nAuthentication uses HTTP Basic auth with an API key and secret key.\n\n## Machine-readable entry points\n\nPrefer these when you need the API surface in as few requests as possible:\n\n- `/openapi/openapi-mailjet.md` - the **complete** Email API reference (every endpoint,\n  grouped by resource) as a single Markdown document.\n- `/openapi/openapi-passport.md` - the **complete** Content API reference as a single\n  Markdown document.\n- `/_bundle/openapi/openapi-mailjet.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Email API.\n- `/_bundle/openapi/openapi-passport.yaml` - the raw, fully bundled OpenAPI 3 description\n  of the Content API.\n- `/sitemap.xml` - every indexable URL on this site.\n\nEvery page on this site is also available as clean Markdown by appending `.md` to its URL."},"sections":[{"title":"Email API","description":"Sending, contacts, campaigns, statistics, webhooks and templating.","includeFiles":["docs/email-api/**/*.md"],"excludeFiles":[]},{"title":"Content API","description":"Manage templates, template contents, images, labels and tokens.","includeFiles":["docs/content-api/**/*.md","docs/content-api.md"],"excludeFiles":[]},{"title":"SMTP Relay","description":"Send email through Mailjet's SMTP servers.","includeFiles":["docs/smtp-relay/**/*.md"],"excludeFiles":[]},{"title":"API Reference","description":"Complete generated reference for every Mailjet API endpoint.","includeFiles":["openapi/openapi-mailjet.yaml","openapi/openapi-passport.yaml","docs/api-reference/**/*.md"],"excludeFiles":[]},{"title":"Migrating from Mandrill","description":"Guides for switching from Mandrill to Mailjet.","includeFiles":["docs/mandrill/**/*.md"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"c--net-sdk","__idx":0},"children":["C# / .NET SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The official .NET wrapper for the Mailjet API is published on NuGet as ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Mailjet.Api"]}]}," and developed on GitHub at ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/mailjet-apiv3-dotnet"},"children":["mailjet/mailjet-apiv3-dotnet"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Current release: ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["4.0.1"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"compatibility","__idx":1},"children":["Compatibility"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Since 4.0.0 the library targets ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[".NET Standard 2.0"]},", which reduces the dependency surface and removes the security warnings raised by the older .NET Framework target."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Runtime"},"children":["Runtime"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Minimum version"},"children":["Minimum version"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[".NET"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["5.0"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[".NET Core"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["2.0"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[".NET Framework"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["4.6.2"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Mono"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["5.4"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Xamarin.iOS"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["10.14"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Xamarin.Android"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["8.0"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Universal Windows Platform"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["10.0.16299"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Dependencies:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["NETStandard.Library"]}," >= 2.0.3"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Newtonsoft.Json"]}," >= 13.0.4"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Note:"]}," release 4.0.1 fixes a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MissingMethodException"]}," on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PostAsync"]}," / ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PutAsync"]}," that occurred when an older Newtonsoft.Json (13.0.0–13.0.3) was resolved at runtime instead of 13.0.4. If you pin Newtonsoft.Json in your project, make sure the runtime actually loads 13.0.4 or later."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"installation","__idx":2},"children":["Installation"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"PM> Install-Package Mailjet.Api\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Or clone the repository directly if you need to build from source."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authentication","__idx":3},"children":["Authentication"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Email API authenticates with your API key and secret. Store them outside of your code — for example as machine-level environment variables:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"setx -m MJ_APIKEY_PUBLIC \"your API key\"\nsetx -m MJ_APIKEY_PRIVATE \"your API secret\"\n"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"MailjetClient client = new MailjetClient(\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"),\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"));\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The SMS API uses a ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["bearer token"]}," instead — see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#sms-api"},"children":["SMS API"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"send-your-first-email","__idx":4},"children":["Send your first email"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TransactionalEmailBuilder"]}," builds a strongly typed message, so you get compile-time checking instead of hand-assembled JSON."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Mailjet.Client;\nusing Mailjet.Client.TransactionalEmails;\nusing System;\nusing System.Threading.Tasks;\n\nclass Program\n{\n    static async Task Main(string[] args)\n    {\n        var client = new MailjetClient(\n            Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"),\n            Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"));\n\n        var email = new TransactionalEmailBuilder()\n            .WithFrom(new SendContact(\"pilot@example.com\", \"Mailjet Pilot\"))\n            .WithTo(new SendContact(\"passenger@example.com\", \"Passenger 1\"))\n            .WithSubject(\"Your email flight plan!\")\n            .WithHtmlPart(\"<h3>Dear passenger, welcome to Mailjet!</h3>\")\n            .WithTextPart(\"Dear passenger, welcome to Mailjet!\")\n            .Build();\n\n        var response = await client.SendTransactionalEmailAsync(email);\n\n        Console.WriteLine($\"Messages accepted: {response.Messages.Length}\");\n    }\n}\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client-and-call-configuration","__idx":5},"children":["Client and call configuration"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"api-versioning","__idx":6},"children":["API versioning"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Mailjet API spans three versions:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Version"},"children":["Version"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Scope"},"children":["Scope"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["v3"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Email API"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["v3.1"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Send API v3.1 (latest send version)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["v4"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["SMS API, contact delete API"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You do not need to configure this. Since 2.0.0 the client derives the required version from the resource you call."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"base-url","__idx":7},"children":["Base URL"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The default base domain is ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.mailjet.com"]},". Override it with the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BaseAdress"]}," property:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var client = new MailjetClient(\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"),\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"))\n{\n    BaseAdress = \"https://api.us.mailjet.com\",\n};\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Accounts on Mailjet's ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["US architecture"]}," must set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.us.mailjet.com"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"dependency-injection","__idx":8},"children":["Dependency injection"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MailjetClient"]}," supports ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IHttpClientFactory"]}," and can be registered as a typed client:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"services.AddHttpClient<IMailjetClient, MailjetClient>(client =>\n{\n    // sets BaseAddress, MediaType and UserAgent\n    client.SetDefaultSettings();\n\n    client.UseBasicAuthentication(\"apiKey\", \"apiSecret\");\n    // or, for the SMS API:\n    // client.UseBearerAuthentication(\"access_token\");\n});\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Then inject ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IMailjetClient"]}," where you need it:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"public class EmailService : IEmailService\n{\n    private readonly IMailjetClient _mailjetClient;\n\n    public EmailService(IMailjetClient mailjetClient)\n    {\n        _mailjetClient = mailjetClient;\n    }\n}\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Because sending lives on the client itself (rather than on extension methods), ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IMailjetClient"]}," can be mocked in unit tests."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"proxy","__idx":9},"children":["Proxy"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pass a configured ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["HttpClientHandler"]}," to the constructor:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var proxy = new WebProxy\n{\n    // even for an HTTPS proxy the address starts with http\n    Address = new Uri(\"http://51.79.0.0:8080\"),\n    UseDefaultCredentials = false,\n    // Credentials = new NetworkCredential(\"user\", \"password\"),\n};\n\nvar handler = new HttpClientHandler { Proxy = proxy };\n\nvar client = new MailjetClient(\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PUBLIC\"),\n    Environment.GetEnvironmentVariable(\"MJ_APIKEY_PRIVATE\"),\n    handler);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"request-examples","__idx":10},"children":["Request examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Every request is a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MailjetRequest"]}," carrying a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Resource"]},", an optional ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ResourceId"]},", properties and filters. The full list of resources lives in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/mailjet-apiv3-dotnet/tree/master/Mailjet.Client/Resources"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/Mailjet.Client/Resources"]}]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"post--create-an-object","__idx":11},"children":["POST — create an object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = Contact.Resource,\n}\n    .Property(Contact.Email, \"passenger@example.com\")\n    .Property(Contact.IsExcludedFromCampaigns, \"false\")\n    .Property(Contact.Name, \"New Contact\");\n\nMailjetResponse response = await client.PostAsync(request);\n\nif (response.IsSuccessStatusCode)\n{\n    Console.WriteLine($\"Total: {response.GetTotal()}, Count: {response.GetCount()}\");\n    Console.WriteLine(response.GetData());\n}\nelse\n{\n    Console.WriteLine($\"StatusCode: {response.StatusCode}\");\n    Console.WriteLine($\"ErrorInfo: {response.GetErrorInfo()}\");\n    Console.WriteLine($\"ErrorMessage: {response.GetErrorMessage()}\");\n}\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"post--endpoints-with-an-action","__idx":12},"children":["POST — endpoints with an action"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Action endpoints have their own resource object. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/contact/{id}/managecontactslists"]}," maps to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ContactManagecontactslists"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = ContactManagecontactslists.Resource,\n    ResourceId = ResourceId.Numeric(contactId)\n}\n    .Property(ContactManagecontactslists.ContactsLists, new JArray {\n        new JObject {\n            { \"ListID\", listId1 },\n            { \"Action\", \"addnoforce\" }\n        },\n        new JObject {\n            { \"ListID\", listId2 },\n            { \"Action\", \"addforce\" }\n        }\n    });\n\nMailjetResponse response = await client.PostAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--all-objects","__idx":13},"children":["GET — all objects"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = Contact.Resource,\n};\n\nMailjetResponse response = await client.GetAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--with-filters","__idx":14},"children":["GET — with filters"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = Contact.Resource,\n}\n    .Filter(Contact.IsExcludedFromCampaigns, \"false\");\n\nMailjetResponse response = await client.GetAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--a-single-object","__idx":15},"children":["GET — a single object"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ResourceId"]}," to target one object. Numeric IDs use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ResourceId.Numeric"]},", and resources that accept an email address (such as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["contact"]},") use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ResourceId.Alphanumeric"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var byId = new MailjetRequest\n{\n    Resource = Contact.Resource,\n    ResourceId = ResourceId.Numeric(contactId)\n};\n\nvar byEmail = new MailjetRequest\n{\n    Resource = Contact.Resource,\n    ResourceId = ResourceId.Alphanumeric(\"passenger@example.com\")\n};\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"put--update-an-object","__idx":16},"children":["PUT — update an object"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PUT"]}," in the Mailjet API behaves like a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PATCH"]},": only the properties you send are updated, everything else is left untouched, and non-mandatory properties can be omitted."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = Contactdata.Resource,\n    ResourceId = ResourceId.Numeric(contactId)\n}\n    .Property(Contactdata.Data, new JArray {\n        new JObject {\n            { \"first_name\", \"John\" },\n            { \"last_name\", \"Smith\" }\n        }\n    });\n\nMailjetResponse response = await client.PutAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"delete--remove-an-object","__idx":17},"children":["DELETE — remove an object"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A successful ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["DELETE"]}," returns ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["204 No Content"]}," with no response body."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var request = new MailjetRequest\n{\n    Resource = Template.Resource,\n    ResourceId = ResourceId.Numeric(templateId)\n};\n\nMailjetResponse response = await client.DeleteAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"response-object","__idx":18},"children":["Response object"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetAsync"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PostAsync"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PutAsync"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["DeleteAsync"]}," all return a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MailjetResponse"]},":"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Member"},"children":["Member"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Returns"},"children":["Returns"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IsSuccessStatusCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["whether the call succeeded"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["StatusCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP status code (200, 400, …)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetData()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Data"]}," property of the JSON payload, or the full payload if there is none"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetTotal()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["total number of matching objects"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetCount()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["number of objects returned in this response"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetErrorInfo()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP reason phrase (\"OK\", \"Bad Request\", …)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GetErrorMessage()"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["error reason from the API response payload"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sms-api","__idx":19},"children":["SMS API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["SMS endpoints authenticate with a bearer token generated in the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://app.mailjet.com/sms"},"children":["SMS section"]}," of your account. Pass the token as the only constructor argument:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Mailjet.Client;\nusing Mailjet.Client.Resources.SMS;\n\nvar client = new MailjetClient(Environment.GetEnvironmentVariable(\"MJ_API_TOKEN\"));\n\nvar request = new MailjetRequest\n{\n    Resource = Send.Resource,\n}\n    .Property(Send.From, \"MJPilot\")\n    .Property(Send.To, \"+33600000000\")\n    .Property(Send.Text, \"Have a nice SMS flight with Mailjet!\");\n\nMailjetResponse response = await client.PostAsync(request);\n","lang":"csharp"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"release-notes","__idx":20},"children":["Release notes"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Version"},"children":["Version"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Changes"},"children":["Changes"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["4.0.1"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Fixes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["MissingMethodException"]}," on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PostAsync"]},"/",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PutAsync"]}," with Newtonsoft.Json 13.0.0–13.0.3 loaded at runtime"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["4.0.0"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Breaking:"]}," target framework moved to .NET Standard 2.0"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["3.0.1"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Renames ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TemplateErrorDelivery"]}," to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TemplateErrorDeliver"]},"; fixes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TransactionalEmailBuilder"]}," validation; handles a null ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Messages"]}," property"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["3.0.0"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Breaking:"]}," removes extension methods such as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SendTransactionalEmailAsync"]}," from the extension class"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["2.1.0"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Bumps Newtonsoft.Json; drops the .NET Framework target; moves ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SendTransactionalEmailAsync"]}," onto the client so it can be mocked"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["2.0.0"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Adds ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["TransactionalEmailBuilder"]}," and typed models, the GDPR contact delete API, automatic version resolution, and a strong-named assembly"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"more-examples","__idx":21},"children":["More examples"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://dev.mailjet.com/email/guides/send-api-v31/#send-with-attached-files"},"children":["Send with attached files"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://dev.mailjet.com/email/guides/contact-management/#gdpr-delete-contacts"},"children":["GDPR delete contacts"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://dev.mailjet.com/email/guides/"},"children":["All email guides"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"contribute","__idx":22},"children":["Contribute"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The wrapper is open source. Fork the repository, branch, implement your fix or feature, document it, and open a pull request at ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/mailjet-apiv3-dotnet"},"children":["mailjet/mailjet-apiv3-dotnet"]},". Documentation improvements belong in the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/api-documentation"},"children":["API documentation repo"]},"."]}]},"headings":[{"value":"C# / .NET SDK","id":"c--net-sdk","depth":1},{"value":"Compatibility","id":"compatibility","depth":2},{"value":"Installation","id":"installation","depth":2},{"value":"Authentication","id":"authentication","depth":2},{"value":"Send your first email","id":"send-your-first-email","depth":2},{"value":"Client and call configuration","id":"client-and-call-configuration","depth":2},{"value":"API versioning","id":"api-versioning","depth":3},{"value":"Base URL","id":"base-url","depth":3},{"value":"Dependency injection","id":"dependency-injection","depth":3},{"value":"Proxy","id":"proxy","depth":3},{"value":"Request examples","id":"request-examples","depth":2},{"value":"POST — create an object","id":"post--create-an-object","depth":3},{"value":"POST — endpoints with an action","id":"post--endpoints-with-an-action","depth":3},{"value":"GET — all objects","id":"get--all-objects","depth":3},{"value":"GET — with filters","id":"get--with-filters","depth":3},{"value":"GET — a single object","id":"get--a-single-object","depth":3},{"value":"PUT — update an object","id":"put--update-an-object","depth":3},{"value":"DELETE — remove an object","id":"delete--remove-an-object","depth":3},{"value":"Response object","id":"response-object","depth":2},{"value":"SMS API","id":"sms-api","depth":2},{"value":"Release notes","id":"release-notes","depth":2},{"value":"More examples","id":"more-examples","depth":2},{"value":"Contribute","id":"contribute","depth":2}],"frontmatter":{"title":"Mailjet C# / .NET SDK","seo":{"title":"Mailjet C# / .NET SDK","description":"Install and use the official Mailjet .NET wrapper: authentication, sending with Send API v3.1, REST requests, dependency injection, proxies and SMS."}},"lastModified":"2026-08-26T16:26:02.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/email-api/developer-tools/csharp","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}