songquanpeng / one-api

OpenAI 接口管理 & 分发系统,支持 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用. OpenAI key management & redistribution system, using a single API for all LLMs, and features an English UI.
https://openai.justsong.cn/
MIT License
19.65k stars 4.34k forks source link

SMTP 邮件服务不支持 Outlook:504 5.7.4 Unrecognized authentication type #108

Open qyhfrank opened 1 year ago

qyhfrank commented 1 year ago

使用Outlook邮箱发信(smtp-mail.outlook.com),得到错误错误:504 5.7.4 Unrecognized authentication type [TYCPR01CA0120.jpnprd01.prod.outlook.com 2023-05-19T20:16:50.695Z 08DB578F0E3AFDFD]

我已经在Python上验证了邮箱发信本身没有问题,怀疑是发信的go library不支持STARTTLS,或者没有开启。

songquanpeng commented 1 year ago

是的,之前有人汇报过类似的问题。

之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。

quzard commented 1 year ago

outlook的加密方式比较特殊,不是tls

songquanpeng commented 1 year ago

之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。

thinker007 commented 1 year ago

同样问题,不支持: 服务器:smtp.office365.com

端口:587

加密:STARTTLS

该加密方式。

thinker007 commented 1 year ago

我们可以找到支持http或者其他邮件发送提供商 这个地方可以考虑自己定制修改。

thinker007 commented 1 year ago

是的,之前有人汇报过类似的问题。

之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。

@songquanpeng https://stackoverflow.com/questions/58804817/setting-up-standard-go-net-smtp-with-office-365-fails-with-error-tls-first-rec

sunweixn commented 1 year ago

普通25端口也会到STARTTLS,common/email.go 我们这边修改成这样目前可用: package common

import ( "crypto/tls" "encoding/base64" "fmt" "net/smtp" "strings" "errors" ) 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: return nil, errors.New("Unknown fromServer") } } return nil, nil }

func SendEmail(subject string, receiver string, content string) error { if SMTPFrom == "" { // for compatibility SMTPFrom = SMTPAccount } encodedSubject := fmt.Sprintf("=?UTF-8?B?%s?=", base64.StdEncoding.EncodeToString([]byte(subject))) mail := []byte(fmt.Sprintf("To: %s\r\n"+ "From: %s<%s>\r\n"+ "Subject: %s\r\n"+ "Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n", receiver, SystemName, SMTPFrom, encodedSubject, content)) //auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer) auth := LoginAuth(SMTPAccount, SMTPToken) addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort) to := strings.Split(receiver, ";") var err error if SMTPPort == 465 { tlsConfig := &tls.Config{ InsecureSkipVerify: true, ServerName: SMTPServer, } conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", SMTPServer, SMTPPort), tlsConfig) if err != nil { return err } client, err := smtp.NewClient(conn, SMTPServer) if err != nil { return err } defer client.Close() if err = client.Auth(auth); err != nil { return err } if err = client.Mail(SMTPFrom); err != nil { return err } receiverEmails := strings.Split(receiver, ";") for , receiver := range receiverEmails { if err = client.Rcpt(receiver); err != nil { return err } } w, err := client.Data() if err != nil { return err } , err = w.Write(mail) if err != nil { return err } err = w.Close() if err != nil { return err } } else { conn, err := smtp.Dial(addr) if err != nil { return err } defer conn.Close() if ok, := conn.Extension("STARTTLS"); ok { tlsConfig := &tls.Config{ServerName: SMTPServer, InsecureSkipVerify: true} if err = conn.StartTLS(tlsConfig); err != nil { return err } } if err = conn.Auth(auth); err != nil { return err } if err = conn.Mail(SMTPFrom); err != nil { return err } for , receiver := range to { if err = conn.Rcpt(receiver); err != nil { return err } } w, err := conn.Data() if err != nil { return err } _, err = w.Write(mail) if err != nil { return err } err = w.Close() if err != nil { return err } //err = smtp.SendMail(addr, auth, SMTPAccount, to, mail) } return err }

ykangw commented 7 months ago

同样问题,期待尽快支持

popdo commented 4 months ago

之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。

outlook支持每日上千封邮件发送,现在每日收发邮件已经突破上千封。国内其它免费邮箱都无法满足。

请问是否有计划支持outlook的smtp

006lp commented 3 weeks ago

现在哪些smtp服务器可用啊