mailjet

package module
v0.0.0-...-11f04dd Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: MIT Imports: 18 Imported by: 0

README

alt text

Build Status GoDoc Go Report Card

Mailjet Go Client

This GO library is a client for version 3 of the Mailjet API.

Getting Started

Every code examples can be find on the Mailjet Documentation

(Please refer to the Mailjet Documentation Repository to contribute to the documentation examples)

Prerequisites

Make sure you have the following requirements:

  • A Mailjet API Key
  • A Mailjet API Secret Key
  • A Go installation (v. >= 1.3)

Both API key and an API secret can be found here.

Get cosy with Mailjet and save your credentials in your environment:

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

Functional test

Under the folder tests is located a small program using the wrapper that can be used to check whether your Mailjet keys in your environment are working

go run main.go

Installation

Get package:

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

And create a new MailjetClient:

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

[...]

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

mj := mailjet.NewMailjetClient(publicKey, secretKey)

It's ready to use !

Examples

List resources

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	var res []resources.Metadata
	count, total, err := mj.List("metadata", &res)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	fmt.Printf("Count: %d\nTotal: %d\n", count, total)

	fmt.Println("Resources:")
	for _, resource := range res {
		fmt.Println(resource.Name)
	}
}

Create a resource

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	var senders []resources.Sender
	fmr := &FullRequest{
		Info:    &Request{Resource: "sender"},
		Payload: &resources.Sender{Name: "Default", Email: "qwe@qwe.com"},
	}
	err := mj.Post(fmr, &senders)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if senders != nil {
		fmt.Printf("Data struct: %+v\n", senders[0])
	}
}

Update a resource

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	fmr := &FullRequest{
		Info:    &Request{Resource: "sender", AltID: "qwe@qwe.com"},
		Payload: &resources.Sender{Name: "Bob", IsDefaultSender: true},
	}
	err := mj.Put(fmr, []string{"Name", "IsDefaultSender"})
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	} else {
		fmt.Println("Success")
	}
}

View a resource

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	var senders []resources.Sender
	info := &Request{
		Resource: "sender",
		AltID:    "qwe@qwe.com",
	}
	err := mj.Get(info, &senders)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if senders != nil {
		fmt.Printf("Sender struct: %+v\n", senders[0])
	}
}

Delete a resource

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	info := &Request{
		Resource: "sender",
		AltID:    "qwe@qwe.com",
	}
	err := mj.Delete(info)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	} else {
		fmt.Println("Success")
	}
}

Send a mail

package main

import (
	"fmt"
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/mailjet-apiv3-go/resources"
	"os"
)

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

	mj := mailjet.NewMailjetClient(publicKey, secretKey)

	param := &mailjet.InfoSendMail{
		FromEmail: "qwe@qwe.com",
		FromName:  "Bob Patrick",
		Recipients: []mailjet.Recipient{
			mailjet.Recipient{
				Email: "qwe@qwe.com",
			},
		},
		Subject:  "Hello World!",
		TextPart: "Hi there !",
	}
	res, err := mj.SendMail(param)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Success")
		fmt.Println(res)
	}
}

Send a mail through a proxy

package main

import (
	"github.com/lbryio/mailjet-apiv3-go"
	"github.com/lbryio/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)

	param := &mailjet.InfoSendMail{
		FromEmail: "qwe@qwe.com",
		FromName: "Bob Patrick",
		Recipients: []mailjet.Recipient{
			mailjet.Recipient{
				Email: "qwe@qwe.com",
			},
		},
		Subject: "Hello World!",
		TextPart: "Hi there !",
	}
	res, err := mj.SendMail(param)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Success")
		fmt.Println(res)
	}
}

Send a mail with send API v 3.1

package main

import (
	"fmt"
	"log"
	"os"

	mailjet "github.com/lbryio/mailjet-apiv3-go"
)

func main() {
	m := mailjet.NewMailjetClient(
		os.Getenv("MJ_APIKEY_PUBLIC"),
		os.Getenv("MJ_APIKEY_PRIVATE"))

	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:  "Send API v 3.1 testing",
			TextPart: "Hey, that's pretty good!",
		},
	}

	messages := mailjet.MessagesV31{Info: messagesInfo}

	res, err := m.SendMailV31(&messages)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data: %+v\n", res)
}

Contribute

Feel free to bring any contribution.

Please make sure you follow this step-by-step guide before contributing :

  • Fork the project.
  • Create a topic branch.
  • Implement your feature or bug fix.
  • Add documentation for your feature or bug fix.
  • Commit and push your changes.
  • Submit a pull request

Submit your issues here.

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.4.5"
)

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