Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3706d0de
Commit
3706d0de
authored
Jun 04, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on email and notification infra #1456
parent
3f5ab189
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
7 deletions
+62
-7
pkg/notifications/email.go
+43
-1
pkg/notifications/notifications.go
+11
-0
pkg/services/mailer/mailer.go
+8
-4
pkg/setting/setting.go
+0
-2
No files found.
pkg/
models/emails
.go
→
pkg/
notifications/email
.go
View file @
3706d0de
package
models
package
notifications
import
(
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
type
SendEmailCommand
struct
{
To
[]
string
...
...
@@ -10,6 +15,10 @@ type SendEmailCommand struct {
Info
string
}
type
SendResetPasswordEmailCommand
struct
{
Email
string
}
// create mail content
func
(
m
*
SendEmailCommand
)
Content
()
string
{
// set mail type
...
...
@@ -22,3 +31,36 @@ func (m *SendEmailCommand) Content() string {
content
:=
"From: "
+
m
.
From
+
"
\r\n
Subject: "
+
m
.
Subject
+
"
\r\n
Content-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"
,
}
}
// Create New mail message use MailFrom and MailUser
func
NewMailMessageFrom
(
To
[]
string
,
from
,
subject
,
body
string
)
SendEmailCommand
{
return
NewSendEmailCommand
(
To
,
from
,
subject
,
body
)
}
// Create New mail message use MailFrom and MailUser
func
NewMailMessage
(
To
string
,
subject
,
body
string
)
SendEmailCommand
{
return
NewMailMessageFrom
([]
string
{
To
},
setting
.
Smtp
.
FromAddress
,
subject
,
body
)
}
func
GetMailTmplData
(
u
*
m
.
User
)
map
[
interface
{}]
interface
{}
{
data
:=
make
(
map
[
interface
{}]
interface
{},
10
)
data
[
"AppUrl"
]
=
setting
.
AppUrl
data
[
"BuildVersion"
]
=
setting
.
BuildVersion
data
[
"BuildStamp"
]
=
setting
.
BuildStamp
data
[
"BuildCommit"
]
=
setting
.
BuildCommit
if
u
!=
nil
{
data
[
"User"
]
=
u
}
return
data
}
pkg/notifications/notifications.go
0 → 100644
View file @
3706d0de
package
notifications
import
"github.com/grafana/grafana/pkg/bus"
func
Init
()
{
bus
.
AddHandler
(
"email"
,
sendResetPasswordEmail
)
}
func
sendResetPasswordEmail
(
cmd
*
SendResetPasswordEmailCommand
)
error
{
email
:=
NewMailMessage
(
""
)
}
pkg/services/mailer/mailer.go
View file @
3706d0de
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package
mailer
import
(
...
...
@@ -11,16 +15,16 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/model
s"
"github.com/grafana/grafana/pkg/notification
s"
"github.com/grafana/grafana/pkg/setting"
)
var
mailQueue
chan
*
m
.
SendEmailCommand
var
mailQueue
chan
*
notifications
.
SendEmailCommand
func
Init
()
{
bus
.
AddHandler
(
"email"
,
handleEmailCommand
)
mailQueue
=
make
(
chan
*
m
.
SendEmailCommand
,
10
)
mailQueue
=
make
(
chan
*
notifications
.
SendEmailCommand
,
10
)
setting
.
Smtp
=
setting
.
SmtpSettings
{
Host
:
"smtp.gmail.com:587"
,
...
...
@@ -57,7 +61,7 @@ func encodeRFC2047(text string) string {
return
strings
.
Trim
(
addr
.
String
(),
" <>"
)
}
func
handleEmailCommand
(
cmd
*
m
.
SendEmailCommand
)
error
{
func
handleEmailCommand
(
cmd
*
notifications
.
SendEmailCommand
)
error
{
log
.
Info
(
"Sending on queue"
)
mailQueue
<-
cmd
return
nil
...
...
pkg/setting/setting.go
View file @
3706d0de
...
...
@@ -38,7 +38,6 @@ const (
var
(
// App settings.
Env
string
=
DEV
AppName
string
AppUrl
string
AppSubUrl
string
...
...
@@ -350,7 +349,6 @@ func NewConfigContext(args *CommandLineArgs) {
setHomePath
(
args
)
loadConfiguration
(
args
)
AppName
=
Cfg
.
Section
(
""
)
.
Key
(
"app_name"
)
.
MustString
(
"Grafana"
)
Env
=
Cfg
.
Section
(
""
)
.
Key
(
"app_mode"
)
.
MustString
(
"development"
)
server
:=
Cfg
.
Section
(
"server"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment