mailjet

package module
v0.0.0-...-c24bc15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 18 Imported by: 115

README

alt text

Official Mailjet Go Client

Build Status GoDoc Go Report Card Current Version

Overview

This repository contains the official Go wrapper for the Mailjet API.

Check out all the resources and Go code examples in the Offical Documentation.

Table of contents

Compatibility

Our library requires Go version 1.3 or higher.

Installation

Get package:

go get github.com/mailjet/mailjet-apiv3-go

And create a new MailjetClient:

// Import the Mailjet wrapper
import (
	"github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
	"os"
)

Authentication

The Mailjet Email API uses your API and Secret keys for authentication. Grab and save your Mailjet API credentials.

export MJ_APIKEY_PUBLIC='your API key'
export MJ_APIKEY_PRIVATE='your API secret'

Then initialize your Mailjet client:

// Get your environment Mailjet keys and connect
publicKey := os.Getenv("MJ_APIKEY_PUBLIC")
secretKey := os.Getenv("MJ_APIKEY_PRIVATE")

mj := mailjet.NewMailjetClient(publicKey, secretKey)
Functional test

In 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.

go run main.go

Make your first call

Here's an example on how to send an email:

package main
import (
    "fmt"
    "log"
    "os"
    mailjet "github.com/mailjet/mailjet-apiv3-go"
)
func main () {
    mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
    messagesInfo := []mailjet.InfoMessagesV31 {
      mailjet.InfoMessagesV31{
        From: &mailjet.RecipientV31{
          Email: "pilot@mailjet.com",
          Name: "Mailjet Pilot",
        },
        To: &mailjet.RecipientsV31{
          mailjet.RecipientV31 {
            Email: "passenger1@mailjet.com",
            Name: "passenger 1",
          },
        },
        Subject: "Your email flight plan!",
        TextPart: "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
        HTMLPart: "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!",
      },
    }
    messages := mailjet.MessagesV31{Info: messagesInfo }
    res, err := m.SendMailV31(&messages)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Data: %+v\n", res)
}

Client / Call configuration specifics

Base URL

The 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:

mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"),"https://api.us.mailjet.com")

If your account has been moved to Mailjet's US architecture, the URL value you need to set is https://api.us.mailjet.com.

Send emails through proxy
package main

import (
	"github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"

	"fmt"
	"log"
	"net/url"
	"os"
)

// Set the http client with the given proxy url
func setupProxy(url string) *http.Client {
	proxyURL, err := url.Parse(url)
	if err != nil {
		log.Fatal(err)
	}
	tr := &http.Transport{Proxy: http.ProxyURL(proxyURL)}
	client := &http.Client{}
	client.Transport = tr

	return client
}

func main() {
	publicKey := os.Getenv("MJ_APIKEY_PUBLIC")
	secretKey := os.Getenv("MJ_APIKEY_PRIVATE")
	proxyURL  := os.Getenv("HTTP_PROXY")

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	// Here we inject our http client configured with our proxy
	client := setupProxy(proxyURL)
	mj.SetClient(client)

	messagesInfo := []mailjet.InfoMessagesV31{
		mailjet.InfoMessagesV31{
			From: &mailjet.RecipientV31{
				Email: "qwe@qwe.com",
				Name:  "Bob Patrick",
			},
			To: &mailjet.RecipientsV31{
				mailjet.RecipientV31{
					Email: "qwe@qwe.com",
				},
			},
			Subject:  "Hello World!",
			TextPart: "Hi there !",
		},
	}

	messages := mailjet.MessagesV31{Info: messagesInfo}

	res, err := mj.SendMail(param)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Success")
		fmt.Println(res)
	}
}

Request examples

POST request
Simple POST request
/*
Create a new contact.
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Contact
	mr := &Request{
	  Resource: "contact",
	}
	fmr := &FullRequest{
	  Info: mr,
	  Payload: &resources.Contact {
      Email: "passenger@mailjet.com",
      IsExcludedFromCampaigns: "true",
      Name: "New Contact",
    },
	}
	err := mailjetClient.Post(fmr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
Using actions
/*
Create : Manage a contact subscription to a list
*/
package main
import (
    "fmt"
    "log"
    "os"
    mailjet "github.com/mailjet/mailjet-apiv3-go"
    "github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
    mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
    var data []resources.ContactManagecontactslists
    mr := &Request{
      Resource: "contact",
      ID: RESOURCE_ID,
      Action: "managecontactslists",
    }
    fmr := &FullRequest{
      Info: mr,
      Payload: &resources.ContactManagecontactslists {
      ContactsLists: []MailjetContactsList {
        MailjetContactsList {
          ListID: "$ListID_1",
          Action: "addnoforce",
        },
        MailjetContactsList {
          ListID: "$ListID_2",
          Action: "addforce",
        },
      },
    },
    }
    err := mailjetClient.Post(fmr, &data)
    if err != nil {
      fmt.Println(err)
    }
    fmt.Printf("Data array: %+v\n", data)
}
GET request
Retrieve all objects
/*
Retrieve all contacts:
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Contact
	_, _, err := mailjetClient.List("contact", &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
Use filtering
/*
Retrieve all contacts that are not in the campaign exclusion list :
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Contact
	_, _, err := mailjetClient.List("contact", &data, Filter("IsExcludedFromCampaigns", false))
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
Retrieve a single object
/*
Retrieve a specific contact ID :
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	var data []resources.Contact
	mr := &Request{
	  Resource: "contact",
	  ID: RESOURCE_ID,
	}
	err := mailjetClient.Get(mr, &data)
	if err != nil {
	  fmt.Println(err)
	}
	fmt.Printf("Data array: %+v\n", data)
}
PUT request

A 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.

Here's an example of a PUT request:

/*
Update the contact properties for a contact:
*/
package main
import (
    "fmt"
    "log"
    "os"
    mailjet "github.com/mailjet/mailjet-apiv3-go"
    "github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
    mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
    mr := &Request{
      Resource: "contactdata",
      ID: RESOURCE_ID,
    }
    fmr := &FullRequest{
      Info: mr,
      Payload: &resources.Contactdata {
      Data: []MailjetDat {
        MailjetDat {
          Name: "first_name",
          Value: "John",
        },
        MailjetDat {
          Name: "last_name",
          Value: "Smith",
        },
      },
    },
    }
    err := mailjetClient.Put(fmr)
    if err != nil {
      fmt.Println(err)
    }
}
DELETE request

Upon a successful DELETE request the response will not include a response body, but only a 204 No Content response code.

Here's an example of a DELETE request:

/*
Delete an email template:
*/
package main
import (
	"fmt"
	"log"
	"os"
	mailjet "github.com/mailjet/mailjet-apiv3-go"
	"github.com/mailjet/mailjet-apiv3-go/resources"
)
func main () {
	mailjetClient := NewMailjetClient(os.Getenv("MJ_APIKEY_PUBLIC"), os.Getenv("MJ_APIKEY_PRIVATE"))
	mr := &Request{
	  Resource: "template",
	  ID: RESOURCE_ID,
	}
	err := mailjetClient.Delete(mr)
	if err != nil {
	  fmt.Println(err)
	}
}

Contribute

Mailjet loves developers. You can be part of this project!

This wrapper is a great introduction to the open source world, check out the code!

Feel free to ask anything, and contribute:

  • Fork the project.
  • Create a new branch.
  • Implement your feature or bug fix.
  • Add documentation to it.
  • Commit, push, open a pull request and voila.

If you have suggestions on how to improve the guides, please submit an issue in our Official API Documentation repo.

Documentation

Overview

Package mailjet provides methods for interacting with the last version of the Mailjet API. The goal of this component is to simplify the usage of the MailJet API for GO developers.

For more details, see the full API Documentation at http://dev.mailjet.com/

Package mailjet provides methods for interacting with the last version of the Mailjet API. The goal of this component is to simplify the usage of the MailJet API for GO developers.

For more details, see the full API Documentation at http://dev.mailjet.com/

Index

Constants

View Source
const (
	LevelNone      = iota // No debug.
	LevelDebug            // Debug without body.
	LevelDebugFull        // Debug with body.
)

These are the different level of debug.

View Source
const (
	UserAgentBase    = "mailjet-api-v3-go"
	UserAgentVersion = "2.5.0"
)

User-Agent is formated as "UserAgentBase/UserAgentVersion;runtime.Version()".

View Source
const (
	SortDesc = SortOrder(iota)
	SortAsc
)

These are the two possible order.

View Source
const (
	HostSMTP = "in-v3.mailjet.com"
	PortSMTP = 587
)

Hostname and port for the SMTP client.

Variables

View Source
var DebugLevel int

DebugLevel defines the verbosity of the debug.

View Source
var NbAttempt = 5

NbAttempt defines the number of attempt for a request as long as StatusCode == 500.

Functions

func SetDebugOutput

func SetDebugOutput(w io.Writer)

SetDebugOutput sets the output destination for the debug.

Types

type APIErrorDetailsV31

type APIErrorDetailsV31 struct {
	ErrorClass     string
	ErrorMessage   string
	ErrorRelatedTo []string
	StatusCode     int
}

APIErrorDetailsV31 contains the information details describing a specific error

type APIFeedbackErrorV31

type APIFeedbackErrorV31 struct {
	Errors []APIErrorDetailsV31
}

APIFeedbackErrorV31 struct is composed of an error definition and the payload associated

type APIFeedbackErrorsV31

type APIFeedbackErrorsV31 struct {
	Messages []APIFeedbackErrorV31
}

APIFeedbackErrorsV31 defines the error when a validation error is being sent by the API

func (*APIFeedbackErrorsV31) Error

func (api *APIFeedbackErrorsV31) Error() string

type Attachment

type Attachment struct {
	ContentType string `json:"Content-Type"`
	Content     string
	Filename    string
}

Attachment bundles data on the file attached to the mail.

type AttachmentV31

type AttachmentV31 struct {
	ContentType   string `json:"ContentType,omitempty"`
	Base64Content string `json:"Base64Content,omitempty"`
	Filename      string `json:"Filename,omitempty"`
}

AttachmentV31 struct represent a content attachment

type AttachmentsV31

type AttachmentsV31 []AttachmentV31

AttachmentsV31 collection

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client bundles data needed by a large number of methods in order to interact with the Mailjet API.

func NewClient

func NewClient(httpCl HTTPClientInterface, smtpCl SMTPClientInterface, baseURL ...string) *Client

NewClient function

func NewMailjetClient

func NewMailjetClient(apiKeyPublic, apiKeyPrivate string, baseURL ...string) *Client

NewMailjetClient returns a new MailjetClient using an public apikey and an secret apikey to be used when authenticating to API.

func (*Client) APIKeyPrivate

func (c *Client) APIKeyPrivate() string

APIKeyPrivate returns the secret key.

func (*Client) APIKeyPublic

func (c *Client) APIKeyPublic() string

APIKeyPublic returns the public key.

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns the underlying http client

func (*Client) Delete

func (c *Client) Delete(mr *Request) (err error)

Delete is used to delete a resource.

func (*Client) DeleteData

func (mj *Client) DeleteData(mdr *DataRequest) (err error)

DeleteData is used to delete a data resource.

func (*Client) Get

func (c *Client) Get(mr *Request, resp interface{}, options ...RequestOptions) (err error)

Get issues a GET to view a resource specifying an id and stores the result in the value pointed to by res. Filters can be add via functional options. Without an specified ID in MailjetRequest, it is the same as List.

