|
|
@ -6,6 +6,7 @@ package mailer |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/hex" |
|
|
|
"encoding/hex" |
|
|
|
|
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
@ -15,12 +16,17 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Create New mail message use MailFrom and MailUser
|
|
|
|
// Create New mail message use MailFrom and MailUser
|
|
|
|
func NewMailMessage(To []string, subject, body string) Message { |
|
|
|
func NewMailMessageFrom(To []string, from, subject, body string) Message { |
|
|
|
msg := NewHtmlMessage(To, base.MailService.User, subject, body) |
|
|
|
msg := NewHtmlMessage(To, from, subject, body) |
|
|
|
msg.User = base.MailService.User |
|
|
|
msg.User = base.MailService.User |
|
|
|
return msg |
|
|
|
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{} { |
|
|
|
func GetMailTmplData(user *models.User) map[interface{}]interface{} { |
|
|
|
data := make(map[interface{}]interface{}, 10) |
|
|
|
data := make(map[interface{}]interface{}, 10) |
|
|
|
data["AppName"] = base.AppName |
|
|
|
data["AppName"] = base.AppName |
|
|
@ -84,3 +90,33 @@ func SendActiveMail(r *middleware.Render, user *models.User) { |
|
|
|
|
|
|
|
|
|
|
|
SendAsync(&msg) |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|