Exemplo n.º 1
0
// 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 nil, errors.New("mail.NotifyWatchers(get watches): " + err.Error())
	}

	tos := make([]string, 0, len(watches))
	for i := range watches {
		uid := watches[i].UserId
		if user.Id == uid {
			continue
		}
		u, err := models.GetUserById(uid)
		if err != nil {
			return nil, errors.New("mail.NotifyWatchers(get user): " + err.Error())
		}
		tos = append(tos, u.Email)
	}

	if len(tos) == 0 {
		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>.",
		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
}
Exemplo n.º 2
0
Arquivo: mail.go Projeto: JREAMLU/gogs
// 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
}