Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequestOptions to SendMail and SendMailV31 #64

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions mailjet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package mailjet

import (
"bytes"
"context"
"fmt"

"encoding/json"
Expand Down Expand Up @@ -95,6 +96,13 @@ func Filter(key, value string) RequestOptions {
}
}

// WithContext sets the request context
func WithContext(ctx context.Context) RequestOptions {
return func(req *http.Request) {
*req = *(req.WithContext(ctx))
}
}

// SortOrder defines the order of the result.
type SortOrder int

Expand Down Expand Up @@ -202,9 +210,9 @@ func (c *Client) Delete(mr *Request) (err error) {
}

// SendMail send mail via API.
func (c *Client) SendMail(data *InfoSendMail) (res *SentResult, err error) {
func (c *Client) SendMail(data *InfoSendMail, options ...RequestOptions) (res *SentResult, err error) {
url := c.apiBase + "/send/message"
req, err := createRequest("POST", url, data, nil)
req, err := createRequest("POST", url, data, nil, options...)
if err != nil {
return res, err
}
Expand Down Expand Up @@ -237,9 +245,9 @@ func buildMessage(header textproto.MIMEHeader, content []byte) []byte {
}

// SendMailV31 sends a mail to the send API v3.1
func (c *Client) SendMailV31(data *MessagesV31) (*ResultsV31, error) {
func (c *Client) SendMailV31(data *MessagesV31, options ...RequestOptions) (*ResultsV31, error) {
url := c.apiBase + ".1/send"
req, err := createRequest("POST", url, data, nil)
req, err := createRequest("POST", url, data, nil, options...)
if err != nil {
return nil, err
}
Expand Down