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
db0c442e
Commit
db0c442e
authored
Jun 08, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added configuration options for smtp
parent
42fc68ba
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
118 additions
and
8 deletions
+118
-8
conf/defaults.ini
+14
-0
conf/sample.ini
+14
-0
pkg/api/signup.go
+8
-0
pkg/events/events.go
+8
-0
pkg/services/notifications/mailer.go
+0
-8
pkg/services/notifications/notifications.go
+25
-0
pkg/setting/setting.go
+1
-0
pkg/setting/setting_smtp.go
+18
-0
public/emails/welcome_on_signup.html
+30
-0
No files found.
conf/defaults.ini
View file @
db0c442e
...
...
@@ -174,6 +174,20 @@ header_name = X-WEBAUTH-USER
header_property
=
username
auto_sign_up
=
true
#################################### SMTP / Emailing ##########################
[smtp]
enabled
=
false
host
=
localhost:25
user
=
password
=
cert_file
=
key_file
=
skip_verify
=
false
from_address
=
admin@grafana.localhost
[emails]
welcome_email_on_sign_up
=
false
#################################### Logging ##########################
[log]
# Either "console", "file", default is "console"
...
...
conf/sample.ini
View file @
db0c442e
...
...
@@ -173,6 +173,20 @@
;header_property = username
;auto_sign_up = true
#################################### SMTP / Emailing ##########################
[smtp]
;enabled = false
;host = localhost:25
;user =
;password =
;cert_file =
;key_file =
;skip_verify = false
;from_address = admin@grafana.localhost
[emails]
;welcome_email_on_sign_up = false
#################################### Logging ##########################
[log]
# Either "console", "file", default is "console"
...
...
pkg/api/signup.go
View file @
db0c442e
...
...
@@ -2,6 +2,7 @@ package api
import
(
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
...
...
@@ -24,6 +25,13 @@ func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
user
:=
cmd
.
Result
bus
.
Publish
(
&
events
.
UserSignedUp
{
Id
:
user
.
Id
,
Name
:
user
.
Name
,
Email
:
user
.
Email
,
Login
:
user
.
Login
,
})
loginUserWithUser
(
&
user
,
c
)
c
.
JsonOK
(
"User created and logged in"
)
...
...
pkg/events/events.go
View file @
db0c442e
...
...
@@ -70,6 +70,14 @@ type UserCreated struct {
Email
string
`json:"email"`
}
type
UserSignedUp
struct
{
Timestamp
time
.
Time
`json:"timestamp"`
Id
int64
`json:"id"`
Name
string
`json:"name"`
Login
string
`json:"login"`
Email
string
`json:"email"`
}
type
UserUpdated
struct
{
Timestamp
time
.
Time
`json:"timestamp"`
Id
int64
`json:"id"`
...
...
pkg/services/notifications/mailer.go
View file @
db0c442e
...
...
@@ -21,14 +21,6 @@ var mailQueue chan *Message
func
initMailQueue
()
{
mailQueue
=
make
(
chan
*
Message
,
10
)
setting
.
Smtp
=
setting
.
SmtpSettings
{
Host
:
"smtp.gmail.com:587"
,
User
:
"torkel.odegaard@gmail.com"
,
Password
:
"peslpwstnnloiksq"
,
FromAddress
:
"grafana@grafana.org"
,
}
go
processMailQueue
()
}
...
...
pkg/services/notifications/notifications.go
View file @
db0c442e
...
...
@@ -7,6 +7,8 @@ import (
"path/filepath"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
...
...
@@ -14,6 +16,7 @@ import (
var
mailTemplates
*
template
.
Template
var
tmplResetPassword
=
"reset_password.html"
var
tmplWelcomeOnSignUp
=
"welcome_on_signup.html"
func
Init
()
error
{
initMailQueue
()
...
...
@@ -22,6 +25,8 @@ func Init() error {
bus
.
AddHandler
(
"email"
,
validateResetPasswordCode
)
bus
.
AddHandler
(
"email"
,
sendEmailCommandHandler
)
bus
.
AddEventListener
(
userSignedUpHandler
)
mailTemplates
=
template
.
New
(
"name"
)
mailTemplates
.
Funcs
(
template
.
FuncMap
{
"Subject"
:
subjectTemplateFunc
,
...
...
@@ -50,6 +55,10 @@ func subjectTemplateFunc(obj map[string]interface{}, value string) string {
}
func
sendEmailCommandHandler
(
cmd
*
m
.
SendEmailCommand
)
error
{
if
!
setting
.
Smtp
.
Enabled
{
return
errors
.
New
(
"Grafana mailing/smtp options not configured, contact your Grafana admin"
)
}
var
buffer
bytes
.
Buffer
data
:=
cmd
.
Data
if
data
==
nil
{
...
...
@@ -98,3 +107,19 @@ func validateResetPasswordCode(query *m.ValidateResetPasswordCodeQuery) error {
query
.
Result
=
userQuery
.
Result
return
nil
}
func
userSignedUpHandler
(
evt
*
events
.
UserSignedUp
)
error
{
log
.
Info
(
"User signed up: %s, send_option: %s"
,
evt
.
Email
,
setting
.
Smtp
.
SendWelcomeEmailOnSignUp
)
if
evt
.
Email
==
""
||
!
setting
.
Smtp
.
SendWelcomeEmailOnSignUp
{
return
nil
}
return
sendEmailCommandHandler
(
&
m
.
SendEmailCommand
{
To
:
[]
string
{
evt
.
Email
},
Template
:
tmplWelcomeOnSignUp
,
Data
:
map
[
string
]
interface
{}{
"Name"
:
evt
.
Login
,
},
})
}
pkg/setting/setting.go
View file @
db0c442e
...
...
@@ -409,6 +409,7 @@ func NewConfigContext(args *CommandLineArgs) {
GoogleAnalyticsId
=
analytics
.
Key
(
"google_analytics_ua_id"
)
.
String
()
readSessionConfig
()
readSmtpSettings
()
}
func
readSessionConfig
()
{
...
...
pkg/setting/setting_smtp.go
View file @
db0c442e
package
setting
type
SmtpSettings
struct
{
Enabled
bool
Host
string
User
string
Password
string
...
...
@@ -8,4 +9,21 @@ type SmtpSettings struct {
KeyFile
string
FromAddress
string
SkipVerify
bool
SendWelcomeEmailOnSignUp
bool
}
func
readSmtpSettings
()
{
sec
:=
Cfg
.
Section
(
"smtp"
)
Smtp
.
Enabled
=
sec
.
Key
(
"enabled"
)
.
MustBool
(
false
)
Smtp
.
Host
=
sec
.
Key
(
"host"
)
.
String
()
Smtp
.
User
=
sec
.
Key
(
"user"
)
.
String
()
Smtp
.
Password
=
sec
.
Key
(
"password"
)
.
String
()
Smtp
.
CertFile
=
sec
.
Key
(
"cert_file"
)
.
String
()
Smtp
.
KeyFile
=
sec
.
Key
(
"key_file"
)
.
String
()
Smtp
.
FromAddress
=
sec
.
Key
(
"from_address"
)
.
String
()
Smtp
.
SkipVerify
=
sec
.
Key
(
"skip_verify"
)
.
MustBool
(
false
)
emails
:=
Cfg
.
Section
(
"emails"
)
Smtp
.
SendWelcomeEmailOnSignUp
=
emails
.
Key
(
"welcome_email_on_sign_up"
)
.
MustBool
(
false
)
}
public/emails/welcome_on_signup.html
0 → 100644
View file @
db0c442e
{{Subject .Subject "Welcome to Grafana"}}
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
{{.Name}} Welcome to Grafana
</title>
</head>
<body
style=
"background:#eee;"
>
<div
style=
"color:#333; font:12px/1.5 Tahoma,Arial,sans-serif;; text-shadow:1px 1px #fff; padding:0; margin:0;"
>
<div
style=
"width:600px;margin:0 auto; padding:40px 0 20px;"
>
<div
style=
"border:1px solid #d9d9d9;border-radius:3px; background:#fff; box-shadow: 0px 2px 5px rgba(0, 0, 0,.05); -webkit-box-shadow: 0px 2px 5px rgba(0, 0, 0,.05);"
>
<div
style=
"padding: 20px 15px;"
>
<div
style=
"padding:40px 15px;"
>
<div
style=
"font-size:16px; padding-bottom:30px; font-weight:bold;"
>
Hi
<span
style=
"color: #00BFFF;"
>
{{.Name}}
</span>
,
</div>
<div
style=
"font-size:14px; padding:0 15px;"
>
</div>
</div>
</div>
</div>
<div
style=
"color:#aaa;padding:10px;text-align:center;"
>
© 2014
<a
style=
"color:#888;text-decoration:none;"
target=
"_blank"
href=
"http://grafana.org"
>
Grafana
</a>
</div>
</div>
</div>
</body>
</html>
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