Пример #1
0
// sendEmail sends an email notification. Event specifies which notification to
// send. Valid choices are EVENT_ (see template.go).
func sendEmail(job *database.Job, event string) {
	mailServer := database.GetMailServer()

	htmlMessage := message(job, database.NotificationServiceEmail, event, TypeHTML)
	txtMessage := message(job, database.NotificationServiceEmail, event, TypeText)
	subject := emailSubject(job, event)
	recipient := mail.Address{
		Name:    job.Name,
		Address: job.Email,
	}

	message := gophermail.Message{
		From:     mailServer.From(),
		To:       []mail.Address{recipient},
		Subject:  subject,
		Body:     txtMessage,
		HTMLBody: htmlMessage,
	}

	err := gophermail.SendMail(mailServer.Server(), mailServer.Auth(), &message)

	if err != nil {
		log.Println(err)
	}
}
Пример #2
0
func viewAdminUpdateMailserver(w http.ResponseWriter, r *http.Request) {
	template := "mailserver/admin/update.html"
	ctx := make(responseContext)

	if r.Method == "POST" {
		err := mailserverAdminForm{}.update(r)

		if err == nil {
			ctx["message"] = "Update successful."
		} else {
			ctx["error"] = err.Error()
		}
	}

	server := database.GetMailServer()
	ctx["server"] = server

	render(w, r, template, ctx)
}