emailsender

package module
v0.0.0-...-cab9e6e Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSendgridEmail

func CreateSendgridEmail(emailRequest *SendEmailRequestDTO) *mail.SGMailV3

CreateSendgridEmail creates a sendgrid email object using the sendgrid mail library. See: https://github.com/sendgrid/sendgrid-go/blob/main/examples/helpers/mail/example.go

func CreateSendgridRequest

func CreateSendgridRequest(emailRequest *SendEmailRequestDTO) rest.Request

CreateSendgridRequest creates a sendgrid HTTP request object. See: https://github.com/sendgrid/sendgrid-go/blob/main/use-cases/README.md

func SendgridPubSubHandler

func SendgridPubSubHandler(ctx context.Context, e event.Event) error

SendgridPubSubHandler consumes a CloudEvent message and sends an email via the sendgrid API. If an error is returned by the handler, pubsub will retry the message. If nil is returned, pubsub will regard this as an "ack" and remove the message from the queue. This function intentionally processes a single 'to' email at a time. While this is less efficient it makes working with sendgrid templates easier. Note: We might decide to create a separate handler for marketing emails in the future - since these can be processed in bulk.

Types

type MessagePublishedData

type MessagePublishedData struct {
	Subscription string        `json:"subscription"`
	Message      PubSubMessage `json:"message"`
}

MessagePublishedData contains the full Pub/Sub message See the documentation for more details: https://cloud.google.com/eventarc/docs/cloudevents#pubsub

func MessageFromEvent

func MessageFromEvent(e event.Event) (*MessagePublishedData, error)

MessageFromEvent - parses a pub-sub message from the cloud event.

type PubSubMessage

type PubSubMessage struct {
	Attributes  map[string]string `json:"attributes,omitempty"`
	Data        []byte            `json:"data"`
	MessageID   string            `json:"messageId,omitempty"`
	PublishTime time.Time         `json:"publishTime,omitempty"`
	OrderingKey string            `json:"orderingKey,omitempty"`
}

PubSubMessage is the payload of a Pub/Sub event. See the documentation for more details: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage

type SendEmailRequestDTO

type SendEmailRequestDTO struct {
	FromName          string            `json:"fromName"`
	FromAddress       string            `json:"fromAddress"`
	ToName            string            `json:"toName"`
	ToAddress         string            `json:"toAddress"`
	TemplateID        string            `json:"templateId"`
	TemplateVariables map[string]string `json:"templateVariables"`
}

SendEmailRequestDTO is a data type used to send an email via sendgrid.

func ParseEmailRequestDTO

func ParseEmailRequestDTO(e event.Event) (*SendEmailRequestDTO, error)

ParseEmailRequestDTO parses a CloudEvent message and returns a SendEmailRequestDTO.

Jump to

Keyboard shortcuts

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