mail

package
v4.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 5 Imported by: 0

README

This helper allows you to quickly and easily build a Mail object for sending email through Twilio SendGrid.

Dependencies

Quick Start

Run the example (make sure you have set your environment variable to include your SENDGRID_API_KEY).

go run examples/helpers/mail/example.go

Usage

Test

go test ./... -v

or

cd helpers/mail
go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestBody

func GetRequestBody(m *SGMailV3) []byte

GetRequestBody ...

Types

type Asm

type Asm struct {
	GroupID         int   `json:"group_id,omitempty"`
	GroupsToDisplay []int `json:"groups_to_display,omitempty"`
}

Asm contains Grpip Id and int array of groups ID

func NewASM

func NewASM() *Asm

NewASM ...

func (*Asm) AddGroupsToDisplay

func (a *Asm) AddGroupsToDisplay(groupsToDisplay ...int) *Asm

AddGroupsToDisplay ...

func (*Asm) SetGroupID

func (a *Asm) SetGroupID(groupID int) *Asm

SetGroupID ...

type Attachment

type Attachment struct {
	Content     string `json:"content,omitempty"`
	Type        string `json:"type,omitempty"`
	Name        string `json:"name,omitempty"`
	Filename    string `json:"filename,omitempty"`
	Disposition string `json:"disposition,omitempty"`
	ContentID   string `json:"content_id,omitempty"`
}

Attachment holds attachement information

func NewAttachment

func NewAttachment() *Attachment

NewAttachment ...

func (*Attachment) SetContent

func (a *Attachment) SetContent(content string) *Attachment

SetContent ...

func (*Attachment) SetContentID

func (a *Attachment) SetContentID(contentID string) *Attachment

SetContentID ...

func (*Attachment) SetDisposition

func (a *Attachment) SetDisposition(disposition string) *Attachment

SetDisposition ...

func (*Attachment) SetFilename

func (a *Attachment) SetFilename(filename string) *Attachment

SetFilename ...

func (*Attachment) SetType

func (a *Attachment) SetType(contentType string) *Attachment

SetType ...

type BccSetting

type BccSetting struct {
	Enable *bool  `json:"enable,omitempty"`
	Email  string `json:"email,omitempty"`
}

BccSetting holds email bcc setings to enable of disable default is false

func NewBCCSetting

func NewBCCSetting() *BccSetting

NewBCCSetting ...

func (*BccSetting) SetEmail

func (b *BccSetting) SetEmail(email string) *BccSetting

SetEmail ...

func (*BccSetting) SetEnable

func (b *BccSetting) SetEnable(enable bool) *BccSetting

SetEnable ...

type ClickTrackingSetting

type ClickTrackingSetting struct {
	Enable     *bool `json:"enable,omitempty"`
	EnableText *bool `json:"enable_text,omitempty"`
}

ClickTrackingSetting ...

func NewClickTrackingSetting

func NewClickTrackingSetting() *ClickTrackingSetting

NewClickTrackingSetting ...

func (*ClickTrackingSetting) SetEnable

func (c *ClickTrackingSetting) SetEnable(enable bool) *ClickTrackingSetting

SetEnable ...

func (*ClickTrackingSetting) SetEnableText

func (c *ClickTrackingSetting) SetEnableText(enableText bool) *ClickTrackingSetting

SetEnableText ...

type Content

type Content struct {
	Type  string `json:"type,omitempty"`
	Value string `json:"value,omitempty"`
}

Content defines content of the mail body

func NewContent

func NewContent(contentType string, value string) *Content

NewContent ...

type Email

type Email struct {
	Name    string `json:"name,omitempty"`
	Address string `json:"email,omitempty"`
}

Email holds email name and address info

func NewEmail

func NewEmail(name string, address string) *Email

NewEmail ...

func ParseEmail

func ParseEmail(emailInfo string) (*Email, error)

ParseEmail parses a string that contains an rfc822 formatted email address and returns an instance of *Email.

type FooterSetting

type FooterSetting struct {
	Enable *bool  `json:"enable,omitempty"`
	Text   string `json:"text,omitempty"`
	Html   string `json:"html,omitempty"`
}

FooterSetting holds enaable/disable settings and the format of footer i.e HTML/Text

func NewFooterSetting

func NewFooterSetting() *FooterSetting

NewFooterSetting ...

func (*FooterSetting) SetEnable

func (f *FooterSetting) SetEnable(enable bool) *FooterSetting

SetEnable ...

func (*FooterSetting) SetHTML

func (f *FooterSetting) SetHTML(html string) *FooterSetting

SetHTML ...

func (*FooterSetting) SetText

func (f *FooterSetting) SetText(text string) *FooterSetting

SetText ...

type GaSetting

type GaSetting struct {
	Enable          *bool  `json:"enable,omitempty"`
	CampaignSource  string `json:"utm_source,omitempty"`
	CampaignTerm    string `json:"utm_term,omitempty"`
	CampaignContent string `json:"utm_content,omitempty"`
	CampaignName    string `json:"utm_campaign,omitempty"`
	CampaignMedium  string `json:"utm_medium,omitempty"`
}

GaSetting ...

func NewGaSetting

func NewGaSetting() *GaSetting

NewGaSetting ...

func (*GaSetting) SetCampaignContent

func (g *GaSetting) SetCampaignContent(campaignContent string) *GaSetting

SetCampaignContent ...

func (*GaSetting) SetCampaignMedium

func (g *GaSetting) SetCampaignMedium(campaignMedium string) *GaSetting

SetCampaignMedium ...

func (*GaSetting) SetCampaignName

func (g *GaSetting) SetCampaignName(campaignName string) *GaSetting

SetCampaignName ...

func (*GaSetting) SetCampaignSource

func (g *GaSetting) SetCampaignSource(campaignSource string) *GaSetting

SetCampaignSource ...

func (*GaSetting) SetCampaignTerm

func (g *GaSetting) SetCampaignTerm(campaignTerm string) *GaSetting

SetCampaignTerm ...

func (*GaSetting) SetEnable

func (g *GaSetting) SetEnable(enable bool) *GaSetting

SetEnable ...

type MailSettings

type MailSettings struct {
	BCC                         *BccSetting       `json:"bcc,omitempty"`
	BypassListManagement        *Setting          `json:"bypass_list_management,omitempty"`
	BypassSpamManagement        *Setting          `json:"bypass_spam_management,omitempty"`
	BypassBounceManagement      *Setting          `json:"bypass_bounce_management,omitempty"`
	BypassUnsubscribeManagement *Setting          `json:"bypass_unsubscribe_management,omitempty"`
	Footer                      *FooterSetting    `json:"footer,omitempty"`
	SandboxMode                 *Setting          `json:"sandbox_mode,omitempty"`
	SpamCheckSetting            *SpamCheckSetting `json:"spam_check,omitempty"`
}

MailSettings defines mail and spamCheck settings

func NewMailSettings

func NewMailSettings() *MailSettings

NewMailSettings ...

func (*MailSettings) SetBCC

func (m *MailSettings) SetBCC(bcc *BccSetting) *MailSettings

SetBCC ...

func (*MailSettings) SetBypassBounceManagement

func (m *MailSettings) SetBypassBounceManagement(bypassBounceManagement *Setting) *MailSettings

SetBypassBounceManagement ...

func (*MailSettings) SetBypassListManagement

func (m *MailSettings) SetBypassListManagement(bypassListManagement *Setting) *MailSettings

SetBypassListManagement ...

func (*MailSettings) SetBypassSpamManagement

func (m *MailSettings) SetBypassSpamManagement(bypassSpamManagement *Setting) *MailSettings

SetBypassSpamManagement ...

func (*MailSettings) SetBypassUnsubscribeManagement

func (m *MailSettings) SetBypassUnsubscribeManagement(bypassUnsubscribeManagement *Setting) *MailSettings

SetBypassUnsubscribeManagement ...