func (*Client) GetData

func (mj *Client) GetData(mdr *DataRequest, res interface{}, options ...RequestOptions) (err error)

GetData issues a GET to view a resource specifying an id and stores the result in the value pointed to by res. Filters can be add via functional options. Without an specified SourceTypeID in MailjetDataRequest, it is the same as ListData.

func (*Client) List

func (c *Client) List(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error)

List issues a GET to list the specified resource and stores the result in the value pointed to by res. Filters can be add via functional options.

func (*Client) ListData

func (mj *Client) ListData(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error)

ListData issues a GET to list the specified data resource and stores the result in the value pointed to by res. Filters can be add via functional options.

func (*Client) Post

func (c *Client) Post(fmr *FullRequest, resp interface{}, options ...RequestOptions) (err error)

Post issues a POST to create a new resource and stores the result in the value pointed to by res. Filters can be add via functional options.

func (*Client) PostData

func (mj *Client) PostData(fmdr *FullDataRequest, res interface{}, options ...RequestOptions) (err error)

PostData issues a POST to create a new data resource and stores the result in the value pointed to by res. Filters can be add via functional options.

func (*Client) Put

func (c *Client) Put(fmr *FullRequest, onlyFields []string, options ...RequestOptions) (err error)

Put is used to update a resource. Fields to be updated must be specified by the string array onlyFields. If onlyFields is nil, all fields except these with the tag read_only, are updated. Filters can be add via functional options.

func (*Client) PutData

func (mj *Client) PutData(fmr *FullDataRequest, onlyFields []string, options ...RequestOptions) (err error)

PutData is used to update a data resource. Fields to be updated must be specified by the string array onlyFields. If onlyFields is nil, all fields except these with the tag read_only, are updated. Filters can be add via functional options.

func (*Client) SendMail

func (c *Client) SendMail(data *InfoSendMail) (res *SentResult, err error)

SendMail send mail via API.

func (*Client) SendMailSMTP

func (c *Client) SendMailSMTP(info *InfoSMTP) error

SendMailSMTP send mail via SMTP.

func (*Client) SendMailV31

func (c *Client) SendMailV31(data *MessagesV31) (*ResultsV31, error)

SendMailV31 sends a mail to the send API v3.1

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string)

SetBaseURL sets the base URL

func (*Client) SetClient

func (c *Client) SetClient(client *http.Client)

SetClient allows to customize http client.

func (*Client) SetURL

func (c *Client) SetURL(baseURL string)

SetURL function to set the base url of the wrapper instance

type ClientInterface

type ClientInterface interface {
	APIKeyPublic() string
	APIKeyPrivate() string
	Client() *http.Client
	SetClient(client *http.Client)
	List(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error)
	Get(mr *Request, resp interface{}, options ...RequestOptions) error
	Post(fmr *FullRequest, resp interface{}, options ...RequestOptions) error
	Put(fmr *FullRequest, onlyFields []string, options ...RequestOptions) error
	Delete(mr *Request) error
	SendMail(data *InfoSendMail) (*SentResult, error)
	SendMailSMTP(info *InfoSMTP) (err error)
}

ClientInterface defines all Clients fuctions.

type DataRequest

type DataRequest struct {
	SourceType   string
	SourceTypeID int64
	DataType     string
	MimeType     string
	DataTypeID   int64
	LastID       bool
}

DataRequest bundles data needed to build the DATA URL.

type ErrorInfoV31

type ErrorInfoV31 struct {
	Identifier string `json:"ErrorIdentifier,omitempty"`
	Info       string `json:"ErrorInfo"`
	Message    string `json:"ErrorMessage"`
	StatusCode int    `json:"StatusCode"`
}

ErrorInfoV31 struct

func (*ErrorInfoV31) Error

func (err *ErrorInfoV31) Error() string

type FullDataRequest

type FullDataRequest struct {
	Info    *DataRequest
	Payload interface{}
}

