🐛 fix: Outlook email authentication error (#212)
This commit is contained in:
parent
dfc79097c8
commit
671aa51f42
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,4 +12,5 @@ tmp/
|
|||||||
.env
|
.env
|
||||||
common/balancer/
|
common/balancer/
|
||||||
config.yaml
|
config.yaml
|
||||||
dist
|
dist
|
||||||
|
test.yaml
|
@ -55,6 +55,7 @@ func (s *StmpConfig) Send(to, subject, body string) error {
|
|||||||
client.SetSSL(true)
|
client.SetSSL(true)
|
||||||
case 587:
|
case 587:
|
||||||
client.SetTLSPolicy(mail.TLSMandatory)
|
client.SetTLSPolicy(mail.TLSMandatory)
|
||||||
|
client.SetSMTPAuth(mail.SMTPAuthLogin)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.DialAndSend(message); err != nil {
|
if err := client.DialAndSend(message); err != nil {
|
||||||
|
66
common/stmp/email_test.go
Normal file
66
common/stmp/email_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package stmp_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"one-api/common"
|
||||||
|
"one-api/common/stmp"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitConfig() {
|
||||||
|
viper.AddConfigPath("/one-api")
|
||||||
|
viper.SetConfigName("test")
|
||||||
|
viper.ReadInConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
type SMTPConfig struct {
|
||||||
|
Name string `mapstructure:"name"`
|
||||||
|
SMTPServer string `mapstructure:"SMTPServer"`
|
||||||
|
SMTPPort int `mapstructure:"SMTPPort"`
|
||||||
|
SMTPAccount string `mapstructure:"SMTPAccount"`
|
||||||
|
SMTPToken string `mapstructure:"SMTPToken"`
|
||||||
|
SMTPFrom string `mapstructure:"SMTPFrom"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSend(t *testing.T) {
|
||||||
|
InitConfig()
|
||||||
|
|
||||||
|
var configs []SMTPConfig
|
||||||
|
err := viper.UnmarshalKey("stmp.provider", &configs)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(configs)
|
||||||
|
email := viper.GetString("stmp.to")
|
||||||
|
fmt.Println(email)
|
||||||
|
|
||||||
|
for _, tt := range configs {
|
||||||
|
t.Run(tt.Name, func(t *testing.T) {
|
||||||
|
stmpClient := stmp.NewStmp(tt.SMTPServer, tt.SMTPPort, tt.SMTPAccount, tt.SMTPToken, tt.SMTPFrom)
|
||||||
|
code := "123456"
|
||||||
|
contentTemp := `
|
||||||
|
<p>
|
||||||
|
您正在进行邮箱验证。您的验证码为:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="text-align: center; font-size: 30px; color: #58a6ff;">
|
||||||
|
<strong>%s</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="color: #858585; padding-top: 15px;">
|
||||||
|
验证码 %d 分钟内有效,如果不是本人操作,请忽略。
|
||||||
|
</p>`
|
||||||
|
|
||||||
|
subject := fmt.Sprintf("%s邮箱验证邮件", common.SystemName)
|
||||||
|
content := fmt.Sprintf(contentTemp, code, common.VerificationValidMinutes)
|
||||||
|
|
||||||
|
err := stmpClient.Render(email, subject, content)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user