mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-08 23:12:54 +01:00
33 lines
663 B
Go
33 lines
663 B
Go
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)
|
|
}
|
|
}
|