diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-25 21:37:18 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-25 21:37:18 -0400 |
commit | c1a3d4fefbbbf332cd1cedda66e93bf40cc9713d (patch) | |
tree | b3eb7a817533770f172744b4e5dbb0360f6657bc /modules/mailer | |
parent | bc5316b82ed20a4392cac6a57b86efcd467cef09 (diff) | |
download | gitea-c1a3d4fefbbbf332cd1cedda66e93bf40cc9713d.tar.gz gitea-c1a3d4fefbbbf332cd1cedda66e93bf40cc9713d.zip |
Add mail notify for creating issue
Diffstat (limited to 'modules/mailer')
-rw-r--r-- | modules/mailer/mail.go | 40 | ||||
-rw-r--r-- | modules/mailer/mailer.go | 2 |
2 files changed, 39 insertions, 3 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 +} diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index da63e01d2a..63861d870e 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -33,7 +33,7 @@ func (m Message) Content() string { } // create mail content - content := "From: " + m.User + "<" + m.From + + content := "From: " + m.From + "<" + m.User + ">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body return content } |