Exemplo n.º 1
0
func SendMail(to string, applier BasicUser, url string) error {
	msg := gomail.NewMessage()
	msg.SetHeader("From", "*****@*****.**")
	msg.SetHeader("To", to)
	msg.SetHeader("Subject", RecommLetterSubject)

	//Write letter template
	data := struct {
		ApplyUser BasicUser
		RecommUrl string
	}{
		ApplyUser: applier,
		RecommUrl: url,
	}
	buffer := new(bytes.Buffer)
	if e := RecommLetterTmpl.Execute(buffer, &data); e != nil {
		return e
	}
	msg.SetBody("text/plain", buffer.String())

	dialer := gomail.Dialer{
		Host: "localhost",
		Port: 25,
	}
	return dialer.DialAndSend(msg)
}
Exemplo n.º 2
0
// MakeMessage prepare message to send
func (sender *Sender) MakeMessage(events notifier.EventsData, contact notifier.ContactData, trigger notifier.TriggerData, throttled bool) *gomail.Message {

	state := events.GetSubjectState()
	tags := trigger.GetTags()

	subject := fmt.Sprintf("%s %s %s (%d)", state, trigger.Name, tags, len(events))

	templateData := struct {
		Link      string
		Throttled bool
		Items     []*templateRow
	}{
		Link:      fmt.Sprintf("%s/#/events/%s", sender.FrontURI, events[0].TriggerID),
		Throttled: throttled,
		Items:     make([]*templateRow, 0, len(events)),
	}

	for _, event := range events {
		templateData.Items = append(templateData.Items, &templateRow{
			Metric:     event.Metric,
			Timestamp:  time.Unix(event.Timestamp, 0).Format("15:04 02.01.2006"),
			Oldstate:   event.OldState,
			State:      event.State,
			Value:      strconv.FormatFloat(event.Value, 'f', -1, 64),
			WarnValue:  strconv.FormatFloat(trigger.WarnValue, 'f', -1, 64),
			ErrorValue: strconv.FormatFloat(trigger.ErrorValue, 'f', -1, 64),
		})
	}

	m := gomail.NewMessage()
	m.SetHeader("From", sender.From)
	m.SetHeader("To", contact.Value)
	m.SetHeader("Subject", subject)
	m.AddAlternativeWriter("text/html", func(w io.Writer) error {
		return tpl.Execute(w, templateData)
	})

	return m
}
Exemplo n.º 3
0
func NewMail() *gomail.Message {

	m := gomail.NewMessage()
	m.SetHeader("From", "*****@*****.**")
	return m
}