FullDataRequest is the same as a DataRequest but with a payload.

type FullRequest

type FullRequest struct {
	Info    *Request
	Payload interface{}
}

FullRequest is the same as a Request but with a payload.

type GeneratedMessageV31

type GeneratedMessageV31 struct {
	Email       string
	MessageUUID string
	MessageID   int64
	MessageHref string
}

GeneratedMessageV31 contains info to retrieve a generated email

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient is a wrapper arround http.Client

func NewHTTPClient

func NewHTTPClient(apiKeyPublic, apiKeyPrivate string) *HTTPClient

NewHTTPClient returns a new httpClient

func (*HTTPClient) APIKeyPrivate

func (c *HTTPClient) APIKeyPrivate() string

APIKeyPrivate returns the secret key.

func (*HTTPClient) APIKeyPublic

func (c *HTTPClient) APIKeyPublic() string

APIKeyPublic returns the public key.

func (*HTTPClient) Call

func (c *HTTPClient) Call() (count, total int, err error)

Call execute the HTTP call to the API

func (*HTTPClient) Client

func (c *HTTPClient) Client() *http.Client

Client returns the underlying http client

func (*HTTPClient) Read

func (c *HTTPClient) Read(response interface{}) HTTPClientInterface

Read binds the response to the underlying http client

func (*HTTPClient) Send

Send binds the request to the underlying http client

func (*HTTPClient) SendMailV31

func (c *HTTPClient) SendMailV31(req *http.Request) (*http.Response, error)

SendMailV31 simply calls the underlying http client.Do function

func (*HTTPClient) SetClient

func (c *HTTPClient) SetClient(client *http.Client)

SetClient sets the underlying http client

func (*HTTPClient) With

func (c *HTTPClient) With(headers map[string]string) HTTPClientInterface

With binds the header to the underlying http client

type HTTPClientInterface

type HTTPClientInterface interface {
	APIKeyPublic() string
	APIKeyPrivate() string
	Client() *http.Client
	SetClient(client *http.Client)
	Send(req *http.Request) HTTPClientInterface
	SendMailV31(req *http.Request) (*http.Response, error)
	With(headers map[string]string) HTTPClientInterface
	Read(response interface{}) HTTPClientInterface
	Call() (count int, total int, err error)
}

HTTPClientInterface method definition

type HTTPClientMock

type HTTPClientMock struct {
	CallFunc        func() (int, int, error)
	SendMailV31Func func(req *http.Request) (*http.Response, error)
	// contains filtered or unexported fields
}

HTTPClientMock definition

func NewhttpClientMock

func NewhttpClientMock(valid bool) *HTTPClientMock

NewhttpClientMock instanciate new httpClientMock

func (*HTTPClientMock) APIKeyPrivate

func (c *HTTPClientMock) APIKeyPrivate() string

APIKeyPrivate returns the secret key.

func (*HTTPClientMock) APIKeyPublic

func (c *HTTPClientMock) APIKeyPublic() string

APIKeyPublic returns the public key.

func (*HTTPClientMock) Call

func (c *HTTPClientMock) Call() (int, int, error)

Call the mailjet API

func (*HTTPClientMock) Client

func (c *HTTPClientMock) Client() *http.Client

Client returns the underlying http client

func (*HTTPClientMock) Read

func (c *HTTPClientMock) Read(response interface{}) HTTPClientInterface

Read allow you to bind the response recieved through the underlying http client

func (*HTTPClientMock) Send

Send data through HTTP with the current configuration

func (*HTTPClientMock) SendMailV31

func (c *HTTPClientMock) SendMailV31(req *http.Request) (*http.Response, error)

SendMailV31 mock function

func (*HTTPClientMock) SetClient

func (c *HTTPClientMock) SetClient(client *http.Client)

SetClient allow to set the underlying http client

func (*HTTPClientMock) With

