@mxraven/mail 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,323 @@
1
+ import { ConnectionOptions } from "node:tls";
2
+ //#region src/message.d.ts
3
+ /** A custom message header. */
4
+ interface Header {
5
+ /** The header field name. */
6
+ readonly name: string;
7
+ /** The header field value. It must not contain line breaks. */
8
+ readonly value: string;
9
+ }
10
+ /**
11
+ * A message attachment.
12
+ *
13
+ * The attachment data is retained by reference until the message is built. Callers must not mutate
14
+ * it in the meantime.
15
+ */
16
+ interface Attachment {
17
+ /** The attachment filename. It may be empty. */
18
+ readonly filename?: string;
19
+ /** The media type. Defaults to `application/octet-stream`. */
20
+ readonly contentType?: string;
21
+ /** The raw attachment content. The caller retains ownership. */
22
+ readonly data: Uint8Array;
23
+ /** Marks the attachment for inline display, for example a `cid:` image. */
24
+ readonly inline?: boolean;
25
+ /** The inline content identifier, without angle brackets. */
26
+ readonly contentId?: string;
27
+ }
28
+ /**
29
+ * The SMTP envelope for a raw message, independent of the message headers.
30
+ *
31
+ * @public
32
+ */
33
+ interface Envelope {
34
+ /**
35
+ * The envelope sender. An empty or omitted value requests a null reverse-path, which is
36
+ * appropriate for bounce messages.
37
+ */
38
+ readonly from?: string;
39
+ /** At least one envelope recipient. */
40
+ readonly to: readonly string[];
41
+ }
42
+ /**
43
+ * A mutable, chainable builder for an email message.
44
+ *
45
+ * Chained methods return the receiver, so a message is normally composed in a single expression. A
46
+ * `Message` is not safe for concurrent use. It can be sent repeatedly; each send serializes the
47
+ * current state.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const message = new Message()
52
+ * .from("Acme <noreply@acme.example>")
53
+ * .to("customer@example.com")
54
+ * .subject("Your receipt")
55
+ * .text("Thanks for your order.")
56
+ * .html("<p>Thanks for your order.</p>");
57
+ * ```
58
+ *
59
+ * @public
60
+ */
61
+ export declare class Message {
62
+ private fromAddress;
63
+ private isNullSender;
64
+ private senderAddress;
65
+ private replyToAddress;
66
+ private toAddresses;
67
+ private ccAddresses;
68
+ private bccAddresses;
69
+ private subjectText;
70
+ private textBody;
71
+ private htmlBody;
72
+ private customHeaders;
73
+ private attachments;
74
+ private messageIdValue;
75
+ private inReplyToValue;
76
+ private referencesValue;
77
+ private dateValue;
78
+ /** Sets the envelope sender and the `From` header. */
79
+ from(address: string): this;
80
+ /**
81
+ * Uses a null reverse-path while keeping the `From` header.
82
+ *
83
+ * It is intended for bounce and other auto-generated messages. A `From` header is still required
84
+ * for a valid message.
85
+ */
86
+ nullSender(): this;
87
+ /** Sets the `Sender` header, required when `From` contains more than one mailbox. */
88
+ sender(address: string): this;
89
+ /** Sets the `Reply-To` header. */
90
+ replyTo(address: string): this;
91
+ /** Adds envelope and `To` header recipients. */
92
+ to(addresses: string | readonly string[]): this;
93
+ /** Adds envelope and `Cc` header recipients. */
94
+ cc(addresses: string | readonly string[]): this;
95
+ /** Adds envelope recipients without a visible `Bcc` header. */
96
+ bcc(addresses: string | readonly string[]): this;
97
+ /** Sets the `Subject` header. Non-ASCII subjects are RFC 2047 encoded. */
98
+ subject(subject: string): this;
99
+ /** Sets the `Message-ID` header. The value is wrapped in angle brackets when needed. */
100
+ messageId(id: string): this;
101
+ /** Sets the `In-Reply-To` header for threading. */
102
+ inReplyTo(id: string): this;
103
+ /** Sets the `References` header for threading. */
104
+ references(ids: string | readonly string[]): this;
105
+ /** Sets the `Date` header. When unset, the time of sending is used. */
106
+ date(date: Date): this;
107
+ /**
108
+ * Sets the plain-text body.
109
+ *
110
+ * When both a text and an HTML body are set, the message is sent as `multipart/alternative`.
111
+ */
112
+ text(body: string): this;
113
+ /**
114
+ * Sets the HTML body.
115
+ *
116
+ * When both a text and an HTML body are set, the message is sent as `multipart/alternative`.
117
+ */
118
+ html(body: string): this;
119
+ /** Appends a custom header. */
120
+ header(name: string, value: string): this;
121
+ /**
122
+ * Appends an attachment.
123
+ *
124
+ * The data is retained by reference until the message is built. Callers must not mutate it in the
125
+ * meantime.
126
+ */
127
+ attach(attachment: Attachment): this;
128
+ /** Appends a file attachment with an `application/octet-stream` content type. */
129
+ attachFile(filename: string, data: Uint8Array): this;
130
+ /** Appends an inline attachment referenced by `contentId`, for example from `cid:` HTML. */
131
+ attachInline(filename: string, contentId: string, data: Uint8Array): this;
132
+ /** Renders the body, wrapping attachments in `multipart/mixed` when present. */
133
+ private renderBody;
134
+ /** Parses an optional address, recording a problem when invalid. */
135
+ private parseOptional;
136
+ /** Parses a list of addresses, recording problems for invalid entries. */
137
+ private parseMany;
138
+ }
139
+ //#endregion
140
+ //#region src/result.d.ts
141
+ /**
142
+ * Describes the outcome of a submission that reached the server.
143
+ *
144
+ * @public
145
+ */
146
+ interface Result {
147
+ /**
148
+ * The mxRaven message reference from the server's final `message_ref=<uuid>` reply. It is empty
149
+ * when the server did not report one.
150
+ */
151
+ readonly messageRef: string;
152
+ /** The three-digit SMTP reply code of the final reply. */
153
+ readonly code: number;
154
+ /** The final SMTP reply text. It is intended for humans and is not stable. */
155
+ readonly message: string;
156
+ /**
157
+ * Per-recipient acceptance. It is populated when the server returned individual `RCPT TO`
158
+ * responses.
159
+ */
160
+ readonly recipients: readonly RecipientResult[];
161
+ }
162
+ /**
163
+ * Reports whether a single envelope recipient was accepted.
164
+ *
165
+ * @public
166
+ */
167
+ interface RecipientResult {
168
+ /** The recipient address as submitted. */
169
+ readonly address: string;
170
+ /** Whether the server accepted the recipient. */
171
+ readonly accepted: boolean;
172
+ /** The rejection reason when {@link RecipientResult.accepted} is `false`. */
173
+ readonly error?: Error;
174
+ }
175
+ //#endregion
176
+ //#region src/client.d.ts
177
+ /** The default mxRaven SMTP submission port. */
178
+ export declare const defaultAddressPort = 587;
179
+ /** Options for a {@link Client}. */
180
+ interface ClientOptions {
181
+ /** The submission server host. A port must not be included. */
182
+ readonly host: string;
183
+ /** The submission server port. Defaults to {@link defaultAddressPort}. */
184
+ readonly port?: number;
185
+ /** The submission API key username, for example `mxr_tx_ab12cd34ef56`. */
186
+ readonly username: string;
187
+ /** The submission API key secret. */
188
+ readonly secret: string;
189
+ /** STARTTLS options, for example a custom CA or `servername`. */
190
+ readonly tls?: ConnectionOptions;
191
+ /** The maximum number of pooled connections. Defaults to 5. */
192
+ readonly poolSize?: number;
193
+ /** The TCP connect deadline in milliseconds. Defaults to 30000. */
194
+ readonly connectTimeout?: number;
195
+ /** The per-read deadline in milliseconds. Defaults to 300000. */
196
+ readonly readTimeout?: number;
197
+ /** The per-write deadline in milliseconds. Defaults to 300000. */
198
+ readonly writeTimeout?: number;
199
+ /** The name sent in EHLO. Defaults to `localhost`. */
200
+ readonly localName?: string;
201
+ }
202
+ /** Per-call options for {@link Client.send} and {@link Client.sendRaw}. */
203
+ interface SendOptions {
204
+ /** Cancels the submission. */
205
+ readonly signal?: AbortSignal;
206
+ }
207
+ /**
208
+ * Submits mail to the mxRaven SMTP submission service.
209
+ *
210
+ * A client maintains a bounded pool of authenticated connections and is safe
211
+ * for concurrent use. The submission service requires STARTTLS and SMTP AUTH,
212
+ * so both are always used.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const secret = process.env.MXRAVEN_SECRET;
217
+ * if (secret === undefined || secret === "") {
218
+ * throw new Error("MXRAVEN_SECRET is required");
219
+ * }
220
+ *
221
+ * const client = new Client({
222
+ * host: "smtp.mxraven.com",
223
+ * username: "mxr_tx_ab12cd34ef56",
224
+ * secret,
225
+ * });
226
+ * const result = await client.send(
227
+ * new Message().from("noreply@acme.example").to("customer@example.com").text("Hi"),
228
+ * );
229
+ * await client.close();
230
+ * ```
231
+ *
232
+ * @public
233
+ */
234
+ export declare class Client {
235
+ private readonly pool;
236
+ /**
237
+ * @param options - The server address, credentials, and tuning options.
238
+ * @throws `Error` When required options are missing or invalid.
239
+ */
240
+ constructor(options: ClientOptions);
241
+ /**
242
+ * Sends a composed message.
243
+ *
244
+ * @param message - The message to submit. It may be sent more than once.
245
+ * @param options - An optional cancellation signal.
246
+ * @returns The server's result for the submission.
247
+ * @throws {@link SMTPError} When the server rejects a command.
248
+ * @throws {@link SMTPTransactionError} When every recipient is rejected; the
249
+ * per-recipient detail is on {@link SMTPTransactionError.result}.
250
+ *
251
+ * @public
252
+ */
253
+ send(message: Message, options?: SendOptions): Promise<Result>;
254
+ /**
255
+ * Streams an already serialized RFC 5322 message with an explicit envelope.
256
+ *
257
+ * The message is not parsed, so the caller is responsible for RFC 5322
258
+ * correctness. Prefer this for large or pre-rendered messages.
259
+ *
260
+ * @param envelope - The SMTP envelope, independent of the message headers.
261
+ * @param data - The raw message bytes, or an async stream of chunks.
262
+ * @param options - An optional cancellation signal.
263
+ * @returns The server's result for the submission.
264
+ * @throws {@link SMTPError} When the server rejects a command.
265
+ * @throws {@link SMTPTransactionError} When every recipient is rejected.
266
+ *
267
+ * @public
268
+ */
269
+ sendRaw(envelope: Envelope, data: Uint8Array | AsyncIterable<Uint8Array>, options?: SendOptions): Promise<Result>;
270
+ /** Releases the pooled connections. It is safe to call more than once. */
271
+ close(): Promise<void>;
272
+ private transact;
273
+ private toEnvelope;
274
+ private envelopeFromPublic;
275
+ }
276
+ //#endregion
277
+ //#region src/errors.d.ts
278
+ /**
279
+ * An SMTP reply that rejected a submission.
280
+ *
281
+ * It is thrown when the server refuses a command, for example when the sender
282
+ * domain is not authorized or a recipient is rejected. Inspect {@link SMTPError.code}
283
+ * or {@link SMTPError.enhancedCode} to make a delivery decision; the `message`
284
+ * is intended for humans and is not stable.
285
+ *
286
+ * @public
287
+ */
288
+ export declare class SMTPError extends Error {
289
+ /** The three-digit SMTP reply code. */
290
+ readonly code: number;
291
+ /** The RFC 3463 enhanced status code, when the server supplied one. */
292
+ readonly enhancedCode?: string;
293
+ /** @param options - The reply code, optional enhanced code, and reply text. */
294
+ constructor(options: {
295
+ code: number;
296
+ enhancedCode?: string;
297
+ message: string;
298
+ });
299
+ /** Reports whether the failure is permanent (5xx). Retrying is unlikely to succeed. */
300
+ get permanent(): boolean;
301
+ /** Reports whether the failure is transient (4xx). The message may be retried later. */
302
+ get transient(): boolean;
303
+ }
304
+ /**
305
+ * A submission the server rejected after per-recipient results were collected.
306
+ *
307
+ * It is thrown when every envelope recipient was rejected. The per-recipient
308
+ * detail remains available in {@link SMTPTransactionError.result}.
309
+ *
310
+ * @public
311
+ */
312
+ export declare class SMTPTransactionError extends Error {
313
+ /** The per-recipient results collected before the failure. */
314
+ readonly result: Result;
315
+ /**
316
+ * @param message - A human-readable description.
317
+ * @param result - The partial submission result.
318
+ */
319
+ constructor(message: string, result: Result);
320
+ }
321
+ //#endregion
322
+ export type { Attachment, ClientOptions, Envelope, Header, RecipientResult, Result, SendOptions };
323
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/message.ts","../src/result.ts","../src/client.ts","../src/errors.ts"],"mappings":";;;UA2BiB;;WAEN;;WAEA;;;;;;;;UASM;;WAEN;;WAEA;;WAEA,MAAM;;WAEN;;WAEA;;;;;;;UAQM;;;;;WAKN;;WAEA;;;;;;;;;;;;;;;;;;;;;qBA8CE;UACH;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;EAGR,KAAK;;;;;;;EAWL;;EAMA,OAAO;;EAMP,QAAQ;;EAMR,GAAG;;EAMH,GAAG;;EAMH,IAAI;;EAMJ,QAAQ;;EAMR,UAAU;;EAMV,UAAU;;EAMV,WAAW;;EAMX,KAAK,MAAM;;;;;;EAUX,KAAK;;;;;;EAUL,KAAK;;EAML,OAAO,cAAc;;;;;;;EAWrB,OAAO,YAAY;;EAMnB,WAAW,kBAAkB,MAAM;;EAKnC,aAAa,kBAAkB,mBAAmB,MAAM;;UA6GhD;;UAqDA;;UAiBA;;;;;;;;;UCvaO;;;;;WAKN;;WAGA;;WAGA;;;;;WAMA,qBAAqB;;;;;;;UAQf;;WAEN;;WAGA;;WAGA,QAAQ;;;;;qBC1BN;;UAGI;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgCP;mBACM;;;;;EAML,YAAA,SAAS;;;;;;;;;;;;;EAmDf,KAAK,SAAS,SAAS,UAAS,cAAmB,QAAQ;;;;;;;;;;;;;;;;EA0B3D,QACJ,UAAU,UACV,MAAM,aAAa,cAAc,aACjC,UAAS,cACR,QAAQ;;EASL,SAAS;UAID;UAWN;UASA;;;;;;;;;;;;;;qBCtLG,kBAAkB;;WAEpB;;WAGA;;EAGG,YAAA;IAAW;IAAc;IAAuB;;;MAQxD;;MAKA;;;;;;;;;;qBAaO,6BAA6B;;WAE/B,QAAQ;;;;;EAML,YAAA,iBAAiB,QAAQ"}
@@ -0,0 +1,323 @@
1
+ import { ConnectionOptions } from "node:tls";
2
+ //#region src/message.d.ts
3
+ /** A custom message header. */
4
+ interface Header {
5
+ /** The header field name. */
6
+ readonly name: string;
7
+ /** The header field value. It must not contain line breaks. */
8
+ readonly value: string;
9
+ }
10
+ /**
11
+ * A message attachment.
12
+ *
13
+ * The attachment data is retained by reference until the message is built. Callers must not mutate
14
+ * it in the meantime.
15
+ */
16
+ interface Attachment {
17
+ /** The attachment filename. It may be empty. */
18
+ readonly filename?: string;
19
+ /** The media type. Defaults to `application/octet-stream`. */
20
+ readonly contentType?: string;
21
+ /** The raw attachment content. The caller retains ownership. */
22
+ readonly data: Uint8Array;
23
+ /** Marks the attachment for inline display, for example a `cid:` image. */
24
+ readonly inline?: boolean;
25
+ /** The inline content identifier, without angle brackets. */
26
+ readonly contentId?: string;
27
+ }
28
+ /**
29
+ * The SMTP envelope for a raw message, independent of the message headers.
30
+ *
31
+ * @public
32
+ */
33
+ interface Envelope {
34
+ /**
35
+ * The envelope sender. An empty or omitted value requests a null reverse-path, which is
36
+ * appropriate for bounce messages.
37
+ */
38
+ readonly from?: string;
39
+ /** At least one envelope recipient. */
40
+ readonly to: readonly string[];
41
+ }
42
+ /**
43
+ * A mutable, chainable builder for an email message.
44
+ *
45
+ * Chained methods return the receiver, so a message is normally composed in a single expression. A
46
+ * `Message` is not safe for concurrent use. It can be sent repeatedly; each send serializes the
47
+ * current state.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const message = new Message()
52
+ * .from("Acme <noreply@acme.example>")
53
+ * .to("customer@example.com")
54
+ * .subject("Your receipt")
55
+ * .text("Thanks for your order.")
56
+ * .html("<p>Thanks for your order.</p>");
57
+ * ```
58
+ *
59
+ * @public
60
+ */
61
+ export declare class Message {
62
+ private fromAddress;
63
+ private isNullSender;
64
+ private senderAddress;
65
+ private replyToAddress;
66
+ private toAddresses;
67
+ private ccAddresses;
68
+ private bccAddresses;
69
+ private subjectText;
70
+ private textBody;
71
+ private htmlBody;
72
+ private customHeaders;
73
+ private attachments;
74
+ private messageIdValue;
75
+ private inReplyToValue;
76
+ private referencesValue;
77
+ private dateValue;
78
+ /** Sets the envelope sender and the `From` header. */
79
+ from(address: string): this;
80
+ /**
81
+ * Uses a null reverse-path while keeping the `From` header.
82
+ *
83
+ * It is intended for bounce and other auto-generated messages. A `From` header is still required
84
+ * for a valid message.
85
+ */
86
+ nullSender(): this;
87
+ /** Sets the `Sender` header, required when `From` contains more than one mailbox. */
88
+ sender(address: string): this;
89
+ /** Sets the `Reply-To` header. */
90
+ replyTo(address: string): this;
91
+ /** Adds envelope and `To` header recipients. */
92
+ to(addresses: string | readonly string[]): this;
93
+ /** Adds envelope and `Cc` header recipients. */
94
+ cc(addresses: string | readonly string[]): this;
95
+ /** Adds envelope recipients without a visible `Bcc` header. */
96
+ bcc(addresses: string | readonly string[]): this;
97
+ /** Sets the `Subject` header. Non-ASCII subjects are RFC 2047 encoded. */
98
+ subject(subject: string): this;
99
+ /** Sets the `Message-ID` header. The value is wrapped in angle brackets when needed. */
100
+ messageId(id: string): this;
101
+ /** Sets the `In-Reply-To` header for threading. */
102
+ inReplyTo(id: string): this;
103
+ /** Sets the `References` header for threading. */
104
+ references(ids: string | readonly string[]): this;
105
+ /** Sets the `Date` header. When unset, the time of sending is used. */
106
+ date(date: Date): this;
107
+ /**
108
+ * Sets the plain-text body.
109
+ *
110
+ * When both a text and an HTML body are set, the message is sent as `multipart/alternative`.
111
+ */
112
+ text(body: string): this;
113
+ /**
114
+ * Sets the HTML body.
115
+ *
116
+ * When both a text and an HTML body are set, the message is sent as `multipart/alternative`.
117
+ */
118
+ html(body: string): this;
119
+ /** Appends a custom header. */
120
+ header(name: string, value: string): this;
121
+ /**
122
+ * Appends an attachment.
123
+ *
124
+ * The data is retained by reference until the message is built. Callers must not mutate it in the
125
+ * meantime.
126
+ */
127
+ attach(attachment: Attachment): this;
128
+ /** Appends a file attachment with an `application/octet-stream` content type. */
129
+ attachFile(filename: string, data: Uint8Array): this;
130
+ /** Appends an inline attachment referenced by `contentId`, for example from `cid:` HTML. */
131
+ attachInline(filename: string, contentId: string, data: Uint8Array): this;
132
+ /** Renders the body, wrapping attachments in `multipart/mixed` when present. */
133
+ private renderBody;
134
+ /** Parses an optional address, recording a problem when invalid. */
135
+ private parseOptional;
136
+ /** Parses a list of addresses, recording problems for invalid entries. */
137
+ private parseMany;
138
+ }
139
+ //#endregion
140
+ //#region src/result.d.ts
141
+ /**
142
+ * Describes the outcome of a submission that reached the server.
143
+ *
144
+ * @public
145
+ */
146
+ interface Result {
147
+ /**
148
+ * The mxRaven message reference from the server's final `message_ref=<uuid>` reply. It is empty
149
+ * when the server did not report one.
150
+ */
151
+ readonly messageRef: string;
152
+ /** The three-digit SMTP reply code of the final reply. */
153
+ readonly code: number;
154
+ /** The final SMTP reply text. It is intended for humans and is not stable. */
155
+ readonly message: string;
156
+ /**
157
+ * Per-recipient acceptance. It is populated when the server returned individual `RCPT TO`
158
+ * responses.
159
+ */
160
+ readonly recipients: readonly RecipientResult[];
161
+ }
162
+ /**
163
+ * Reports whether a single envelope recipient was accepted.
164
+ *
165
+ * @public
166
+ */
167
+ interface RecipientResult {
168
+ /** The recipient address as submitted. */
169
+ readonly address: string;
170
+ /** Whether the server accepted the recipient. */
171
+ readonly accepted: boolean;
172
+ /** The rejection reason when {@link RecipientResult.accepted} is `false`. */
173
+ readonly error?: Error;
174
+ }
175
+ //#endregion
176
+ //#region src/client.d.ts
177
+ /** The default mxRaven SMTP submission port. */
178
+ export declare const defaultAddressPort = 587;
179
+ /** Options for a {@link Client}. */
180
+ interface ClientOptions {
181
+ /** The submission server host. A port must not be included. */
182
+ readonly host: string;
183
+ /** The submission server port. Defaults to {@link defaultAddressPort}. */
184
+ readonly port?: number;
185
+ /** The submission API key username, for example `mxr_tx_ab12cd34ef56`. */
186
+ readonly username: string;
187
+ /** The submission API key secret. */
188
+ readonly secret: string;
189
+ /** STARTTLS options, for example a custom CA or `servername`. */
190
+ readonly tls?: ConnectionOptions;
191
+ /** The maximum number of pooled connections. Defaults to 5. */
192
+ readonly poolSize?: number;
193
+ /** The TCP connect deadline in milliseconds. Defaults to 30000. */
194
+ readonly connectTimeout?: number;
195
+ /** The per-read deadline in milliseconds. Defaults to 300000. */
196
+ readonly readTimeout?: number;
197
+ /** The per-write deadline in milliseconds. Defaults to 300000. */
198
+ readonly writeTimeout?: number;
199
+ /** The name sent in EHLO. Defaults to `localhost`. */
200
+ readonly localName?: string;
201
+ }
202
+ /** Per-call options for {@link Client.send} and {@link Client.sendRaw}. */
203
+ interface SendOptions {
204
+ /** Cancels the submission. */
205
+ readonly signal?: AbortSignal;
206
+ }
207
+ /**
208
+ * Submits mail to the mxRaven SMTP submission service.
209
+ *
210
+ * A client maintains a bounded pool of authenticated connections and is safe
211
+ * for concurrent use. The submission service requires STARTTLS and SMTP AUTH,
212
+ * so both are always used.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const secret = process.env.MXRAVEN_SECRET;
217
+ * if (secret === undefined || secret === "") {
218
+ * throw new Error("MXRAVEN_SECRET is required");
219
+ * }
220
+ *
221
+ * const client = new Client({
222
+ * host: "smtp.mxraven.com",
223
+ * username: "mxr_tx_ab12cd34ef56",
224
+ * secret,
225
+ * });
226
+ * const result = await client.send(
227
+ * new Message().from("noreply@acme.example").to("customer@example.com").text("Hi"),
228
+ * );
229
+ * await client.close();
230
+ * ```
231
+ *
232
+ * @public
233
+ */
234
+ export declare class Client {
235
+ private readonly pool;
236
+ /**
237
+ * @param options - The server address, credentials, and tuning options.
238
+ * @throws `Error` When required options are missing or invalid.
239
+ */
240
+ constructor(options: ClientOptions);
241
+ /**
242
+ * Sends a composed message.
243
+ *
244
+ * @param message - The message to submit. It may be sent more than once.
245
+ * @param options - An optional cancellation signal.
246
+ * @returns The server's result for the submission.
247
+ * @throws {@link SMTPError} When the server rejects a command.
248
+ * @throws {@link SMTPTransactionError} When every recipient is rejected; the
249
+ * per-recipient detail is on {@link SMTPTransactionError.result}.
250
+ *
251
+ * @public
252
+ */
253
+ send(message: Message, options?: SendOptions): Promise<Result>;
254
+ /**
255
+ * Streams an already serialized RFC 5322 message with an explicit envelope.
256
+ *
257
+ * The message is not parsed, so the caller is responsible for RFC 5322
258
+ * correctness. Prefer this for large or pre-rendered messages.
259
+ *
260
+ * @param envelope - The SMTP envelope, independent of the message headers.
261
+ * @param data - The raw message bytes, or an async stream of chunks.
262
+ * @param options - An optional cancellation signal.
263
+ * @returns The server's result for the submission.
264
+ * @throws {@link SMTPError} When the server rejects a command.
265
+ * @throws {@link SMTPTransactionError} When every recipient is rejected.
266
+ *
267
+ * @public
268
+ */
269
+ sendRaw(envelope: Envelope, data: Uint8Array | AsyncIterable<Uint8Array>, options?: SendOptions): Promise<Result>;
270
+ /** Releases the pooled connections. It is safe to call more than once. */
271
+ close(): Promise<void>;
272
+ private transact;
273
+ private toEnvelope;
274
+ private envelopeFromPublic;
275
+ }
276
+ //#endregion
277
+ //#region src/errors.d.ts
278
+ /**
279
+ * An SMTP reply that rejected a submission.
280
+ *
281
+ * It is thrown when the server refuses a command, for example when the sender
282
+ * domain is not authorized or a recipient is rejected. Inspect {@link SMTPError.code}
283
+ * or {@link SMTPError.enhancedCode} to make a delivery decision; the `message`
284
+ * is intended for humans and is not stable.
285
+ *
286
+ * @public
287
+ */
288
+ export declare class SMTPError extends Error {
289
+ /** The three-digit SMTP reply code. */
290
+ readonly code: number;
291
+ /** The RFC 3463 enhanced status code, when the server supplied one. */
292
+ readonly enhancedCode?: string;
293
+ /** @param options - The reply code, optional enhanced code, and reply text. */
294
+ constructor(options: {
295
+ code: number;
296
+ enhancedCode?: string;
297
+ message: string;
298
+ });
299
+ /** Reports whether the failure is permanent (5xx). Retrying is unlikely to succeed. */
300
+ get permanent(): boolean;
301
+ /** Reports whether the failure is transient (4xx). The message may be retried later. */
302
+ get transient(): boolean;
303
+ }
304
+ /**
305
+ * A submission the server rejected after per-recipient results were collected.
306
+ *
307
+ * It is thrown when every envelope recipient was rejected. The per-recipient
308
+ * detail remains available in {@link SMTPTransactionError.result}.
309
+ *
310
+ * @public
311
+ */
312
+ export declare class SMTPTransactionError extends Error {
313
+ /** The per-recipient results collected before the failure. */
314
+ readonly result: Result;
315
+ /**
316
+ * @param message - A human-readable description.
317
+ * @param result - The partial submission result.
318
+ */
319
+ constructor(message: string, result: Result);
320
+ }
321
+ //#endregion
322
+ export type { Attachment, ClientOptions, Envelope, Header, RecipientResult, Result, SendOptions };
323
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/message.ts","../src/result.ts","../src/client.ts","../src/errors.ts"],"mappings":";;;UA2BiB;;WAEN;;WAEA;;;;;;;;UASM;;WAEN;;WAEA;;WAEA,MAAM;;WAEN;;WAEA;;;;;;;UAQM;;;;;WAKN;;WAEA;;;;;;;;;;;;;;;;;;;;;qBA8CE;UACH;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;EAGR,KAAK;;;;;;;EAWL;;EAMA,OAAO;;EAMP,QAAQ;;EAMR,GAAG;;EAMH,GAAG;;EAMH,IAAI;;EAMJ,QAAQ;;EAMR,UAAU;;EAMV,UAAU;;EAMV,WAAW;;EAMX,KAAK,MAAM;;;;;;EAUX,KAAK;;;;;;EAUL,KAAK;;EAML,OAAO,cAAc;;;;;;;EAWrB,OAAO,YAAY;;EAMnB,WAAW,kBAAkB,MAAM;;EAKnC,aAAa,kBAAkB,mBAAmB,MAAM;;UA6GhD;;UAqDA;;UAiBA;;;;;;;;;UCvaO;;;;;WAKN;;WAGA;;WAGA;;;;;WAMA,qBAAqB;;;;;;;UAQf;;WAEN;;WAGA;;WAGA,QAAQ;;;;;qBC1BN;;UAGI;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgCP;mBACM;;;;;EAML,YAAA,SAAS;;;;;;;;;;;;;EAmDf,KAAK,SAAS,SAAS,UAAS,cAAmB,QAAQ;;;;;;;;;;;;;;;;EA0B3D,QACJ,UAAU,UACV,MAAM,aAAa,cAAc,aACjC,UAAS,cACR,QAAQ;;EASL,SAAS;UAID;UAWN;UASA;;;;;;;;;;;;;;qBCtLG,kBAAkB;;WAEpB;;WAGA;;EAGG,YAAA;IAAW;IAAc;IAAuB;;;MAQxD;;MAKA;;;;;;;;;;qBAaO,6BAA6B;;WAE/B,QAAQ;;;;;EAML,YAAA,iBAAiB,QAAQ"}