smtp.go raw
1 // Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321.
2 //
3 // It also implements the following extensions:
4 //
5 // - 8BITMIME (RFC 1652)
6 // - ENHANCEDSTATUSCODES (RFC 2034)
7 // - AUTH (RFC 2554)
8 // - DELIVERBY (RFC 2852)
9 // - CHUNKING (RFC 3030)
10 // - BINARYMIME (RFC 3030)
11 // - STARTTLS (RFC 3207)
12 // - DSN (RFC 3461, RFC 6533)
13 // - SMTPUTF8 (RFC 6531)
14 // - MT-PRIORITY (RFC 6710)
15 // - RRVS (RFC 7293)
16 // - REQUIRETLS (RFC 8689)
17 //
18 // LMTP (RFC 2033) is also supported.
19 //
20 // Additional extensions may be handled by other packages.
21 package smtp
22
23 import (
24 "time"
25 )
26
27 type BodyType string
28
29 const (
30 Body7Bit BodyType = "7BIT"
31 Body8BitMIME BodyType = "8BITMIME"
32 BodyBinaryMIME BodyType = "BINARYMIME"
33 )
34
35 type DSNReturn string
36
37 const (
38 DSNReturnFull DSNReturn = "FULL"
39 DSNReturnHeaders DSNReturn = "HDRS"
40 )
41
42 // MailOptions contains parameters for the MAIL command.
43 type MailOptions struct {
44 // Value of BODY= argument, 7BIT, 8BITMIME or BINARYMIME.
45 Body BodyType
46
47 // Size of the body. Can be 0 if not specified by client.
48 Size int64
49
50 // TLS is required for the message transmission.
51 //
52 // The message should be rejected if it can't be transmitted
53 // with TLS.
54 RequireTLS bool
55
56 // The message envelope or message header contains UTF-8-encoded strings.
57 // This flag is set by SMTPUTF8-aware (RFC 6531) client.
58 UTF8 bool
59
60 // Value of RET= argument, FULL or HDRS.
61 Return DSNReturn
62
63 // Envelope identifier set by the client.
64 EnvelopeID string
65
66 // The authorization identity asserted by the message sender in decoded
67 // form with angle brackets stripped.
68 //
69 // nil value indicates missing AUTH, non-nil empty string indicates
70 // AUTH=<>.
71 //
72 // Defined in RFC 4954.
73 Auth *string
74 }
75
76 type DSNNotify string
77
78 const (
79 DSNNotifyNever DSNNotify = "NEVER"
80 DSNNotifyDelayed DSNNotify = "DELAY"
81 DSNNotifyFailure DSNNotify = "FAILURE"
82 DSNNotifySuccess DSNNotify = "SUCCESS"
83 )
84
85 type DSNAddressType string
86
87 const (
88 DSNAddressTypeRFC822 DSNAddressType = "RFC822"
89 DSNAddressTypeUTF8 DSNAddressType = "UTF-8"
90 )
91
92 type DeliverByMode string
93
94 const (
95 DeliverByNotify DeliverByMode = "N"
96 DeliverByReturn DeliverByMode = "R"
97 )
98
99 type DeliverByOptions struct {
100 Time time.Duration
101 Mode DeliverByMode
102 Trace bool
103 }
104
105 type PriorityProfile string
106
107 const (
108 PriorityUnspecified PriorityProfile = ""
109 PriorityMIXER PriorityProfile = "MIXER"
110 PrioritySTANAG4406 PriorityProfile = "STANAG4406"
111 PriorityNSEP PriorityProfile = "NSEP"
112 )
113
114 // RcptOptions contains parameters for the RCPT command.
115 type RcptOptions struct {
116 // Value of NOTIFY= argument, NEVER or a combination of either of
117 // DELAY, FAILURE, SUCCESS.
118 Notify []DSNNotify
119
120 // Original recipient set by client.
121 OriginalRecipientType DSNAddressType
122 OriginalRecipient string
123
124 // Time value of the RRVS= argument
125 // or the zero time if unset.
126 RequireRecipientValidSince time.Time
127
128 // Value of BY= argument or nil if unset.
129 DeliverBy *DeliverByOptions
130
131 // Value of MT-PRIORITY= or nil if unset.
132 MTPriority *int
133 }
134