sendgrid

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sendgrid is a utiliuty package for interfacing with Sendgrid, a third party transactional email provider

Index

Constants

View Source
const (
	Host       = "https://api.sendgrid.com"
	ContactsEP = "/v3/marketing/contacts"
	ListsEP    = "/v3/marketing/lists"
	FieldsEP   = "/v3/marketing/field_definitions"
)

constants for working with sendgrid; didn't make them configurable as these are dictated by the vendor and this is a vendor specific package

Variables

View Source
var (
	ErrNoRecipientFound = errors.New("no recipient found")
)

Functions

func AddContacts

func AddContacts(apiKey string, data *AddContactData) error

AddContacts to SendGrid marketing list

func FieldDefinitions

func FieldDefinitions(apiKey string) (string, error)

FieldDefinitions gets defs from SendGrid - get back all the definitions to re-use them in requests

func GetFirstRecipient

func GetFirstRecipient(msg *sgmail.SGMailV3) (recipient string, err error)

GetFirstRecipient is used to extract the recipient email address from a `SGMailV3` object. It iterates through the personalizations and recipients of the email and returns the first recipient's email address. If no recipient is found, it returns an error

func MarketingLists

func MarketingLists(apiKey, pageToken string) (string, error)

MarketingLists fetches lists of contacts from SendGrid

func WriteMIME

func WriteMIME(msg *sgmail.SGMailV3, path string) error

WriteMIME is used to write the contents of an email message in MIME format to a file. It takes a `SGMailV3` object, which represents the email message, and a file path as input

Types

type AddContactData

type AddContactData struct {
	ListIDs  []string   `json:"list_ids"`
	Contacts []*Contact `json:"contacts"`
}

AddContactData is a struct holding the list(s) to add to as well as a pointer to Contact info to populate

type Contact

type Contact struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Country   string `json:"country"`
}

Contact contains contact information for a user, for adding users to marketing lists and sending emails; note that Contact is also simply a "type" to use when sending emails via sendgrid and doesn't require you to create + fetch a "contact" from their API

func (Contact) FullName

func (c Contact) FullName() string

FullName attempts to construct the contact's full name from existing name fields

func (Contact) NewEmail

func (c Contact) NewEmail() *mail.Email

NewEmail returns the sendgrid email object for constructing emails

func (*Contact) ParseName

func (c *Contact) ParseName(name string)

ParseName attempts to parse a full name into first and last names on the contact

Jump to

Keyboard shortcuts

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