使用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库不支持STARTTLS或者没有开启。
错误:504 5.7.4 Unrecognized authentication type [TYCPR01CA0120.jpnprd01.prod.outlook.com 2023-05-19T20:16:50.695Z 08DB578F0E3AFDFD]
6pp0gazn1#
是的,之前有人汇报过类似的问题。之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。
bxjv4tth2#
Outlook的加密方式比较特殊,不是TLS。
mrzz3bfm3#
之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。
ubby3x7f4#
同样的问题,不支持:服务器:smtp.office365.com端口:587加密:STARTTLS该加密方式。
a6b3iqyw5#
我们可以找到支持http或其他邮件发送提供商的地方,可以考虑自己定制修改。
aiazj4mn6#
是的,之前有人汇报过类似的问题。之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。@songquanpeng https://stackoverflow.com/questions/58804817/setting-up-standard-go-net-smtp-with-office-365-fails-with-error-tls-first-rec
sirbozc57#
普通25端口也会到STARTTLS,common/email.go 我们这边修改成这样目前可用:package commonimport ("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), nilcase "Password:":return []byte(a.password), nildefault:return nil, errors.New("Unknown fromServer")}}return nil, nil}func SendEmail(subject string, receiver string, content string) error {if SMTPFrom == "" { // for compatibilitySMTPFrom = 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 errorif 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}
1tuwyuhd8#
同样问题,期待尽快支持
v7pvogib9#
之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。Outlook 支持每日上千封邮件发送,现在每日收发邮件已经突破上千封。国内其他免费邮箱都无法满足。请问是否有计划支持 Outlook 的 SMTP?
9条答案
按热度按时间6pp0gazn1#
是的,之前有人汇报过类似的问题。之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。
bxjv4tth2#
Outlook的加密方式比较特殊,不是TLS。
mrzz3bfm3#
之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。
ubby3x7f4#
同样的问题,不支持:
服务器:smtp.office365.com
端口:587
加密:STARTTLS
该加密方式。
a6b3iqyw5#
我们可以找到支持http或其他邮件发送提供商的地方,可以考虑自己定制修改。
aiazj4mn6#
是的,之前有人汇报过类似的问题。之后会考虑更换邮件库,当前的邮件库是我基于标准库的 smtp 库简单封装的。@songquanpeng https://stackoverflow.com/questions/58804817/setting-up-standard-go-net-smtp-with-office-365-fails-with-error-tls-first-rec
sirbozc57#
普通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
}
1tuwyuhd8#
同样问题,期待尽快支持
v7pvogib9#
之后打算换用别人写好的包,就不直接用标准库里的 smtp 包了,坑还是蛮多的。
Outlook 支持每日上千封邮件发送,现在每日收发邮件已经突破上千封。国内其他免费邮箱都无法满足。
请问是否有计划支持 Outlook 的 SMTP?