func (*MailSettings) SetFooter

func (m *MailSettings) SetFooter(footerSetting *FooterSetting) *MailSettings

SetFooter ...

func (*MailSettings) SetSandboxMode

func (m *MailSettings) SetSandboxMode(sandboxMode *Setting) *MailSettings

SetSandboxMode ...

func (*MailSettings) SetSpamCheckSettings

func (m *MailSettings) SetSpamCheckSettings(spamCheckSetting *SpamCheckSetting) *MailSettings

SetSpamCheckSettings ...

type OpenTrackingSetting

type OpenTrackingSetting struct {
	Enable          *bool  `json:"enable,omitempty"`
	SubstitutionTag string `json:"substitution_tag,omitempty"`
}

OpenTrackingSetting ...

func NewOpenTrackingSetting

func NewOpenTrackingSetting() *OpenTrackingSetting

NewOpenTrackingSetting ...

func (*OpenTrackingSetting) SetEnable

func (o *OpenTrackingSetting) SetEnable(enable bool) *OpenTrackingSetting

SetEnable ...

func (*OpenTrackingSetting) SetSubstitutionTag

func (o *OpenTrackingSetting) SetSubstitutionTag(subTag string) *OpenTrackingSetting

SetSubstitutionTag ...

type Personalization

type Personalization struct {
	To                  []*Email               `json:"to,omitempty"`
	From                *Email                 `json:"from,omitempty"`
	CC                  []*Email               `json:"cc,omitempty"`
	BCC                 []*Email               `json:"bcc,omitempty"`
	Subject             string                 `json:"subject,omitempty"`
	Headers             map[string]string      `json:"headers,omitempty"`
	Substitutions       map[string]string      `json:"substitutions,omitempty"`
	CustomArgs          map[string]string      `json:"custom_args,omitempty"`
	DynamicTemplateData map[string]interface{} `json:"dynamic_template_data,omitempty"`
	Categories          []string               `json:"categories,omitempty"`
	SendAt              int                    `json:"send_at,omitempty"`
}

Personalization holds mail body struct

func NewPersonalization

func NewPersonalization() *Personalization

NewPersonalization ...

func (*Personalization) AddBCCs

func (p *Personalization) AddBCCs(bcc ...*Email)

AddBCCs ...

func (*Personalization) AddCCs

func (p *Personalization) AddCCs(cc ...*Email)

AddCCs ...

func (*Personalization) AddFrom

func (p *Personalization) AddFrom(from *Email)

AddFrom ...

func (*Personalization) AddTos

func (p *Personalization) AddTos(to ...*Email)

AddTos ...

func (*Personalization) SetCustomArg

func (p *Personalization) SetCustomArg(key string, value string)

SetCustomArg ...

func (*Personalization) SetDynamicTemplateData

func (p *Personalization) SetDynamicTemplateData(key string, value interface{})

SetDynamicTemplateData ...

func (*Personalization) SetHeader

func (p *Personalization) SetHeader(key string, value string)

SetHeader ...

func (*Personalization) SetSendAt

func (p *Personalization) SetSendAt(sendAt int)

SetSendAt ...

func (*Personalization) SetSubstitution

func (p *Personalization) SetSubstitution(key string, value string)

SetSubstitution ...

type SGMailV3

type SGMailV3 struct {
	From             *Email             `json:"from,omitempty"`
	Subject          string             `json:"subject,omitempty"`
	Personalizations []*Personalization `json:"personalizations,omitempty"`
	Content          []*Content         `json:"content,omitempty"`
	Attachments      []*Attachment      `json:"attachments,omitempty"`
	TemplateID       string             `json:"template_id,omitempty"`
	Sections         map[string]string  `json:"sections,omitempty"`
	Headers          map[string]string  `json:"headers,omitempty"`
	Categories       []string           `json:"categories,omitempty"`
	CustomArgs       map[string]string  `json:"custom_args,omitempty"`
	SendAt           int                `json:"send_at,omitempty"`
	BatchID          string             `json:"batch_id,omitempty"`
	Asm              *Asm               `json:"asm,omitempty"`
	IPPoolID         string             `json:"ip_pool_name,omitempty"`
	MailSettings     *MailSettings      `json:"mail_settings,omitempty"`
	TrackingSettings *TrackingSettings  `json:"tracking_settings,omitempty"`
	ReplyTo          *Email             `json:"reply_to,omitempty"`
}

