{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/email-api/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Mailjet Go SDK","siteUrl":"https://dev.mailjet.com/","projectTitle":"Mailjet Developer Documentation","description":"Install and use the official Mailjet Go client: authentication, sending with Send API v3.1, REST requests, filtering, proxies and module versioning.","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":"go-sdk","__idx":0},"children":["Go SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The official Go client for the Mailjet API lives at ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/mailjet-apiv3-go"},"children":["mailjet/mailjet-apiv3-go"]},". Reference documentation is published on ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://pkg.go.dev/github.com/mailjet/mailjet-apiv3-go/v4"},"children":["pkg.go.dev"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"compatibility","__idx":1},"children":["Compatibility"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The library requires ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Go 1.13 or higher"]},". Because ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://go.dev/doc/devel/release#policy"},"children":["each major Go release is supported until two newer major releases exist"]},", there is no guarantee the client works on Go versions that are themselves out of support."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Breaking change:"]}," backward compatibility was broken in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["v3.0"]},", which introduced the versioned module paths required by Go modules. Import paths must include the major version."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"installation","__idx":2},"children":["Installation"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"go get github.com/mailjet/mailjet-apiv3-go/v4\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"import (\n    \"github.com/mailjet/mailjet-apiv3-go/v4\"\n    \"github.com/mailjet/mailjet-apiv3-go/v4/resources\"\n)\n","lang":"go"},"children":[]},{"$$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. Keep them in the environment rather than in code:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"export MJ_APIKEY_PUBLIC='your API key'\nexport MJ_APIKEY_PRIVATE='your API secret'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"publicKey := os.Getenv(\"MJ_APIKEY_PUBLIC\")\nsecretKey := os.Getenv(\"MJ_APIKEY_PRIVATE\")\n\nmj := mailjet.NewMailjetClient(publicKey, secretKey)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"verify-your-credentials","__idx":4},"children":["Verify your credentials"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The repository ships a small program under ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["tests/"]}," that exercises the wrapper. Running it is a quick way to confirm the keys in your environment are valid and active:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"go run main.go\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"send-your-first-email","__idx":5},"children":["Send your first email"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"package main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"os\"\n\n    \"github.com/mailjet/mailjet-apiv3-go/v4\"\n)\n\nfunc main() {\n    mailjetClient := mailjet.NewMailjetClient(\n        os.Getenv(\"MJ_APIKEY_PUBLIC\"),\n        os.Getenv(\"MJ_APIKEY_PRIVATE\"),\n    )\n\n    messagesInfo := []mailjet.InfoMessagesV31{\n        {\n            From: &mailjet.RecipientV31{\n                Email: \"pilot@example.com\",\n                Name:  \"Mailjet Pilot\",\n            },\n            To: &mailjet.RecipientsV31{\n                mailjet.RecipientV31{\n                    Email: \"passenger1@example.com\",\n                    Name:  \"Passenger 1\",\n                },\n            },\n            Subject:  \"Your email flight plan!\",\n            TextPart: \"Dear passenger 1, welcome to Mailjet!\",\n            HTMLPart: \"<h3>Dear passenger 1, welcome to Mailjet!</h3>\",\n        },\n    }\n\n    messages := mailjet.MessagesV31{Info: messagesInfo}\n\n    res, err := mailjetClient.SendMailV31(&messages)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Printf(\"Data: %+v\\n\", res)\n}\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client-and-call-configuration","__idx":6},"children":["Client and call configuration"]},{"$$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"]},". Pass a different one as a third argument to the constructor:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"mailjetClient := mailjet.NewMailjetClient(\n    os.Getenv(\"MJ_APIKEY_PUBLIC\"),\n    os.Getenv(\"MJ_APIKEY_PRIVATE\"),\n    \"https://api.us.mailjet.com\",\n)\n","lang":"go"},"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":"send-through-a-proxy","__idx":8},"children":["Send through a proxy"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Inject your own ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["*http.Client"]}," with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SetClient"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"func setupProxy(proxyURLStr string) *http.Client {\n    proxyURL, err := url.Parse(proxyURLStr)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}\n\n    client := &http.Client{}\n    client.Transport = transport\n\n    return client\n}\n\nfunc main() {\n    mj := mailjet.NewMailjetClient(\n        os.Getenv(\"MJ_APIKEY_PUBLIC\"),\n        os.Getenv(\"MJ_APIKEY_PRIVATE\"),\n    )\n\n    mj.SetClient(setupProxy(os.Getenv(\"HTTP_PROXY\")))\n\n    // ...\n}\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The same hook lets you set custom timeouts, instrumentation or retry transports."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"request-examples","__idx":9},"children":["Request examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["REST calls are built from a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mailjet.Request"]}," (resource, ID, action) and, for writes, a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mailjet.FullRequest"]}," that pairs that request with a typed payload from the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["resources"]}," package. Responses are unmarshalled into a slice of the matching resource type."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"post--create-an-object","__idx":10},"children":["POST — create an object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"var data []resources.Contact\n\nmr := &mailjet.Request{\n    Resource: \"contact\",\n}\n\nfmr := &mailjet.FullRequest{\n    Info: mr,\n    Payload: &resources.Contact{\n        Email:                   \"passenger@example.com\",\n        IsExcludedFromCampaigns: true,\n        Name:                    \"New Contact\",\n    },\n}\n\nerr := mailjetClient.Post(fmr, &data)\nif err != nil {\n    fmt.Println(err)\n}\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"post--endpoints-with-an-action","__idx":11},"children":["POST — endpoints with an action"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Action"]}," on the request to reach action endpoints such as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/contact/{id}/managecontactslists"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"var data []resources.ContactManagecontactslists\n\nmr := &mailjet.Request{\n    Resource: \"contact\",\n    ID:       423,\n    Action:   \"managecontactslists\",\n}\n\nfmr := &mailjet.FullRequest{\n    Info: mr,\n    Payload: &resources.ContactManagecontactslists{\n        ContactsLists: []resources.ContactsListAction{\n            {\n                ListID: 432,\n                Action: \"addnoforce\",\n            },\n            {\n                ListID: 553,\n                Action: \"addforce\",\n            },\n        },\n    },\n}\n\nerr := mailjetClient.Post(fmr, &data)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--all-objects","__idx":12},"children":["GET — all objects"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"var data []resources.Contact\n\n_, _, err := mailjetClient.List(\"contact\", &data)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--with-filters","__idx":13},"children":["GET — with filters"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"var data []resources.Contact\n\n_, _, err := mailjetClient.List(\n    \"contact\",\n    &data,\n    mailjet.Filter(\"IsExcludedFromCampaigns\", \"false\"),\n)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get--a-single-object","__idx":14},"children":["GET — a single object"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"var data []resources.Contact\n\nmr := &mailjet.Request{\n    Resource: \"contact\",\n    ID:       5234,\n}\n\nerr := mailjetClient.Get(mr, &data)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"put--update-an-object","__idx":15},"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":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AltID"]}," accepts an alternative identifier — a contact's email address, for example — instead of the numeric ID."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"go","header":{"controls":{"copy":{}}},"source":"mr := &mailjet.Request{\n    Resource: \"contactdata\",\n    ID:       325,\n    // AltID: \"user1@example.com\",\n}\n\nfmr := &mailjet.FullRequest{\n    Info: mr,\n    Payload: &resources.Contactdata{\n        Data: resources.KeyValueList{\n            {\n                \"Name\":  \"name\",\n                \"Value\": \"John\",\n            },\n            {\n                \"Name\":  \"country\",\n                \"Value\": \"Canada\",\n            },\n        },\n    },\n}\n\nerr := mailjetClient.Put(fmr, nil)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"delete--remove-an-object","__idx":16},"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":"go","header":{"controls":{"copy":{}}},"source":"mr := &mailjet.Request{\n    Resource: \"template\",\n    ID:       423,\n}\n\nerr := mailjetClient.Delete(mr)\n","lang":"go"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"contribute","__idx":17},"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-go"},"children":["mailjet/mailjet-apiv3-go"]},". Documentation improvements belong in the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/mailjet/api-documentation"},"children":["API documentation repo"]},"."]}]},"headings":[{"value":"Go SDK","id":"go-sdk","depth":1},{"value":"Compatibility","id":"compatibility","depth":2},{"value":"Installation","id":"installation","depth":2},{"value":"Authentication","id":"authentication","depth":2},{"value":"Verify your credentials","id":"verify-your-credentials","depth":3},{"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":"Base URL","id":"base-url","depth":3},{"value":"Send through a proxy","id":"send-through-a-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":"Contribute","id":"contribute","depth":2}],"frontmatter":{"title":"Mailjet Go SDK","seo":{"title":"Mailjet Go SDK","description":"Install and use the official Mailjet Go client: authentication, sending with Send API v3.1, REST requests, filtering, proxies and module versioning."}},"lastModified":"2026-08-26T16:26:02.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/email-api/developer-tools/go","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}