Exemplo n.º 1
0
func setTo(mail *sendgrid.SGMail, event *Event) (*sendgrid.SGMail, error) {
	err := mail.AddTo(event.User.Email)
	if err != nil {
		return nil, err
	}

	return mail, nil
}
Exemplo n.º 2
0
func setBody(mail *sendgrid.SGMail, event *Event) (*sendgrid.SGMail, error) {
	if event.Body == nil {
		return nil, ErrSendgridBodyEmpty
	}

	bodyType := event.Body.Type
	switch bodyType {
	case HtmlBodyType:
		mail.SetHTML(event.Body.Content)
	case TextBodyType:
		mail.SetText(event.Body.Content)
	}

	return mail, nil
}
Exemplo n.º 3
0
func setFrom(mail *sendgrid.SGMail, event *Event) (*sendgrid.SGMail, error) {
	from, ok := event.Properties["from"]
	if !ok {
		from = DefaultFromAddress
	}

	if err := mail.SetFrom(from.(string)); err != nil {
		return nil, err
	}

	fromName, ok := event.Properties["fromName"]
	if !ok {
		fromName = DefaultFromName
	}

	mail.SetFromName(fromName.(string))

	return mail, nil
}
Exemplo n.º 4
0
func setSubject(mail *sendgrid.SGMail, event *Event) (*sendgrid.SGMail, error) {
	mail.SetSubject(event.Name)
	return mail, nil
}