SGMailV3 contains mail struct

func NewSingleEmail

func NewSingleEmail(from *Email, subject string, to *Email, plainTextContent string, htmlContent string) *SGMailV3

NewSingleEmail ...

func NewSingleEmailPlainText

func NewSingleEmailPlainText(from *Email, subject string, to *Email, plainTextContent string) *SGMailV3

NewSingleEmailPlainText is used to build *SGMailV3 object having only 'plain-text' as email content.

func NewV3Mail

func NewV3Mail() *SGMailV3

NewV3Mail ...

func NewV3MailInit

func NewV3MailInit(from *Email, subject string, to *Email, content ...*Content) *SGMailV3

NewV3MailInit ...

func (*SGMailV3) AddAttachment

func (s *SGMailV3) AddAttachment(a ...*Attachment) *SGMailV3

AddAttachment ...

func (*SGMailV3) AddCategories

func (s *SGMailV3) AddCategories(category ...string) *SGMailV3

AddCategories ...

func (*SGMailV3) AddContent

func (s *SGMailV3) AddContent(c ...*Content) *SGMailV3

AddContent ...

func (*SGMailV3) AddPersonalizations

func (s *SGMailV3) AddPersonalizations(p ...*Personalization) *SGMailV3

AddPersonalizations ...

func (*SGMailV3) AddSection

func (s *SGMailV3) AddSection(key string, value string) *SGMailV3

AddSection ...

func (*SGMailV3) SetASM

func (s *SGMailV3) SetASM(asm *Asm) *SGMailV3

SetASM ...

func (*SGMailV3) SetBatchID

func (s *SGMailV3) SetBatchID(batchID string) *SGMailV3

SetBatchID ...

func (*SGMailV3) SetCustomArg

func (s *SGMailV3) SetCustomArg(key string, value string) *SGMailV3

SetCustomArg ...

func (*SGMailV3) SetFrom

func (s *SGMailV3) SetFrom(e *Email) *SGMailV3

SetFrom ...

func (*SGMailV3) SetHeader

func (s *SGMailV3) SetHeader(key string, value string) *SGMailV3

SetHeader ...

func (*SGMailV3) SetIPPoolID

func (s *SGMailV3) SetIPPoolID(ipPoolID string) *SGMailV3

SetIPPoolID ...

func (*SGMailV3) SetMailSettings

func (s *SGMailV3) SetMailSettings(mailSettings *MailSettings) *SGMailV3

SetMailSettings ...

func (*SGMailV3) SetReplyTo

func (s *SGMailV3) SetReplyTo(e *Email) *SGMailV3

SetReplyTo ...

func (*SGMailV3) SetSendAt

func (s *SGMailV3) SetSendAt(sendAt int) *SGMailV3

SetSendAt ...

func (*SGMailV3) SetTemplateID

func (s *SGMailV3) SetTemplateID(templateID string) *SGMailV3

SetTemplateID ...

func (*SGMailV3) SetTrackingSettings

func (s *SGMailV3) SetTrackingSettings(trackingSettings *TrackingSettings) *SGMailV3

SetTrackingSettings ...

type SandboxModeSetting

type SandboxModeSetting struct {
	Enable      *bool             `json:"enable,omitempty"`
	ForwardSpam *bool             `json:"forward_spam,omitempty"`
	SpamCheck   *SpamCheckSetting `json:"spam_check,omitempty"`
}

SandboxModeSetting ...

func NewSandboxModeSetting

func NewSandboxModeSetting(enable bool, forwardSpam bool, spamCheck *SpamCheckSetting) *SandboxModeSetting

