mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-10 08:32:56 +08:00
feat: test SMTP connection with browser parameters (#2986)
This commit is contained in:
@@ -27,11 +27,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type EmailForm struct {
|
type EmailForm struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Sender string `json:"sender"`
|
Sender string `json:"sender"`
|
||||||
Receivers []string `json:"receivers"`
|
Receivers []string `json:"receivers"`
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
|
ProviderObject object.Provider `json:"providerObject"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SmsForm struct {
|
type SmsForm struct {
|
||||||
@@ -74,7 +75,6 @@ func (c *ApiController) SendEmail() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// called by Casdoor SDK via Client ID & Client Secret, so the used Email provider will be the application' Email provider or the default Email provider
|
// called by Casdoor SDK via Client ID & Client Secret, so the used Email provider will be the application' Email provider or the default Email provider
|
||||||
provider, err = c.GetProviderFromContext("Email")
|
provider, err = c.GetProviderFromContext("Email")
|
||||||
@@ -84,6 +84,13 @@ func (c *ApiController) SendEmail() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if emailForm.ProviderObject.Name != "" {
|
||||||
|
if emailForm.ProviderObject.ClientSecret == "***" {
|
||||||
|
emailForm.ProviderObject.ClientSecret = provider.ClientSecret
|
||||||
|
}
|
||||||
|
provider = &emailForm.ProviderObject
|
||||||
|
}
|
||||||
|
|
||||||
// when receiver is the reserved keyword: "TestSmtpServer", it means to test the SMTP server instead of sending a real Email
|
// when receiver is the reserved keyword: "TestSmtpServer", it means to test the SMTP server instead of sending a real Email
|
||||||
if len(emailForm.Receivers) == 1 && emailForm.Receivers[0] == "TestSmtpServer" {
|
if len(emailForm.Receivers) == 1 && emailForm.Receivers[0] == "TestSmtpServer" {
|
||||||
err = object.DailSmtpServer(provider)
|
err = object.DailSmtpServer(provider)
|
||||||
|
@@ -50,6 +50,7 @@ function testEmailProvider(provider, email = "") {
|
|||||||
sender: provider.displayName,
|
sender: provider.displayName,
|
||||||
receivers: email === "" ? ["TestSmtpServer"] : [email],
|
receivers: email === "" ? ["TestSmtpServer"] : [email],
|
||||||
provider: provider.name,
|
provider: provider.name,
|
||||||
|
providerObject: provider,
|
||||||
};
|
};
|
||||||
|
|
||||||
return fetch(`${Setting.ServerUrl}/api/send-email`, {
|
return fetch(`${Setting.ServerUrl}/api/send-email`, {
|
||||||
|
Reference in New Issue
Block a user