Update README.md and removed example code in favor for doc_test.go example

This commit is contained in:
Winni Neessen 2022-03-12 15:19:32 +01:00
parent 06e37755f2
commit 2bd7cf0cb3
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 36 additions and 29 deletions

View file

@ -15,7 +15,7 @@ mail and SMTP related tasks.
## Features
Some of the features of this library:
* [X] Only Standard Library dependant
* [X] Modern, idiotmatic Go
* [X] Modern, idiomatic Go
* [X] Sane and secure defaults
* [X] SSL/TLS support
* [X] StartTLS support with different policies
@ -28,31 +28,5 @@ Some of the features of this library:
* [ ] Support for attachments
* [ ] Go template support
## Example
```go
package main
import (
"context"
"fmt"
"github.com/wneessen/go-mail"
"os"
"time"
)
func main() {
c, err := mail.NewClient("mail.example.com", mail.WithTimeout(time.Millisecond*500),
mail.WithTLSPolicy(mail.TLSMandatory), mail.WithSMTPAuth(mail.SMTPAuthDigestMD5),
mail.WithUsername("tester@example.com"), mail.WithPassword("secureP4ssW0rd!"))
if err != nil {
fmt.Printf("failed to create new client: %s\n", err)
os.Exit(1)
}
defer c.Close()
if err := c.DialAndSend(); err != nil {
fmt.Printf("failed to dial: %s\n", err)
os.Exit(1)
}
}
```
## Examples
The [package](https://pkg.go.dev/github.com/wneessen/go-mail) is shipped with example code.

33
doc_test.go Normal file
View file

@ -0,0 +1,33 @@
package mail
import (
"fmt"
"os"
)
func ExampleClient_DialAndSend() {
from := "Toni Tester <toni@example.com>"
to := "Alice <alice@example.com>"
server := "mail.example.com"
m := NewMsg()
if err := m.From(from); err != nil {
fmt.Printf("failed to set FROM address: %s", err)
os.Exit(1)
}
if err := m.To(to); err != nil {
fmt.Printf("failed to set TO address: %s", err)
os.Exit(1)
}
m.Subject("This is a great subject")
c, err := NewClient(server)
if err != nil {
fmt.Printf("failed to create mail client: %s", err)
os.Exit(1)
}
if err := c.DialAndSend(m); err != nil {
fmt.Printf("failed to send mail: %s", err)
os.Exit(1)
}
}