NewSandboxModeSetting ...

type Setting

type Setting struct {
	Enable *bool `json:"enable,omitempty"`
}

Setting enables the mail settings

func NewSetting

func NewSetting(enable bool) *Setting

NewSetting ...

type SpamCheckSetting

type SpamCheckSetting struct {
	Enable        *bool  `json:"enable,omitempty"`
	SpamThreshold int    `json:"threshold,omitempty"`
	PostToURL     string `json:"post_to_url,omitempty"`
}

SpamCheckSetting holds spam settings and which can be enable or disable and contains spamThreshold value

func NewSpamCheckSetting

func NewSpamCheckSetting() *SpamCheckSetting

NewSpamCheckSetting ...

func (*SpamCheckSetting) SetEnable

func (s *SpamCheckSetting) SetEnable(enable bool) *SpamCheckSetting

SetEnable ...

func (*SpamCheckSetting) SetPostToURL

func (s *SpamCheckSetting) SetPostToURL(postToURL string) *SpamCheckSetting

SetPostToURL ...

func (*SpamCheckSetting) SetSpamThreshold

func (s *SpamCheckSetting) SetSpamThreshold(spamThreshold int) *SpamCheckSetting

SetSpamThreshold ...

type SubscriptionTrackingSetting

type SubscriptionTrackingSetting struct {
	Enable          *bool  `json:"enable,omitempty"`
	Text            string `json:"text,omitempty"`
	Html            string `json:"html,omitempty"`
	SubstitutionTag string `json:"substitution_tag,omitempty"`
}

SubscriptionTrackingSetting ...

func NewSubscriptionTrackingSetting

func NewSubscriptionTrackingSetting() *SubscriptionTrackingSetting

NewSubscriptionTrackingSetting ...

func (*SubscriptionTrackingSetting) SetEnable

SetEnable ...

func (*SubscriptionTrackingSetting) SetHTML

SetHTML ...

func (*SubscriptionTrackingSetting) SetSubstitutionTag

func (s *SubscriptionTrackingSetting) SetSubstitutionTag(subTag string) *SubscriptionTrackingSetting

SetSubstitutionTag ...

func (*SubscriptionTrackingSetting) SetText

SetText ...

type TrackingSettings

type TrackingSettings struct {
	ClickTracking        *ClickTrackingSetting        `json:"click_tracking,omitempty"`
	OpenTracking         *OpenTrackingSetting         `json:"open_tracking,omitempty"`
	SubscriptionTracking *SubscriptionTrackingSetting `json:"subscription_tracking,omitempty"`
	GoogleAnalytics      *GaSetting                   `json:"ganalytics,omitempty"`
	BCC                  *BccSetting                  `json:"bcc,omitempty"`
	BypassListManagement *Setting                     `json:"bypass_list_management,omitempty"`
	Footer               *FooterSetting               `json:"footer,omitempty"`
	SandboxMode          *SandboxModeSetting          `json:"sandbox_mode,omitempty"`
}

TrackingSettings holds tracking settings and mail settings

func NewTrackingSettings

func NewTrackingSettings() *TrackingSettings

NewTrackingSettings ...

func (*TrackingSettings) SetClickTracking

func (t *TrackingSettings) SetClickTracking(clickTracking *ClickTrackingSetting) *TrackingSettings

SetClickTracking ...

func (*TrackingSettings) SetGoogleAnalytics

func (t *TrackingSettings) SetGoogleAnalytics(googleAnalytics *GaSetting) *TrackingSettings

SetGoogleAnalytics ...

func (*TrackingSettings) SetOpenTracking

func (t *TrackingSettings) SetOpenTracking(openTracking *OpenTrackingSetting) *TrackingSettings

SetOpenTracking ...

func (*TrackingSettings) SetSubscriptionTracking

func (t *TrackingSettings) SetSubscriptionTracking(subscriptionTracking *SubscriptionTrackingSetting) *TrackingSettings

SetSubscriptionTracking ...

Jump to

Keyboard shortcuts

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