| 1 |
package enmime_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/smtp" |
| 5 |
"strings" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/jhillyerd/enmime" |
| 9 |
) |
| 10 |
|
| 11 |
func TestSMTPSend(t *testing.T) { |
| 12 |
from := "[email protected]" |
| 13 |
auth := smtp.PlainAuth("", from, "password", "mail.example.com") |
| 14 |
s := enmime.NewSMTP("0.0.0.0", auth) |
| 15 |
|
| 16 |
// Satisfy requirements of the Send method and use an intentionally malformed From Address to |
| 17 |
// elicit an expected error from smtp.SendMail, which can be type-checked and verified. |
| 18 |
err := s.Send(from+"\rinvalid", []string{"[email protected]"}, []byte("message content")) |
| 19 |
if err == nil { |
| 20 |
t.Fatal("Send() returned nil error, wanted one.") |
| 21 |
} |
| 22 |
if !strings.Contains(err.Error(), "smtp: A line must not contain CR or LF") { |
| 23 |
t.Fatalf("Send() did not return expected error, failed: %s", err.Error()) |
| 24 |
} |
| 25 |
} |