smtpapi

package
v0.0.0-...-ac35ce9 Latest Latest
Warning

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

Go to latest
Published: May 31, 2016 License: MIT Imports: 4 Imported by: 2

README

SMTP-API

This is a simple library to simplify the process of using SendGrid's X-SMTPAPI.

BuildStatus

Examples

New Header
header := smtpapi.NewSMTPAPIHeader()
Recipients
header.AddTo("addTo@mailinator.com")
// or
tos := []string{"test@test.com", "test@email.com"}
header.AddTos(tos)
// or
header.SetTos(tos)
Substitutions
header.AddSubstitution("key", "value")
// or
values := []string{"value1", "value2"}
header.AddSubstitutions("key", values)
//or
sub := make(map[string][]string)
sub["key"] = values
header.SetSubstitutions(sub)
Section
header.AddSection("section", "value")
// or
sections := make(map[string]string)
sections["section"] = "value"
header.SetSections(sections)
Category
header.AddCategory("category")
// or
categories := []string{"setCategories"}
header.AddCategories(categories)
// or
header.SetCategories(categories)
Unique Arguments
header.AddUniqueArg("key", "value")
// or
args := make(map[string]string)
args["key"] = "value"
header.SetUniqueArgs(args)
Filters
header.AddFilter("filter", "setting", "value")
// or
filter := &Filter{
  Settings: make(map[string]string),
}
filter.Settings["enable"] = "1"
filter.Settings["text/plain"] = "You can haz footers!"
header.SetFilter("footer", filter)

Send At
header.SetSendAt(1428611024)
// or
sendEachAt := []int64{1428611024, 1428611025}
header.SetSendEachAt(sendEachAt)
// or
header.AddSendEachAt(1428611024)
header.AddSendEachAt(1428611025)
ASM Group ID
asmGroupID := 1
header.SetASMGroupID(asmGroupID)
IP Pools
header.SetIpPool("testPool")
JSONString
header.JSONString() //returns a JSON string representation of the headers

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running Tests

go test -v
```

## MIT License

Documentation

Index

Constants

View Source
const Version = "0.4.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Settings map[string]string `json:"settings,omitempty"`
}

Filter represents an App/Filter and its settings

type SMTPAPIHeader

type SMTPAPIHeader struct {
	To         []string            `json:"to,omitempty"`
	Sub        map[string][]string `json:"sub,omitempty"`
	Section    map[string]string   `json:"section,omitempty"`
	Category   []string            `json:"category,omitempty"`
	UniqueArgs map[string]string   `json:"unique_args,omitempty"`
	Filters    map[string]Filter   `json:"filters,omitempty"`
	ASMGroupID int                 `json:"asm_group_id,omitempty"`
	SendAt     int64               `json:"send_at,omitempty"`
	SendEachAt []int64             `json:"send_each_at,omitempty"`
	IpPool     string              `json:"ip_pool,omitempty"`
}

SMTPAPIHeader will be used to set up X-SMTPAPI params

func NewSMTPAPIHeader

func NewSMTPAPIHeader() *SMTPAPIHeader

NewSMTPAPIHeader creates a new header struct

func (*SMTPAPIHeader) AddCategories

func (h *SMTPAPIHeader) AddCategories(categories []string)

AddCategories adds multiple categories to the Category header

func (*SMTPAPIHeader) AddCategory

func (h *SMTPAPIHeader) AddCategory(category string)

AddCategory adds a new category to the Category header

func (*SMTPAPIHeader) AddFilter

func (h *SMTPAPIHeader) AddFilter(filter, setting, value string)

AddFilter will set the specific setting for a filter

func (*SMTPAPIHeader) AddSection

func (h *SMTPAPIHeader) AddSection(section, value string)

AddSection sets the value for a specific section

func (*SMTPAPIHeader) AddSendEachAt

func (h *SMTPAPIHeader) AddSendEachAt(sendEachAt int64)

AddSendEachAt takes in a timestamp and pushes it into a list Must match length of To emails

func (*SMTPAPIHeader) AddSubstitution

func (h *SMTPAPIHeader) AddSubstitution(key, sub string)

AddSubstitution adds a new substitution to a specific key

func (*SMTPAPIHeader) AddSubstitutions

func (h *SMTPAPIHeader) AddSubstitutions(key string, subs []string)

AddSubstitutions adds a multiple substitutions to a specific key

func (*SMTPAPIHeader) AddTo

func (h *SMTPAPIHeader) AddTo(email string)

AddTo appends a single email to the To header

func (*SMTPAPIHeader) AddTos

func (h *SMTPAPIHeader) AddTos(emails []string)

AddTos appends multiple emails to the To header

func (*SMTPAPIHeader) AddUniqueArg

func (h *SMTPAPIHeader) AddUniqueArg(arg, value string)

AddUniqueArg will set the value of a specific argument

func (*SMTPAPIHeader) JSONString

func (h *SMTPAPIHeader) JSONString() (string, error)

JSONString returns the representation of the Header

func (*SMTPAPIHeader) SetASMGroupID

func (h *SMTPAPIHeader) SetASMGroupID(groupID int)

SetASMGroupID will set the value of the ASMGroupID field

func (*SMTPAPIHeader) SetCategories

func (h *SMTPAPIHeader) SetCategories(categories []string)

SetCategories will set the value of the Categories field

func (*SMTPAPIHeader) SetFilter

func (h *SMTPAPIHeader) SetFilter(filter string, value *Filter)

SetFilter takes in a Filter struct with predetermined settings and sets it for such Filter key

func (*SMTPAPIHeader) SetIpPool

func (h *SMTPAPIHeader) SetIpPool(ipPool string)

SetIpPool takes a strings and sets the IpPool field

func (*SMTPAPIHeader) SetSections

func (h *SMTPAPIHeader) SetSections(sections map[string]string)

SetSections sets the value for the Section header

func (*SMTPAPIHeader) SetSendAt

func (h *SMTPAPIHeader) SetSendAt(sendAt int64)

SetSendAt takes in a timestamp which determines when the email will be sent

func (*SMTPAPIHeader) SetSendEachAt

func (h *SMTPAPIHeader) SetSendEachAt(sendEachAt []int64)

SetSendEachAt takes an array of timestamps. Must match length of To emails

func (*SMTPAPIHeader) SetSubstitutions

func (h *SMTPAPIHeader) SetSubstitutions(sub map[string][]string)

SetSubstitutions sets the value of the substitutions on the Sub header

func (*SMTPAPIHeader) SetTos

func (h *SMTPAPIHeader) SetTos(emails []string)

SetTos sets the value of the To header

func (*SMTPAPIHeader) SetUniqueArgs

func (h *SMTPAPIHeader) SetUniqueArgs(args map[string]string)

SetUniqueArgs will set the value of the Unique_args header

Jump to

Keyboard shortcuts

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