{"id":21152094,"url":"https://github.com/mailjet/mailjet-apiv3-go","last_synced_at":"2025-05-16T12:12:34.060Z","repository":{"id":41824547,"uuid":"44368907","full_name":"mailjet/mailjet-apiv3-go","owner":"mailjet","description":"[API v3] Official Mailjet API v3 Go wrapper","archived":false,"fork":false,"pushed_at":"2024-12-03T17:34:37.000Z","size":158,"stargazers_count":90,"open_issues_count":1,"forks_count":31,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-12T08:38:33.363Z","etag":null,"topics":["api","email","golang","mailjet","mailjet-api","transactional-emails"],"latest_commit_sha":null,"homepage":"https://dev.mailjet.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mailjet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-16T07:19:07.000Z","updated_at":"2025-02-24T23:06:47.000Z","dependencies_parsed_at":"2025-01-15T15:13:06.929Z","dependency_job_id":"3788d2cf-29b2-447a-a4e9-0d0a837f14c5","html_url":"https://github.com/mailjet/mailjet-apiv3-go","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailjet%2Fmailjet-apiv3-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailjet","download_url":"https://codeload.github.com/mailjet/mailjet-apiv3-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","email","golang","mailjet","mailjet-api","transactional-emails"],"created_at":"2024-11-20T10:24:23.804Z","updated_at":"2025-05-16T12:12:33.730Z","avatar_url":"https://github.com/mailjet.png","language":"Go","funding_links":[],"categories":["Table of Contents"],"sub_categories":["Email Service"],"readme":"[mailjet]: http://www.mailjet.com\n[api_credential]: https://app.mailjet.com/account/api_keys\n[doc]: http://dev.mailjet.com/guides/?go#\n\n\n![alt text](https://www.mailjet.com/images/email/transac/logo_header.png \"Mailjet\")\n\n# Official Mailjet Go Client\n\n[![CI](https://github.com/mailjet/mailjet-apiv3-go/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/mailjet/mailjet-apiv3-go/actions/workflows/main.yml)\n[![GoDoc](https://godoc.org/github.com/mailjet/mailjet-apiv3-go?status.svg)](https://pkg.go.dev/github.com/mailjet/mailjet-apiv3-go/v4)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mailjet/mailjet-apiv3-go/v4)](https://goreportcard.com/report/github.com/mailjet/mailjet-apiv3-go/v4)\n\n## Overview\n\nThis repository contains the official Go wrapper for the Mailjet API.\n\nCheck out all the resources and in the [Official Documentation][doc].\n\n## Table of contents\n\n- [Compatibility](#compatibility)\n- [Installation](#installation)\n- [Authentication](#authentication)\n\t- [Functional test](#functional-test)\n- [Make your first call](#make-your-first-call)\n- [Client / Call configuration specifics](#client--call-configuration-specifics)\n  - [Send emails through proxy](#send-emails-through-proxy)\n- [Request examples](#request-examples)\n  - [POST request](#post-request)\n    - [Simple POST request](#simple-post-request)\n    - [Using actions](#using-actions)\n  - [GET request](#get-request)\n    - [Retrieve all objects](#retrieve-all-objects)\n    - [Use filtering](#use-filtering)\n    - [Retrieve a single object](#retrieve-a-single-object)\n  - [PUT request](#put-request)\n  - [DELETE request](#delete-request)\n- [Contribute](#contribute)\n\n## Compatibility\n\nOur library requires Go version 1.13 or higher. \nBut since [each major Go release is supported until there are two newer major releases](https://go.dev/doc/devel/release#policy), there is no guarantee that it will be working on unsupported Go versions.\n\n**NOTE: Backward compatibility has been broken with the `v3.0` release which includes versioned paths required by go modules (See [Releasing Modules](https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher)).**\n\n### Installation\n\nGet package:\n\n```\ngo get github.com/mailjet/mailjet-apiv3-go/v4\n```\n\nAnd import the Mailjet wrapper:\n\n```go\nimport (\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n```\n\n## Authentication\n\nThe Mailjet Email API uses your API and Secret keys for authentication. [Grab][api_credential] and save your Mailjet API credentials.\n\n```bash\nexport MJ_APIKEY_PUBLIC='your API key'\nexport MJ_APIKEY_PRIVATE='your API secret'\n```\n\nThen initialize your Mailjet client:\n\n```go\n// Get your environment Mailjet keys and connect\npublicKey := os.Getenv(\"MJ_APIKEY_PUBLIC\")\nsecretKey := os.Getenv(\"MJ_APIKEY_PRIVATE\")\n\nmj := mailjet.NewMailjetClient(publicKey, secretKey)\n```\n\n### Functional test\n\nIn the `tests` folder you will find a small program using the wrapper. It can be used to check whether the Mailjet API keys in your environment are valid and active.\n\n```\ngo run main.go\n```\n\n## Make your first call\n\nHere's an example on how to send an email:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tmessagesInfo := []mailjet.InfoMessagesV31{\n\t\t{\n\t\t\tFrom: \u0026mailjet.RecipientV31{\n\t\t\t\tEmail: \"pilot@mailjet.com\",\n\t\t\t\tName:  \"Mailjet Pilot\",\n\t\t\t},\n\t\t\tTo: \u0026mailjet.RecipientsV31{\n\t\t\t\tmailjet.RecipientV31{\n\t\t\t\t\tEmail: \"passenger1@mailjet.com\",\n\t\t\t\t\tName:  \"passenger 1\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tSubject:  \"Your email flight plan!\",\n\t\t\tTextPart: \"Dear passenger 1, welcome to Mailjet! May the delivery force be with you!\",\n\t\t\tHTMLPart: \"\u003ch3\u003eDear passenger 1, welcome to \u003ca href=\\\"https://www.mailjet.com/\\\"\u003eMailjet\u003c/a\u003e!\u003c/h3\u003e\u003cbr /\u003eMay the delivery force be with you!\",\n\t\t},\n\t}\n\tmessages := mailjet.MessagesV31{Info: messagesInfo}\n\tres, err := mailjetClient.SendMailV31(\u0026messages)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Printf(\"Data: %+v\\n\", res)\n}\n```\n\n## Client / Call configuration specifics\n\n### Base URL\n\nThe default base domain name for the Mailjet API is `https://api.mailjet.com`. You can modify this base URL by adding a different URL in the client configuration for your call:\n\n```go\nmailjetClient := NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"), \"https://api.us.mailjet.com\")\n```\n\nIf your account has been moved to Mailjet's **US architecture**, the URL value you need to set is `https://api.us.mailjet.com`.\n\n### Send emails through proxy\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\t\"net/url\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n)\n\n// Set the http client with the given proxy url\nfunc setupProxy(proxyURLStr string) *http.Client {\n\tproxyURL, err := url.Parse(proxyURLStr)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\ttr := \u0026http.Transport{Proxy: http.ProxyURL(proxyURL)}\n\tclient := \u0026http.Client{}\n\tclient.Transport = tr\n\n\treturn client\n}\n\nfunc main() {\n\tpublicKey := os.Getenv(\"MJ_APIKEY_PUBLIC\")\n\tsecretKey := os.Getenv(\"MJ_APIKEY_PRIVATE\")\n\tproxyURL  := os.Getenv(\"HTTP_PROXY\")\n\n\tmj := mailjet.NewMailjetClient(publicKey, secretKey)\n\n\t// Here we inject our http client configured with our proxy\n\tclient := setupProxy(proxyURL)\n\tmj.SetClient(client)\n\n\tmessagesInfo := []mailjet.InfoMessagesV31{\n\t\t{\n\t\t\tFrom: \u0026mailjet.RecipientV31{\n\t\t\t\tEmail: \"qwe@qwe.com\",\n\t\t\t\tName:  \"Bob Patrick\",\n\t\t\t},\n\t\t\tTo: \u0026mailjet.RecipientsV31{\n\t\t\t\tmailjet.RecipientV31{\n\t\t\t\t\tEmail: \"qwe@qwe.com\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tSubject:  \"Hello World!\",\n\t\t\tTextPart: \"Hi there !\",\n\t\t},\n\t}\n\n\tmessages := \u0026mailjet.MessagesV31{Info: messagesInfo}\n\n\tres, err := mj.SendMailV31(messages)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t} else {\n\t\tfmt.Println(\"Success\")\n\t\tfmt.Println(res)\n\t}\n}\n```\n\n## Request examples\n\n### POST request\n\n#### Simple POST request\n\n```go\n// Create a new contact.\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Contact\n\tmr := \u0026mailjet.Request{\n\t\tResource: \"contact\",\n\t}\n\tfmr := \u0026mailjet.FullRequest{\n\t\tInfo: mr,\n\t\tPayload: \u0026resources.Contact{\n\t\t\tEmail:                   \"passenger@mailjet.com\",\n\t\t\tIsExcludedFromCampaigns: true,\n\t\t\tName:                    \"New Contact\",\n\t\t},\n\t}\n\terr := mailjetClient.Post(fmr, \u0026data)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n```\n\n#### Using actions\n\n```go\n// Create : Manage a contact subscription to a list\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.ContactManagecontactslists\n\tmr := \u0026mailjet.Request{\n\t\tResource: \"contact\",\n\t\tID:       423, // replace with your contact ID here\n\t\tAction:   \"managecontactslists\",\n\t}\n\tfmr := \u0026mailjet.FullRequest{\n\t\tInfo: mr,\n\t\tPayload: \u0026resources.ContactManagecontactslists{\n\t\t\tContactsLists: []resources.ContactsListAction{ // replace with your contact lists here\n\t\t\t\t{\n\t\t\t\t\tListID: 432,\n\t\t\t\t\tAction: \"addnoforce\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tListID: 553,\n\t\t\t\t\tAction: \"addforce\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\terr := mailjetClient.Post(fmr, \u0026data)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n```\n\n### GET request\n\n#### Retrieve all objects\n\n```go\n// Retrieve all contacts:\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Contact\n\t_, _, err := mailjetClient.List(\"contact\", \u0026data)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n```\n\n#### Use filtering\n\n```go\n// Retrieve all contacts that are not in the campaign exclusion list:\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Contact\n\t_, _, err := mailjetClient.List(\"contact\", \u0026data, mailjet.Filter(\"IsExcludedFromCampaigns\", \"false\"))\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n```\n\n#### Retrieve a single object\n\n```go\n// Retrieve a specific contact ID:\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tvar data []resources.Contact\n\tmr := \u0026mailjet.Request{\n\t\tResource: \"contact\",\n\t\tID:       5234, // replace with your contact ID here\n\t}\n\terr := mailjetClient.Get(mr, \u0026data)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Printf(\"Data array: %+v\\n\", data)\n}\n```\n\n### PUT request\n\nA `PUT` request in the Mailjet API will work as a `PATCH` request - the update will affect only the specified properties. The other properties of an existing resource will neither be modified, nor deleted. It also means that all non-mandatory properties can be omitted from your payload.\n\nHere's an example of a `PUT` request:\n\n```go\n// Update the contact properties for a contact:\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n\t\"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\tmr := \u0026mailjet.Request{\n\t\tResource: \"contactdata\",\n\t\tID:       325, // replace with your contact ID here\n\t\t//AltID: \"user1@example.com\", // alternatively you can use contact's email\n\t}\n\tfmr := \u0026mailjet.FullRequest{\n\t\tInfo: mr,\n\t\tPayload: \u0026resources.Contactdata{\n\t\t\tData: resources.KeyValueList{\n\t\t\t\t{\n\t\t\t\t\t\"Name\":  \"name\",\n\t\t\t\t\t\"Value\": \"John\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"Name\":  \"country\",\n\t\t\t\t\t\"Value\": \"Canada\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\terr := mailjetClient.Put(fmr, nil)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n}\n```\n\n### DELETE request\n\nUpon a successful DELETE request the response will not include a response body, but only a 204 No Content response code.\n\nHere's an example of a DELETE request:\n\n```go\n// Delete an email template:\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mailjet/mailjet-apiv3-go/v4\"\n)\n\nfunc main() {\n\tmailjetClient := mailjet.NewMailjetClient(os.Getenv(\"MJ_APIKEY_PUBLIC\"), os.Getenv(\"MJ_APIKEY_PRIVATE\"))\n\n\tmr := \u0026mailjet.Request{\n\t\tResource: \"template\",\n\t\tID:       423, // replace with your template ID here\n\t}\n\n\terr := mailjetClient.Delete(mr)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n}\n```\n\n## Contribute\n\nMailjet loves developers. You can be part of this project!\n\nThis wrapper is a great introduction to the open source world, check out the code!\n\nFeel free to ask anything, and contribute:\n\n- Fork the project.\n- Create a new branch.\n- Implement your feature or bug fix.\n- Add documentation to it.\n- Commit, push, open a pull request and voilà.\n\nIf you have suggestions on how to improve the guides, please submit an issue in our [Official API Documentation repo](https://github.com/mailjet/api-documentation).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailjet%2Fmailjet-apiv3-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailjet%2Fmailjet-apiv3-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailjet%2Fmailjet-apiv3-go/lists"}