func (c *HTTPClientMock) With(headers map[string]string) HTTPClientInterface

With lets you set the http header and returns the httpClientMock with the header modified

type InfoMessagesV31

type InfoMessagesV31 struct {
	From                     *RecipientV31          `json:",omitempty"`
	ReplyTo                  *RecipientV31          `json:",omitempty"`
	Sender                   *RecipientV31          `json:",omitempty"`
	To                       *RecipientsV31         `json:",omitempty"`
	Cc                       *RecipientsV31         `json:",omitempty"`
	Bcc                      *RecipientsV31         `json:",omitempty"`
	Attachments              *AttachmentsV31        `json:",omitempty"`
	InlinedAttachments       *InlinedAttachmentsV31 `json:",omitempty"`
	Subject                  string                 `json:",omitempty"`
	TextPart                 string                 `json:",omitempty"`
	HTMLPart                 string                 `json:",omitempty"`
	Priority                 int                    `json:",omitempty"`
	CustomCampaign           string                 `json:",omitempty"`
	StatisticsContactsListID int                    `json:",omitempty"`
	MonitoringCategory       string                 `json:",omitempty"`
	DeduplicateCampaign      bool                   `json:",omitempty"`
	TrackClicks              string                 `json:",omitempty"`
	TrackOpens               string                 `json:",omitempty"`
	CustomID                 string                 `json:",omitempty"`
	Variables                map[string]interface{} `json:",omitempty"`
	EventPayload             string                 `json:",omitempty"`
	TemplateID               interface{}            `json:",omitempty"`
	TemplateLanguage         bool                   `json:",omitempty"`
	TemplateErrorReporting   *RecipientV31          `json:",omitempty"`
	TemplateErrorDeliver     bool                   `json:",omitempty"`
	Headers                  map[string]interface{} `json:",omitempty"`
}

InfoMessagesV31 represents the payload input taken by send API v3.1

type InfoSMTP

type InfoSMTP struct {
	From       string
	Recipients []string
	Header     textproto.MIMEHeader
	Content    []byte
}

InfoSMTP contains mandatory informations to send a mail via SMTP.

type InfoSendMail

type InfoSendMail struct {
	FromEmail                string
	FromName                 string
	Sender                   string      `json:",omitempty"`
	Recipients               []Recipient `json:",omitempty"`
	To                       string      `json:",omitempty"`
	Cc                       string      `json:",omitempty"`
	Bcc                      string      `json:",omitempty"`
	Subject                  string
	TextPart                 string            `json:"Text-part,omitempty"`
	HTMLPart                 string            `json:"Html-part,omitempty"`
	Attachments              []Attachment      `json:",omitempty"`
	InlineAttachments        []Attachment      `json:"Inline_attachments,omitempty"`
	MjPrio                   int               `json:"Mj-prio,omitempty"`
	MjCampaign               string            `json:"Mj-campaign,omitempty"`
	MjDeduplicateCampaign    bool              `json:"Mj-deduplicatecampaign,omitempty"`
	MjCustomID               string            `json:"Mj-CustomID,omitempty"`
	MjTemplateID             string            `json:"Mj-TemplateID,omitempty"`
	MjTemplateErrorReporting string            `json:"MJ-TemplateErrorReporting,omitempty"`
	MjTemplateLanguage       string            `json:"Mj-TemplateLanguage,omitempty"`
	MjTemplateErrorDeliver   string            `json:"MJ-TemplateErrorDeliver,omitempty"`
	MjEventPayLoad           string            `json:"Mj-EventPayLoad,omitempty"`
	Headers                  map[string]string `json:",omitempty"`
	Vars                     interface{}       `json:",omitempty"`
	Messages                 []InfoSendMail    `json:",omitempty"`
}

InfoSendMail bundles data used by the Send API.

type InlinedAttachmentV31

type InlinedAttachmentV31 struct {
	AttachmentV31 `json:",omitempty"`
	ContentID     string `json:"ContentID,omitempty"`
}

