mailjet

package
v0.0.0-...-f1b76ca Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

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/

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

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 Attachment

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

Attachment bundles data on the file attached to the mail.

type Client

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

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

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

func (*Client) Delete

func (mj *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 (mj *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 (mj *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 (mj *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 (mj *Client) SendMail(data *InfoSendMail) (res *SentResult, err error)

SendMail send mail via API.

func (*Client) SendMailSMTP

func (mj *Client) SendMailSMTP(info *InfoSMTP) (err error)

SendMailSMTP send mail via SMTP.

func (*Client) SetClient

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

SetClient allows to customize http client.

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 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 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 Recipient

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

Recipient bundles data on the target of the mail.

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