Ejemplo n.º 1
0
func (d *SendGridDriver) Send(language, defaultLang string, t *pb.Target, temp *template.TemplateGroup) error {
	m := t.GetEmail()

	message := sendgrid.NewMail()

	if len(m.FromEmail) > 0 {
		message.SetFrom(m.FromEmail)
	} else {
		message.SetFrom(d.DefaultFromEmail)
	}

	message.AddTos(m.ToEmail)
	message.AddCcs(m.Cc)
	message.AddBccs(m.Bcc)

	if len(m.ReplyTo) > 0 {
		message.SetReplyTo(m.ReplyTo)
	}
	if len(m.ToName) > 0 {
		message.AddToNames(m.ToName)
	}
	if len(m.FromName) > 0 {
		message.SetFromName(m.FromName)
	} else {
		message.SetFromName(d.DefaultFromName)
	}

	if txt := temp.GetText(template.TemplateHtml, language, defaultLang, m.Data); len(txt) > 0 {
		message.SetHTML(txt)
	}

	if txt := temp.GetText(template.TemplateText, language, defaultLang, m.Data); len(txt) > 0 {
		message.SetText(txt)
	}

	if txt := temp.GetText(template.TemplateEmailSubject, language, defaultLang, m.Data); len(txt) > 0 {
		message.SetSubject(txt)
	} else {
		message.SetSubject(m.Subject)
	}

	r := d.Client.Send(message)
	if r != nil {
		log.Errorln(r)
	}
	return r
}
Ejemplo n.º 2
0
func getTargetType(t *pb.Target) drivers.NotificationType {
	switch t.GetBackend().(type) {
	case *pb.Target_Email:
		return drivers.TypeEmail
	case *pb.Target_Push:
		return drivers.TypePush
	case *pb.Target_Sms:
		return drivers.TypeSms
	default:
		return drivers.TypeUnknown
	}
}
Ejemplo n.º 3
0
func getTargetType(t *pb.Target) string {
	switch t.GetBackend().(type) {
	case *pb.Target_Email:
		return drivers.TypeEmail
	case *pb.Target_Push:
		return drivers.TypePush
	case *pb.Target_Sms:
		return drivers.TypeSms
	default:
		return ""
	}
}