笔者在搭建docker版leanote过程中,发现邮件服务器异常,按照下述修改以后,即可解决该问题
//leanote/app/service/EmailService.go原有代码
+111 auth := smtp.PlainAuth("", username, password, hp[0])
//应根据阿里云示例中描述,采用go发送smtp发送邮件的时候需要增加代码段
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
return "LOGIN", []byte(a.username), 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
}
}
return nil, nil
}