@@ -60,8 +60,14 @@ func send(to []string, subject string, body string) error {
6060host := global .GlobalConfig .Host
6161port := global .GlobalConfig .Port
6262isSSL := global .GlobalConfig .IsSSL
63+ isLoginAuth := global .GlobalConfig .IsLoginAuth
6364
64- auth := smtp .PlainAuth ("" , from , secret , host )
65+ var auth smtp.Auth
66+ if isLoginAuth {
67+ auth = LoginAuth (from , secret )
68+ } else {
69+ auth = smtp .PlainAuth ("" , from , secret , host )
70+ }
6571e := email .NewEmail ()
6672if nickname != "" {
6773e .From = fmt .Sprintf ("%s <%s>" , nickname , from )
@@ -80,3 +86,37 @@ func send(to []string, subject string, body string) error {
8086}
8187return err
8288}
89+
90+ // LoginAuth 用于IBM、微软邮箱服务器的LOGIN认证方式
91+ type loginAuth struct {
92+ username , password string
93+ }
94+
95+ func LoginAuth (username , password string ) smtp.Auth {
96+ return & loginAuth {username , password }
97+ }
98+
99+ func (a * loginAuth ) Start (server * smtp.ServerInfo ) (string , []byte , error ) {
100+ return "LOGIN" , []byte {}, nil
101+ }
102+
103+ func (a * loginAuth ) Next (fromServer []byte , more bool ) ([]byte , error ) {
104+ if more {
105+ switch string (fromServer ) {
106+ case "Username:" :
107+ return []byte (a .username ), nil
108+ case "Password:" :
109+ return []byte (a .password ), nil
110+ default :
111+ // 邮箱服务器可能发送的其他提示信息
112+ prompt := strings .ToLower (string (fromServer ))
113+ if strings .Contains (prompt , "username" ) || strings .Contains (prompt , "user" ) {
114+ return []byte (a .username ), nil
115+ }
116+ if strings .Contains (prompt , "password" ) || strings .Contains (prompt , "pass" ) {
117+ return []byte (a .password ), nil
118+ }
119+ }
120+ }
121+ return nil , nil
122+ }
0 commit comments