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
- Variables
- func SetDebugOutput(w io.Writer)
- type APIErrorDetailsV31
- type APIFeedbackErrorV31
- type APIFeedbackErrorsV31
- type Attachment
- type AttachmentV31
- type AttachmentsV31
- type Client
- func (c *Client) APIKeyPrivate() string
- func (c *Client) APIKeyPublic() string
- func (c *Client) Client() *http.Client
- func (c *Client) Delete(mr *Request) (err error)
- func (mj *Client) DeleteData(mdr *DataRequest, options ...RequestOptions) (err error)
- func (c *Client) Get(mr *Request, resp interface{}, options ...RequestOptions) (err error)
- func (mj *Client) GetData(mdr *DataRequest, res interface{}, options ...RequestOptions) (err error)
- func (c *Client) List(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error)
- func (mj *Client) ListData(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error)
- func (c *Client) Post(fmr *FullRequest, resp interface{}, options ...RequestOptions) (err error)
- func (mj *Client) PostData(fmdr *FullDataRequest, res interface{}, options ...RequestOptions) (err error)
- func (c *Client) Put(fmr *FullRequest, onlyFields []string, options ...RequestOptions) (err error)
- func (mj *Client) PutData(fmr *FullDataRequest, onlyFields []string, options ...RequestOptions) (err error)
- func (c *Client) SendMail(data *InfoSendMail, options ...RequestOptions) (res *SentResult, err error)
- func (c *Client) SendMailSMTP(info *InfoSMTP) error
- func (c *Client) SendMailV31(data *MessagesV31, options ...RequestOptions) (*ResultsV31, error)
- func (c *Client) SetBaseURL(baseURL string)
- func (c *Client) SetClient(client *http.Client)
- func (c *Client) SetURL(baseURL string)
- type ClientInterface
- type ClientInterfaceV31
- type DataRequest
- type ErrorInfoV31
- type FullDataRequest
- type FullRequest
- type GeneratedMessageV31
- type HTTPClient
- func (c *HTTPClient) APIKeyPrivate() string
- func (c *HTTPClient) APIKeyPublic() string
- func (c *HTTPClient) Call() (count, total int, err error)
- func (c *HTTPClient) Client() *http.Client
- func (c *HTTPClient) Read(response interface{}) HTTPClientInterface
- func (c *HTTPClient) Send(req *http.Request) HTTPClientInterface
- func (c *HTTPClient) SendMailV31(req *http.Request) (*http.Response, error)
- func (c *HTTPClient) SetClient(client *http.Client)
- func (c *HTTPClient) With(headers map[string]string) HTTPClientInterface
- type HTTPClientInterface
- type HTTPClientMock
- func (c *HTTPClientMock) APIKeyPrivate() string
- func (c *HTTPClientMock) APIKeyPublic() string
- func (c *HTTPClientMock) Call() (int, int, error)
- func (c *HTTPClientMock) Client() *http.Client
- func (c *HTTPClientMock) Read(response interface{}) HTTPClientInterface
- func (c *HTTPClientMock) Send(req *http.Request) HTTPClientInterface
- func (c *HTTPClientMock) SendMailV31(req *http.Request) (*http.Response, error)
- func (c *HTTPClientMock) SetClient(client *http.Client)
- func (c *HTTPClientMock) With(headers map[string]string) HTTPClientInterface
- type InfoMessagesV31
- type InfoSMTP
- type InfoSendMail
- type InlinedAttachmentV31
- type InlinedAttachmentsV31
- type MessagesV31
- type Recipient
- type RecipientV31
- type RecipientsV31
- type Request
- type RequestError
- type RequestErrorV31
- type RequestOptions
- type RequestResult
- type ResultV31
- type ResultsV31
- type SMTPClient
- type SMTPClientInterface
- type SMTPClientMock
- type SentResult
- type SortOrder
Constants ¶
const ( LevelNone = iota // No debug. LevelDebug // Debug without body. LevelDebugFull // Debug with body. )
These are the different level of debug.
const ( UserAgentBase = "mailjet-api-v3-go" UserAgentVersion = "3.1.1" )
User-Agent is formated as "UserAgentBase/UserAgentVersion;runtime.Version()".
const ( SortDesc = SortOrder(iota) SortAsc )
These are the two possible order.
const ( HostSMTP = "in-v3.mailjet.com" PortSMTP = 587 )
Hostname and port for the SMTP client.
Variables ¶
var DebugLevel int
DebugLevel defines the verbosity of the debug.
var NbAttempt = 5
NbAttempt defines the number of attempt for a request as long as StatusCode == 500.
Functions ¶
func SetDebugOutput ¶
SetDebugOutput sets the output destination for the debug.
Types ¶
type APIErrorDetailsV31 ¶
type APIErrorDetailsV31 struct { // Deprecated: ErrorClass is no longer populated. Use the ErrorCode to // classify the issue. ErrorClass string ErrorCode string ErrorIdentifier 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 ¶
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 Client ¶
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 ¶
NewMailjetClient returns a new MailjetClient using an public apikey and an secret apikey to be used when authenticating to API.
func (*Client) APIKeyPrivate ¶
APIKeyPrivate returns the secret key.
func (*Client) APIKeyPublic ¶
APIKeyPublic returns the public key.
func (*Client) DeleteData ¶
func (mj *Client) DeleteData(mdr *DataRequest, options ...RequestOptions) (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, options ...RequestOptions) (res *SentResult, err error)
SendMail send mail via API.
func (*Client) SendMailSMTP ¶
SendMailSMTP send mail via SMTP.
func (*Client) SendMailV31 ¶
func (c *Client) SendMailV31(data *MessagesV31, options ...RequestOptions) (*ResultsV31, error)
SendMailV31 sends a mail to the send API v3.1
func (*Client) SetBaseURL ¶
SetBaseURL sets the base URL
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, options ...RequestOptions) error SendMail(data *InfoSendMail) (*SentResult, error) SendMailSMTP(info *InfoSMTP) (err error) }
ClientInterface defines all Client functions.
type ClientInterfaceV31 ¶
type ClientInterfaceV31 interface { ClientInterface SendMailV31(data *MessagesV31) (*ResultsV31, error) }
ClientInterfaceV31 defines the Client functions, including SendMailV31
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 ¶
func (c *HTTPClient) Send(req *http.Request) HTTPClientInterface
Send binds the request to the underlying http client
func (*HTTPClient) SendMailV31 ¶
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 ¶
func (c *HTTPClientMock) Send(req *http.Request) HTTPClientInterface
Send data through HTTP with the current configuration
func (*HTTPClientMock) SendMailV31 ¶
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 int `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"` AdvanceErrorHandling bool `json:"AdvanceErrorHandling,omitempty"` SandBoxMode bool `json:",omitempty"` }
MessagesV31 definition
type RecipientV31 ¶
RecipientV31 struct handle users input
type RequestError ¶
RequestError is the error returned by the API.
func (RequestError) Error ¶
func (e RequestError) Error() string
type RequestErrorV31 ¶
type RequestErrorV31 struct { ErrorInfo string ErrorMessage string StatusCode int ErrorIdentifier string }
RequestErrorV31 is the error returned by the API.
type RequestOptions ¶
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.
func WithContext ¶
func WithContext(ctx context.Context) RequestOptions
WithContext sets the request context
type RequestResult ¶
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
type SMTPClientInterface ¶
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
type SentResult ¶
SentResult is the JSON result sent by the Send API.
Source Files ¶
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. |