mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-14 01:42:54 +01:00
Update README.md and removed example code in favor for doc_test.go example
This commit is contained in:
parent
06e37755f2
commit
2bd7cf0cb3
2 changed files with 36 additions and 29 deletions
32
README.md
32
README.md
|
@ -15,7 +15,7 @@ mail and SMTP related tasks.
|
||||||
## Features
|
## Features
|
||||||
Some of the features of this library:
|
Some of the features of this library:
|
||||||
* [X] Only Standard Library dependant
|
* [X] Only Standard Library dependant
|
||||||
* [X] Modern, idiotmatic Go
|
* [X] Modern, idiomatic Go
|
||||||
* [X] Sane and secure defaults
|
* [X] Sane and secure defaults
|
||||||
* [X] SSL/TLS support
|
* [X] SSL/TLS support
|
||||||
* [X] StartTLS support with different policies
|
* [X] StartTLS support with different policies
|
||||||
|
@ -28,31 +28,5 @@ Some of the features of this library:
|
||||||
* [ ] Support for attachments
|
* [ ] Support for attachments
|
||||||
* [ ] Go template support
|
* [ ] Go template support
|
||||||
|
|
||||||
## Example
|
## Examples
|
||||||
```go
|
The [package](https://pkg.go.dev/github.com/wneessen/go-mail) is shipped with example code.
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
33
doc_test.go
Normal file
33
doc_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue