Commit c709a28f by Torkel Ödegaard

More work on email and notification infra #1456

parent 3706d0de
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/search"
"github.com/grafana/grafana/pkg/services/eventpublisher" "github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/mailer" "github.com/grafana/grafana/pkg/services/mailer"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/social"
......
...@@ -24,12 +24,12 @@ func GetApiKeys(c *middleware.Context) Response { ...@@ -24,12 +24,12 @@ func GetApiKeys(c *middleware.Context) Response {
} }
} }
bus.Dispatch(&m.SendEmailCommand{ // bus.Dispatch(&m.SendEmailCommand{
To: []string{"torkel@raintank.io"}, // To: []string{"torkel@raintank.io"},
From: "grafana@test.com", // From: "grafana@test.com",
Subject: "Test from Grafana2", // Subject: "Test from Grafana2",
Body: "Body! hej hoppas allt är bra", // Body: "Body! hej hoppas allt är bra",
}) // })
return Json(200, result) return Json(200, result)
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/search" "github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util"
) )
......
...@@ -3,7 +3,7 @@ package api ...@@ -3,7 +3,7 @@ package api
import ( import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/search" "github.com/grafana/grafana/pkg/services/search"
) )
func Search(c *middleware.Context) { func Search(c *middleware.Context) {
......
package models
type SendEmailCommand struct {
To []string
From string
Subject string
Body string
Type string
Massive bool
Info string
}
type SendResetPasswordEmailCommand struct {
Email string
}
// create mail content
func (m *SendEmailCommand) Content() string {
// set mail type
contentType := "text/plain; charset=UTF-8"
if m.Type == "html" {
contentType = "text/html; charset=UTF-8"
}
// create mail content
content := "From: " + m.From + "\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body
return content
}
// Create html mail command
func NewSendEmailCommand(To []string, From, Subject, Body string) SendEmailCommand {
return SendEmailCommand{
To: To,
From: From,
Subject: Subject,
Body: Body,
Type: "html",
}
}
...@@ -15,16 +15,16 @@ import ( ...@@ -15,16 +15,16 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/notifications" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
var mailQueue chan *notifications.SendEmailCommand var mailQueue chan *m.SendEmailCommand
func Init() { func Init() {
bus.AddHandler("email", handleEmailCommand) bus.AddHandler("email", handleEmailCommand)
mailQueue = make(chan *notifications.SendEmailCommand, 10) mailQueue = make(chan *m.SendEmailCommand, 10)
setting.Smtp = setting.SmtpSettings{ setting.Smtp = setting.SmtpSettings{
Host: "smtp.gmail.com:587", Host: "smtp.gmail.com:587",
...@@ -61,7 +61,7 @@ func encodeRFC2047(text string) string { ...@@ -61,7 +61,7 @@ func encodeRFC2047(text string) string {
return strings.Trim(addr.String(), " <>") return strings.Trim(addr.String(), " <>")
} }
func handleEmailCommand(cmd *notifications.SendEmailCommand) error { func handleEmailCommand(cmd *m.SendEmailCommand) error {
log.Info("Sending on queue") log.Info("Sending on queue")
mailQueue <- cmd mailQueue <- cmd
return nil return nil
......
...@@ -7,5 +7,5 @@ func Init() { ...@@ -7,5 +7,5 @@ func Init() {
} }
func sendResetPasswordEmail(cmd *SendResetPasswordEmailCommand) error { func sendResetPasswordEmail(cmd *SendResetPasswordEmailCommand) error {
email := NewMailMessage("") return nil
} }
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/search" "github.com/grafana/grafana/pkg/services/search"
) )
func init() { func init() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment