Skip to content

Commit c709a28

Browse files
committed
More work on email and notification infra grafana#1456
1 parent 3706d0d commit c709a28

File tree

14 files changed

+54
-15
lines changed

14 files changed

+54
-15
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/grafana/grafana/pkg/log"
1515
"github.com/grafana/grafana/pkg/metrics"
1616
"github.com/grafana/grafana/pkg/plugins"
17-
"github.com/grafana/grafana/pkg/search"
1817
"github.com/grafana/grafana/pkg/services/eventpublisher"
1918
"github.com/grafana/grafana/pkg/services/mailer"
19+
"github.com/grafana/grafana/pkg/services/search"
2020
"github.com/grafana/grafana/pkg/services/sqlstore"
2121
"github.com/grafana/grafana/pkg/setting"
2222
"github.com/grafana/grafana/pkg/social"

pkg/api/apikey.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ func GetApiKeys(c *middleware.Context) Response {
2424
}
2525
}
2626

27-
bus.Dispatch(&m.SendEmailCommand{
28-
To: []string{"torkel@raintank.io"},
29-
From: "grafana@test.com",
30-
Subject: "Test from Grafana2",
31-
Body: "Body! hej hoppas allt är bra",
32-
})
27+
// bus.Dispatch(&m.SendEmailCommand{
28+
// To: []string{"torkel@raintank.io"},
29+
// From: "grafana@test.com",
30+
// Subject: "Test from Grafana2",
31+
// Body: "Body! hej hoppas allt är bra",
32+
// })
3333

3434
return Json(200, result)
3535
}

pkg/api/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/grafana/grafana/pkg/metrics"
1111
"github.com/grafana/grafana/pkg/middleware"
1212
m "github.com/grafana/grafana/pkg/models"
13-
"github.com/grafana/grafana/pkg/search"
13+
"github.com/grafana/grafana/pkg/services/search"
1414
"github.com/grafana/grafana/pkg/setting"
1515
"github.com/grafana/grafana/pkg/util"
1616
)

pkg/api/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package api
33
import (
44
"github.com/grafana/grafana/pkg/bus"
55
"github.com/grafana/grafana/pkg/middleware"
6-
"github.com/grafana/grafana/pkg/search"
6+
"github.com/grafana/grafana/pkg/services/search"
77
)
88

99
func Search(c *middleware.Context) {

pkg/models/emails.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package models
2+
3+
type SendEmailCommand struct {
4+
To []string
5+
From string
6+
Subject string
7+
Body string
8+
Type string
9+
Massive bool
10+
Info string
11+
}
12+
13+
type SendResetPasswordEmailCommand struct {
14+
Email string
15+
}
16+
17+
// create mail content
18+
func (m *SendEmailCommand) Content() string {
19+
// set mail type
20+
contentType := "text/plain; charset=UTF-8"
21+
if m.Type == "html" {
22+
contentType = "text/html; charset=UTF-8"
23+
}
24+
25+
// create mail content
26+
content := "From: " + m.From + "\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body
27+
return content
28+
}
29+
30+
// Create html mail command
31+
func NewSendEmailCommand(To []string, From, Subject, Body string) SendEmailCommand {
32+
return SendEmailCommand{
33+
To: To,
34+
From: From,
35+
Subject: Subject,
36+
Body: Body,
37+
Type: "html",
38+
}
39+
}

pkg/services/mailer/mailer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import (
1515

1616
"github.com/grafana/grafana/pkg/bus"
1717
"github.com/grafana/grafana/pkg/log"
18-
"github.com/grafana/grafana/pkg/notifications"
18+
m "github.com/grafana/grafana/pkg/models"
1919
"github.com/grafana/grafana/pkg/setting"
2020
)
2121

22-
var mailQueue chan *notifications.SendEmailCommand
22+
var mailQueue chan *m.SendEmailCommand
2323

2424
func Init() {
2525
bus.AddHandler("email", handleEmailCommand)
2626

27-
mailQueue = make(chan *notifications.SendEmailCommand, 10)
27+
mailQueue = make(chan *m.SendEmailCommand, 10)
2828

2929
setting.Smtp = setting.SmtpSettings{
3030
Host: "smtp.gmail.com:587",
@@ -61,7 +61,7 @@ func encodeRFC2047(text string) string {
6161
return strings.Trim(addr.String(), " <>")
6262
}
6363

64-
func handleEmailCommand(cmd *notifications.SendEmailCommand) error {
64+
func handleEmailCommand(cmd *m.SendEmailCommand) error {
6565
log.Info("Sending on queue")
6666
mailQueue <- cmd
6767
return nil
File renamed without changes.

pkg/notifications/notifications.go renamed to pkg/services/notifications/notifications.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ func Init() {
77
}
88

99
func sendResetPasswordEmail(cmd *SendResetPasswordEmailCommand) error {
10-
email := NewMailMessage("")
10+
return nil
1111
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pkg/services/sqlstore/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/grafana/grafana/pkg/bus"
99
"github.com/grafana/grafana/pkg/metrics"
1010
m "github.com/grafana/grafana/pkg/models"
11-
"github.com/grafana/grafana/pkg/search"
11+
"github.com/grafana/grafana/pkg/services/search"
1212
)
1313

1414
func init() {

0 commit comments

Comments
 (0)