diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-26 14:38:14 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-26 14:38:14 +0800 |
commit | 9dbc808c7b71fc97015346704bb3d3db4918aba0 (patch) | |
tree | f0d76b189a0137bcb455e548e52805787d680fa7 /modules/mailer/mail.go | |
parent | f9024b3f43c700ae997c284458fcc1d0dfc2e9a7 (diff) | |
parent | 06cf878471af02376dfcd02b9781982a89c27a2a (diff) | |
download | gitea-9dbc808c7b71fc97015346704bb3d3db4918aba0.tar.gz gitea-9dbc808c7b71fc97015346704bb3d3db4918aba0.zip |
Merge branch 'master' of github.com:gogits/gogs
Conflicts:
models/repo.go
modules/base/tool.go
serve.go
Diffstat (limited to 'modules/mailer/mail.go')
-rw-r--r-- | modules/mailer/mail.go | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index 92acd20efb..d0decbe068 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -6,6 +6,7 @@ package mailer import ( "encoding/hex" + "errors" "fmt" "github.com/gogits/gogs/models" @@ -15,12 +16,17 @@ import ( ) // Create New mail message use MailFrom and MailUser -func NewMailMessage(To []string, subject, body string) Message { - msg := NewHtmlMessage(To, base.MailService.User, subject, body) +func NewMailMessageFrom(To []string, from, subject, body string) Message { + msg := NewHtmlMessage(To, from, subject, body) msg.User = base.MailService.User return msg } +// Create New mail message use MailFrom and MailUser +func NewMailMessage(To []string, subject, body string) Message { + return NewMailMessageFrom(To, base.MailService.User, subject, body) +} + func GetMailTmplData(user *models.User) map[interface{}]interface{} { data := make(map[interface{}]interface{}, 10) data["AppName"] = base.AppName @@ -84,3 +90,33 @@ func SendActiveMail(r *middleware.Render, user *models.User) { SendAsync(&msg) } + +// SendNotifyMail sends mail notification of all watchers. +func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { + watches, err := models.GetWatches(repoId) + if err != nil { + return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) + } + + tos := make([]string, 0, len(watches)) + for i := range watches { + uid := watches[i].UserId + if userId == uid { + continue + } + u, err := models.GetUserById(uid) + if err != nil { + return errors.New("mail.NotifyWatchers(get user): " + err.Error()) + } + tos = append(tos, u.Email) + } + + if len(tos) == 0 { + return nil + } + + msg := NewMailMessageFrom(tos, userName, subject, content) + msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) + SendAsync(&msg) + return nil +} |