code.gitea.io/gitea@v1.22.3/modules/private/mail.go (about)

     1  // Copyright 2020 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package private
     5  
     6  import (
     7  	"context"
     8  
     9  	"code.gitea.io/gitea/modules/setting"
    10  )
    11  
    12  // Email structure holds a data for sending general emails
    13  type Email struct {
    14  	Subject string
    15  	Message string
    16  	To      []string
    17  }
    18  
    19  // SendEmail calls the internal SendEmail function
    20  // It accepts a list of usernames.
    21  // If DB contains these users it will send the email to them.
    22  // If to list == nil, it's supposed to send emails to every user present in DB
    23  func SendEmail(ctx context.Context, subject, message string, to []string) (*ResponseText, ResponseExtra) {
    24  	reqURL := setting.LocalURL + "api/internal/mail/send"
    25  
    26  	req := newInternalRequest(ctx, reqURL, "POST", Email{
    27  		Subject: subject,
    28  		Message: message,
    29  		To:      to,
    30  	})
    31  
    32  	return requestJSONResp(req, &ResponseText{})
    33  }