Closed AboutSange closed 2 months ago
It solved: When using SMTP port 465 (TLS port) to send mail, always return error "failed to send email: EOF". And this problem is mentioned in https://github.com/nikoksr/notify/issues/269#issuecomment-1115986601
notify/service/mail/mail_send_test.go
cd notify/service/mail/
go test
package mail import ( "context" "crypto/tls" "log" "testing" "github.com/stretchr/testify/assert" ) func TestMail_SendPort25(t *testing.T) { t.Parallel() m := New("xxx@163.com", "smtp.163.com:25") assert.False(t, m.useTLS) assert.Nil(t, m.tlsConfig) m.AuthenticateSMTP("", "xxx@163.com", "xxx", "smtp.163.com") m.AddReceivers("xxx@qq.com") // send a test message. err := m.Send(context.Background(), "SMTP port 25", "The actual message - Hello, you awesome gophers! :)", ) if err != nil { log.Println(err) } } func TestMail_SendPort465(t *testing.T) { t.Parallel() m := New("xxx@163.com", "smtp.163.com:465") assert.False(t, m.useTLS) assert.Nil(t, m.tlsConfig) m.AuthenticateSMTP("", "xxx@163.com", "xxx", "smtp.163.com") m.AddReceivers("xxx@qq.com") m.SetTLS(&tls.Config{ServerName: "smtp.163.com"}) assert.True(t, m.useTLS) assert.NotNil(t, m.tlsConfig) // send a test message. err := m.Send(context.Background(), "SMTP port 465", "The actual message - Hello, you awesome gophers! :)", ) if err != nil { log.Println(err) } } func TestMail_SendPort587(t *testing.T) { t.Parallel() m := New("xxx@163.com", "smtp.163.com:587") assert.False(t, m.useTLS) assert.Nil(t, m.tlsConfig) m.AuthenticateSMTP("", "xxx@163.com", "xxx", "smtp.163.com") m.AddReceivers("xxx@qq.com") m.SetTLS(&tls.Config{ServerName: "smtp.163.com"}) assert.True(t, m.useTLS) assert.NotNil(t, m.tlsConfig) m.UnSetTLS() assert.False(t, m.useTLS) m.SetTLS(&tls.Config{ServerName: "smtp.163.com"}) assert.True(t, m.useTLS) assert.NotNil(t, m.tlsConfig) // send a test message. err := m.Send(context.Background(), "SMTP port 587", "The actual message - Hello, you awesome gophers! :)", ) if err != nil { log.Println(err) } }
go test result: all PASS
all mail was send success
Description
Motivation and Context
It solved: When using SMTP port 465 (TLS port) to send mail, always return error "failed to send email: EOF". And this problem is mentioned in https://github.com/nikoksr/notify/issues/269#issuecomment-1115986601
How Has This Been Tested?
notify/service/mail/mail_send_test.go
, andcd notify/service/mail/
, and rungo test
, it's all PASSScreenshots / Output (if appropriate):
Types of changes
Checklist: