Documentation
¶
Overview ¶
Package postal is a mock SMTP mailer
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MailRecord ¶
MailRecord represents a single record of the SMTP transaction sent
type Postal ¶
type Postal struct {
// contains filtered or unexported fields
}
Postal represents a mocked SMTP mailer
Example ¶
package main import ( "net/smtp" "testing" "github.com/gomicro/postal" ) func main() { // This would normally be provided by the testing function var t *testing.T host := "mailhost.com:25" auth := smtp.PlainAuth("", "username", "password", "mailhost.com") from := "dev@gomicro.io" to := []string{"foo@bar.com"} body := []byte("hello world") p := postal.New() SendMail := p.Mailer() err := SendMail(host, auth, from, to, body) if err != nil { t.Error(err.Error()) } if p.Mailed() != 1 { t.Errorf("expected 1 mailed, got %v mailed", p.Mailed()) } records := p.MailRecords() if len(records) != 1 { t.Errorf("expected 1 record, got %v record", len(records)) } r := records[0] if r.Host != host { t.Errorf("expected %v, got %v", host, r.Host) } if r.From != from { t.Errorf("expected %v, got %v", from, r.From) } if string(r.Body) != string(body) { t.Errorf("expected %v, got %v", string(body), string(r.Body)) } }
Output:
Example (Error) ¶
package main import ( "fmt" "net/smtp" "testing" "github.com/gomicro/postal" ) func main() { // This would normally be provided by the testing function var t *testing.T auth := smtp.PlainAuth("", "username", "password", "mailhost.com") p := postal.New() p.SetError(fmt.Errorf("something's not quite right here")) SendMail := p.Mailer() err := SendMail("mailhost.com:25", auth, "dev@gomicro.io", []string{"foo@bar.com"}, []byte("Hello world")) if err == nil { t.Errorf("Expected error, and got nil") } }
Output:
func (*Postal) MailRecords ¶
func (p *Postal) MailRecords() []MailRecord
MailRecords returns the collection of mail records Postal has captured
Click to show internal directories.
Click to hide internal directories.