mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add tests for DSN, 8BITMIME, and SMTPUTF8 support in SMTP
Introduce new test cases to verify the SMTP server's ability to handle DSN, 8BITMIME, and SMTPUTF8 features. These tests ensure correct response behavior when these features are supported by the server.
This commit is contained in:
parent
0df228178a
commit
0d8d097ae1
1 changed files with 66 additions and 0 deletions
|
@ -2266,6 +2266,72 @@ func TestClient_Mail(t *testing.T) {
|
|||
t.Errorf("expected mail from command to be %q, but sent %q", expected, sent)
|
||||
}
|
||||
})
|
||||
t.Run("from address and server supports DSN", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
PortAdder.Add(1)
|
||||
serverPort := int(TestServerPortBase + PortAdder.Load())
|
||||
featureSet := "250-DSN\r\n250 STARTTLS"
|
||||
go func() {
|
||||
if err := simpleSMTPServer(ctx, t, &serverProps{
|
||||
EchoCommandAsError: "MAIL FROM:",
|
||||
FeatureSet: featureSet,
|
||||
ListenPort: serverPort,
|
||||
},
|
||||
); err != nil {
|
||||
t.Errorf("failed to start test server: %s", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Millisecond * 30)
|
||||
|
||||
client, err := Dial(fmt.Sprintf("%s:%d", TestServerAddr, serverPort))
|
||||
if err != nil {
|
||||
t.Errorf("failed to dial to test server: %s", err)
|
||||
}
|
||||
client.dsnmrtype = "FULL"
|
||||
if err = client.Mail("valid-from@domain.tld"); err == nil {
|
||||
t.Error("server should echo the command as error but didn't")
|
||||
}
|
||||
sent := strings.Replace(err.Error(), "500 ", "", -1)
|
||||
expected := "MAIL FROM:<valid-from@domain.tld> RET=FULL"
|
||||
if !strings.EqualFold(sent, expected) {
|
||||
t.Errorf("expected mail from command to be %q, but sent %q", expected, sent)
|
||||
}
|
||||
})
|
||||
t.Run("from address and server supports DSN, SMTPUTF8 and 8BITMIME", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
PortAdder.Add(1)
|
||||
serverPort := int(TestServerPortBase + PortAdder.Load())
|
||||
featureSet := "250-DSN\r\n250-8BITMIME\r\n250-SMTPUTF8\r\n250 STARTTLS"
|
||||
go func() {
|
||||
if err := simpleSMTPServer(ctx, t, &serverProps{
|
||||
EchoCommandAsError: "MAIL FROM:",
|
||||
FeatureSet: featureSet,
|
||||
ListenPort: serverPort,
|
||||
},
|
||||
); err != nil {
|
||||
t.Errorf("failed to start test server: %s", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Millisecond * 30)
|
||||
|
||||
client, err := Dial(fmt.Sprintf("%s:%d", TestServerAddr, serverPort))
|
||||
if err != nil {
|
||||
t.Errorf("failed to dial to test server: %s", err)
|
||||
}
|
||||
client.dsnmrtype = "FULL"
|
||||
if err = client.Mail("valid-from@domain.tld"); err == nil {
|
||||
t.Error("server should echo the command as error but didn't")
|
||||
}
|
||||
sent := strings.Replace(err.Error(), "500 ", "", -1)
|
||||
expected := "MAIL FROM:<valid-from@domain.tld> BODY=8BITMIME SMTPUTF8 RET=FULL"
|
||||
if !strings.EqualFold(sent, expected) {
|
||||
t.Errorf("expected mail from command to be %q, but sent %q", expected, sent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue