🎨 更新项目版本
This commit is contained in:
@@ -60,8 +60,14 @@ func send(to []string, subject string, body string) error {
|
||||
host := global.GlobalConfig.Host
|
||||
port := global.GlobalConfig.Port
|
||||
isSSL := global.GlobalConfig.IsSSL
|
||||
isLoginAuth := global.GlobalConfig.IsLoginAuth
|
||||
|
||||
auth := smtp.PlainAuth("", from, secret, host)
|
||||
var auth smtp.Auth
|
||||
if isLoginAuth {
|
||||
auth = LoginAuth(from, secret)
|
||||
} else {
|
||||
auth = smtp.PlainAuth("", from, secret, host)
|
||||
}
|
||||
e := email.NewEmail()
|
||||
if nickname != "" {
|
||||
e.From = fmt.Sprintf("%s <%s>", nickname, from)
|
||||
@@ -80,3 +86,37 @@ func send(to []string, subject string, body string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// LoginAuth 用于IBM、微软邮箱服务器的LOGIN认证方式
|
||||
type loginAuth struct {
|
||||
username, password string
|
||||
}
|
||||
|
||||
func LoginAuth(username, password string) smtp.Auth {
|
||||
return &loginAuth{username, password}
|
||||
}
|
||||
|
||||
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
||||
return "LOGIN", []byte{}, nil
|
||||
}
|
||||
|
||||
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
||||
if more {
|
||||
switch string(fromServer) {
|
||||
case "Username:":
|
||||
return []byte(a.username), nil
|
||||
case "Password:":
|
||||
return []byte(a.password), nil
|
||||
default:
|
||||
// 邮箱服务器可能发送的其他提示信息
|
||||
prompt := strings.ToLower(string(fromServer))
|
||||
if strings.Contains(prompt, "username") || strings.Contains(prompt, "user") {
|
||||
return []byte(a.username), nil
|
||||
}
|
||||
if strings.Contains(prompt, "password") || strings.Contains(prompt, "pass") {
|
||||
return []byte(a.password), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user