Add SendMail to plugin API (#10082)

* Add SendMail to plugin API

* Update per feedback

Co-Authored-By: cpanato <ctadeu@gmail.com>
This commit is contained in:
Carlos Tadeu Panato Junior
2019-01-10 10:06:14 +01:00
committed by GitHub
parent 1a3ccaf305
commit f8b87cbe2d
6 changed files with 112 additions and 0 deletions

View File

@@ -465,6 +465,11 @@ type API interface {
// do not need to add that info.
// keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob
LogWarn(msg string, keyValuePairs ...interface{})
// SendMail sends an email to a specific address
//
// Minimum server version: 5.7
SendMail(to, subject, htmlBody string) *model.AppError
}
var handshake = plugin.HandshakeConfig{

View File

@@ -3556,3 +3556,33 @@ func (s *apiRPCServer) LogWarn(args *Z_LogWarnArgs, returns *Z_LogWarnReturns) e
}
return nil
}
type Z_SendMailArgs struct {
A string
B string
C string
}
type Z_SendMailReturns struct {
A *model.AppError
}
func (g *apiRPCClient) SendMail(to, subject, htmlBody string) *model.AppError {
_args := &Z_SendMailArgs{to, subject, htmlBody}
_returns := &Z_SendMailReturns{}
if err := g.client.Call("Plugin.SendMail", _args, _returns); err != nil {
log.Printf("RPC call to SendMail API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) SendMail(args *Z_SendMailArgs, returns *Z_SendMailReturns) error {
if hook, ok := s.impl.(interface {
SendMail(to, subject, htmlBody string) *model.AppError
}); ok {
returns.A = hook.SendMail(args.A, args.B, args.C)
} else {
return encodableError(fmt.Errorf("API SendMail called but not implemented."))
}
return nil
}

View File

@@ -1974,6 +1974,22 @@ func (_m *API) SendEphemeralPost(userId string, post *model.Post) *model.Post {
return r0
}
// SendMail provides a mock function with given fields: to, subject, htmlBody
func (_m *API) SendMail(to string, subject string, htmlBody string) *model.AppError {
ret := _m.Called(to, subject, htmlBody)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, string, string) *model.AppError); ok {
r0 = rf(to, subject, htmlBody)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
}
return r0
}
// SetProfileImage provides a mock function with given fields: userId, data
func (_m *API) SetProfileImage(userId string, data []byte) *model.AppError {
ret := _m.Called(userId, data)