forked from wneessen/go-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_test.go
63 lines (56 loc) · 1.4 KB
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package mail_test
import (
"fmt"
"github.com/wneessen/go-mail"
"os"
)
// Code example for the NewClient method
func ExampleNewClient() {
c, err := mail.NewClient("mail.example.com")
if err != nil {
panic(err)
}
_ = c
// Output:
}
// Code example for the Client.SetTLSPolicy method
func ExampleClient_SetTLSPolicy() {
c, err := mail.NewClient("mail.example.com")
if err != nil {
panic(err)
}
c.SetTLSPolicy(mail.TLSMandatory)
fmt.Println(c.TLSPolicy())
// Output: TLSMandatory
}
// Code example for the NewMsg method
func ExampleNewMsg() {
m := mail.NewMsg(mail.WithEncoding(mail.EncodingQP), mail.WithCharset(mail.CharsetASCII))
fmt.Printf("%s // %s\n", m.Encoding(), m.Charset())
// Output: quoted-printable // US-ASCII
}
// Code example for the Client.DialAndSend method
func ExampleClient_DialAndSend() {
from := "Toni Tester <[email protected]>"
to := "Alice <[email protected]>"
server := "mail.example.com"
m := mail.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 := mail.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)
}
}