aboutsummaryrefslogtreecommitdiff
path: root/modules/mailer/mail.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mailer/mail.go')
-rw-r--r--modules/mailer/mail.go53
1 files changed, 45 insertions, 8 deletions
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go
index b99fc8fd..d2bf1310 100644
--- a/modules/mailer/mail.go
+++ b/modules/mailer/mail.go
@@ -86,16 +86,36 @@ func SendActiveMail(r *middleware.Render, user *models.User) {
}
msg := NewMailMessage([]string{user.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id)
+ msg.Info = fmt.Sprintf("UID: %d, send active mail", user.Id)
SendAsync(&msg)
}
-// SendNotifyMail sends mail notification of all watchers.
-func SendNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) error {
+// Send reset password email.
+func SendResetPasswdMail(r *middleware.Render, user *models.User) {
+ code := CreateUserActiveCode(user, nil)
+
+ subject := "Reset your password"
+
+ data := GetMailTmplData(user)
+ data["Code"] = code
+ body, err := r.HTMLString("mail/auth/reset_passwd", data)
+ if err != nil {
+ log.Error("mail.SendResetPasswdMail(fail to render): %v", err)
+ return
+ }
+
+ msg := NewMailMessage([]string{user.Email}, subject, body)
+ msg.Info = fmt.Sprintf("UID: %d, send reset password email", user.Id)
+
+ SendAsync(&msg)
+}
+
+// SendIssueNotifyMail sends mail notification of all watchers of repository.
+func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
watches, err := models.GetWatches(repo.Id)
if err != nil {
- return errors.New("mail.NotifyWatchers(get watches): " + err.Error())
+ return nil, errors.New("mail.NotifyWatchers(get watches): " + err.Error())
}
tos := make([]string, 0, len(watches))
@@ -106,20 +126,37 @@ func SendNotifyMail(user, owner *models.User, repo *models.Repository, issue *mo
}
u, err := models.GetUserById(uid)
if err != nil {
- return errors.New("mail.NotifyWatchers(get user): " + err.Error())
+ return nil, errors.New("mail.NotifyWatchers(get user): " + err.Error())
}
tos = append(tos, u.Email)
}
if len(tos) == 0 {
- return nil
+ return tos, nil
}
subject := fmt.Sprintf("[%s] %s", repo.Name, issue.Name)
content := fmt.Sprintf("%s<br>-<br> <a href=\"%s%s/%s/issues/%d\">View it on Gogs</a>.",
- issue.Content, base.AppUrl, owner.Name, repo.Name, issue.Index)
+ base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name),
+ base.AppUrl, owner.Name, repo.Name, issue.Index)
+ msg := NewMailMessageFrom(tos, user.Name, subject, content)
+ msg.Info = fmt.Sprintf("Subject: %s, send issue notify emails", subject)
+ SendAsync(&msg)
+ return tos, nil
+}
+
+// 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 {
+ 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.`)
+ 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)
- msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject)
+ msg.Info = fmt.Sprintf("Subject: %s, send issue mention emails", subject)
SendAsync(&msg)
return nil
}