InlinedAttachmentV31 struct represent the content of an inline attachement

type InlinedAttachmentsV31

type InlinedAttachmentsV31 []InlinedAttachmentV31

InlinedAttachmentsV31 collection

type MessagesV31

type MessagesV31 struct {
	Info        []InfoMessagesV31 `json:"Messages,omitempty"`
	SandBoxMode bool              `json:",omitempty"`
}

MessagesV31 definition

type Recipient

type Recipient struct {
	Email string
	Name  string
	Vars  interface{} `json:",omitempty"`
}

Recipient bundles data on the target of the mail.

type RecipientV31

type RecipientV31 struct {
	Email string `json:",omitempty"`
	Name  string `json:",omitempty"`
}

RecipientV31 struct handle users input

type RecipientsV31

type RecipientsV31 []RecipientV31

RecipientsV31 is a collection of emails

type Request

type Request struct {
	Resource string
	ID       int64
	AltID    string
	Action   string
	ActionID int64
}

Request bundles data needed to build the URL.

type RequestError

type RequestError struct {
	ErrorInfo    string
	ErrorMessage string
	StatusCode   int
}

RequestError is the error returned by the API.

type RequestErrorV31

type RequestErrorV31 struct {
	ErrorInfo       string
	ErrorMessage    string
	StatusCode      int
	ErrorIdentifier string
}

RequestErrorV31 is the error returned by the API.

type RequestOptions

type RequestOptions func(*http.Request)

RequestOptions are functional options that modify the specified request.

func Filter

func Filter(key, value string) RequestOptions

Filter applies a filter with the defined key and value.

func Sort

func Sort(value string, order SortOrder) RequestOptions

Sort applies the Sort filter to the request.

type RequestResult

type RequestResult struct {
	Count int
	Data  interface{}
	Total int
}

RequestResult is the JSON result sent by the API.

type ResultV31

type ResultV31 struct {
	Status   string
	CustomID string `json:",omitempty"`
	To       []GeneratedMessageV31
	Cc       []GeneratedMessageV31
	Bcc      []GeneratedMessageV31
}

ResultV31 bundles the results of a sent email

type ResultsV31

type ResultsV31 struct {
	ResultsV31 []ResultV31 `json:"Messages"`
}

ResultsV31 bundles several results when several mails are sent

type SMTPClient

type SMTPClient struct {
	// contains filtered or unexported fields
}

SMTPClient is the wrapper for smtp

func NewSMTPClient

func NewSMTPClient(apiKeyPublic, apiKeyPrivate string) *SMTPClient

NewSMTPClient returns a new smtp client wrapper

func (SMTPClient) SendMail

func (s SMTPClient) SendMail(from string, to []string, msg []byte) error

SendMail wraps smtp.SendMail

type SMTPClientInterface

type SMTPClientInterface interface {
	SendMail(from string, to []string, msg []byte) error
}

SMTPClientInterface def

type SMTPClientMock

type SMTPClientMock struct {
	// contains filtered or unexported fields
}

SMTPClientMock def

func NewSMTPClientMock

func NewSMTPClientMock(valid bool) *SMTPClientMock

NewSMTPClientMock returns a new smtp client mock

func (SMTPClientMock) SendMail

func (s SMTPClientMock) SendMail(from string, to []string, msg []byte) error

SendMail wraps smtp.SendMail

type SentResult

type SentResult struct {
	Sent []struct {
		Email     string
		MessageID int64
	}
}

SentResult is the JSON result sent by the Send API.

type SortOrder

type SortOrder int

SortOrder defines the order of the result.

Directories

Path Synopsis
Package fixtures provid fake data so we can mock the `Client` struct in mailjet_client.go
Package fixtures provid fake data so we can mock the `Client` struct in mailjet_client.go
Package resources provides mailjet resources properties.
Package resources provides mailjet resources properties.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL