diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 04:27:28 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 04:27:28 -0400 |
commit | 02687cbdf37be3c89005abe45c7d1f6240e339e0 (patch) | |
tree | a054383b5bfbaf64fc09d1fdc03d491640b25f6b /modules/mailer | |
parent | 07c3d497a7cffe12f4dae828dc8bd82980595b3c (diff) | |
download | gitea-02687cbdf37be3c89005abe45c7d1f6240e339e0.tar.gz gitea-02687cbdf37be3c89005abe45c7d1f6240e339e0.zip |
Add mail notify for new collaborator
Diffstat (limited to 'modules/mailer')
-rw-r--r-- | modules/mailer/mail.go | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index 834f4a898a..7516ce7e94 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "errors" "fmt" + "path" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" @@ -135,7 +136,7 @@ func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issu return tos, nil } - subject := fmt.Sprintf("[%s] %s", repo.Name, issue.Name) + subject := fmt.Sprintf("[%s] %s(#%d)", repo.Name, issue.Name, issue.Index) content := fmt.Sprintf("%s<br>-<br> <a href=\"%s%s/%s/issues/%d\">View it on Gogs</a>.", base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name), base.AppUrl, owner.Name, repo.Name, issue.Index) @@ -146,17 +147,48 @@ func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issu } // SendIssueMentionMail sends mail notification for who are mentioned in issue. -func SendIssueMentionMail(user, owner *models.User, repo *models.Repository, issue *models.Issue, tos []string) error { +func SendIssueMentionMail(r *middleware.Render, user, owner *models.User, + repo *models.Repository, issue *models.Issue, tos []string) error { + if len(tos) == 0 { return nil } - issueLink := fmt.Sprintf("%s%s/%s/issues/%d", base.AppUrl, owner.Name, repo.Name, issue.Index) - body := fmt.Sprintf(`%s mentioned you.`, user.Name) - subject := fmt.Sprintf("[%s] %s", repo.Name, issue.Name) - content := fmt.Sprintf("%s<br>-<br> <a href=\"%s\">View it on Gogs</a>.", body, issueLink) - msg := NewMailMessageFrom(tos, user.Name, subject, content) + subject := fmt.Sprintf("[%s] %s(#%d)", repo.Name, issue.Name, issue.Index) + + data := GetMailTmplData(nil) + data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index) + data["Subject"] = subject + + body, err := r.HTMLString("mail/notify/mention", data) + if err != nil { + return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err) + } + + msg := NewMailMessageFrom(tos, user.Name, subject, body) msg.Info = fmt.Sprintf("Subject: %s, send issue mention emails", subject) SendAsync(&msg) return nil } + +// SendCollaboratorMail sends mail notification to new collaborator. +func SendCollaboratorMail(r *middleware.Render, user, owner *models.User, + repo *models.Repository) error { + + subject := fmt.Sprintf("%s added you to %s", owner.Name, repo.Name) + + data := GetMailTmplData(nil) + data["RepoLink"] = path.Join(owner.Name, repo.Name) + data["Subject"] = subject + + body, err := r.HTMLString("mail/notify/collaborator", data) + if err != nil { + return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err) + } + + msg := NewMailMessage([]string{user.Email}, subject, body) + msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id) + + SendAsync(&msg) + return nil +} |