@visulima/email 1.0.0-alpha.1 → 1.0.0-alpha.3
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.
- package/CHANGELOG.md +55 -0
- package/README.md +408 -72
- package/dist/crypto/index.js +1 -1
- package/dist/draft-mail-message.d.ts +13 -0
- package/dist/index.d.ts +3 -16
- package/dist/index.js +1 -1
- package/dist/mail-message.d.ts +425 -0
- package/dist/mail.d.ts +124 -275
- package/dist/packem_shared/{DkimSigner-Z8D4Il10.js → DkimSigner-BrJfmMey.js} +1 -1
- package/dist/packem_shared/Mail-CC7Oh--8.js +1 -0
- package/dist/packem_shared/MailMessage-n7kyh9vB.js +1 -0
- package/dist/packem_shared/{SmimeEncrypter-CBevU534.js → SmimeEncrypter-CtvWNS8B.js} +1 -1
- package/dist/packem_shared/{SmimeSigner-02aXVi90.js → SmimeSigner-DZ1hSOM3.js} +1 -1
- package/dist/packem_shared/ahaSendProvider-DlFKEQ6D.js +1 -0
- package/dist/packem_shared/{awsSesProvider-CkuFOzb0.js → awsSesProvider-Ba-eVJxZ.js} +6 -6
- package/dist/packem_shared/azureProvider-CQYAkgVF.js +1 -0
- package/dist/packem_shared/brevoProvider-5p6jjiK9.js +1 -0
- package/dist/packem_shared/build-mime-message-IYaUqqPJ.js +2 -0
- package/dist/packem_shared/create-logger-BiWdqFNg.js +1 -0
- package/dist/packem_shared/{detectMimeType-S8WRsNtY.js → detectMimeType-CrDG3LaZ.js} +1 -1
- package/dist/packem_shared/failoverProvider-CAHQQueo.js +1 -0
- package/dist/packem_shared/{generateBoundary-CZ8kJuY6.js → generate-boundary-Cx8nXYS0.js} +1 -1
- package/dist/packem_shared/{generateMessageId-11Ls5JsR.js → generate-message-id-D4uA8gkj.js} +1 -1
- package/dist/packem_shared/headers-to-record-Qo124ImV.js +1 -0
- package/dist/packem_shared/httpProvider-CZD6LZX3.js +1 -0
- package/dist/packem_shared/infobipProvider-CtLwrUaP.js +1 -0
- package/dist/packem_shared/{mailCrabProvider-BEwRjB3F.js → mailCrabProvider-CM_CFDca.js} +1 -1
- package/dist/packem_shared/mailPaceProvider-B6yKvh6z.js +1 -0
- package/dist/packem_shared/mailerSendProvider-CeeIXFnW.js +1 -0
- package/dist/packem_shared/mailgunProvider-mmjKzouh.js +1 -0
- package/dist/packem_shared/mailjetProvider-DwN6i0VA.js +1 -0
- package/dist/packem_shared/mailomatProvider-DMQmjKHT.js +1 -0
- package/dist/packem_shared/mailtrapProvider-BN3UBEQw.js +1 -0
- package/dist/packem_shared/{makeRequest-DwxHX0xo.js → make-request-BDzF9W9D.js} +1 -1
- package/dist/packem_shared/mandrillProvider-370y7CLu.js +1 -0
- package/dist/packem_shared/mockProvider-DN5ZwutD.js +1 -0
- package/dist/packem_shared/nodemailerProvider-_w8QXMU-.js +1 -0
- package/dist/packem_shared/opentelemetryProvider-C_ZXOLSd.js +1 -0
- package/dist/packem_shared/plunkProvider-DfJumQ4U.js +1 -0
- package/dist/packem_shared/postalProvider-Bavx2FcH.js +1 -0
- package/dist/packem_shared/postmarkProvider-DFC0uvjO.js +1 -0
- package/dist/packem_shared/provider-base-Cmzx6BTO.js +1 -0
- package/dist/packem_shared/readFile-BlZxbhCU-C8Z4K-ib.js +1 -0
- package/dist/packem_shared/resendProvider-CfqU7UdE.js +1 -0
- package/dist/packem_shared/roundRobinProvider-1WQnuKR8.js +1 -0
- package/dist/packem_shared/scalewayProvider-be1HPimL.js +1 -0
- package/dist/packem_shared/sendGridProvider-BVI1sq3n.js +1 -0
- package/dist/packem_shared/smtpProvider-BV-ufR53.js +23 -0
- package/dist/packem_shared/sweegoProvider-7419CSAq.js +1 -0
- package/dist/packem_shared/validate-email-options-DfJ7llf8.js +1 -0
- package/dist/packem_shared/zeptomailProvider-C2lh0Xmo.js +1 -0
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/aws-ses/index.js +1 -1
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/brevo/types.d.ts +10 -3
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/http/index.js +1 -1
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/nodemailer/index.js +1 -1
- package/dist/providers/opentelemetry/index.js +1 -1
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/roundrobin/index.js +1 -1
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/utils/cache.d.ts +54 -0
- package/dist/utils/cache.js +1 -0
- package/dist/utils/create-logger.d.ts +2 -4
- package/dist/utils/format-email-address.js +1 -0
- package/dist/utils/normalize-email-aliases.d.ts +22 -0
- package/dist/utils/normalize-email-aliases.js +1 -0
- package/dist/utils/parse-address.js +1 -0
- package/dist/utils/validation/check-mx-records.d.ts +42 -0
- package/dist/utils/validation/check-mx-records.js +1 -0
- package/dist/utils/validation/disposable-email-domains.d.ts +13 -0
- package/dist/utils/validation/disposable-email-domains.js +1 -0
- package/dist/utils/validation/role-accounts.d.ts +21 -0
- package/dist/utils/validation/role-accounts.js +1 -0
- package/dist/utils/{validate-email-options.d.ts → validation/validate-email-options.d.ts} +1 -1
- package/dist/utils/validation/verify-email.d.ts +47 -0
- package/dist/utils/validation/verify-email.js +1 -0
- package/dist/utils/validation/verify-smtp.d.ts +39 -0
- package/dist/utils/validation/verify-smtp.js +4 -0
- package/package.json +49 -3
- package/dist/packem_shared/MailMessage-Hdgowmvi.js +0 -1
- package/dist/packem_shared/ahaSendProvider-NUD_kwyT.js +0 -1
- package/dist/packem_shared/azureProvider-Ckdrpmw9.js +0 -1
- package/dist/packem_shared/brevoProvider-CB3IYW4n.js +0 -1
- package/dist/packem_shared/buildMimeMessage-BPtd0pno.js +0 -2
- package/dist/packem_shared/comparePriority-BfiwjVsV.js +0 -1
- package/dist/packem_shared/createLogger-DlElSVQP.js +0 -1
- package/dist/packem_shared/failoverProvider-sam9n1AG.js +0 -1
- package/dist/packem_shared/formatEmailAddress-CHeME3Vk.js +0 -1
- package/dist/packem_shared/formatEmailAddresses-UegVOe5A.js +0 -1
- package/dist/packem_shared/headersToRecord-BKUTr40L.js +0 -1
- package/dist/packem_shared/httpProvider-BhN0RrK-.js +0 -1
- package/dist/packem_shared/infobipProvider-D8vYTHV4.js +0 -1
- package/dist/packem_shared/isPortAvailable-5kfsfo8u.js +0 -1
- package/dist/packem_shared/mailPaceProvider-C47Izgaj.js +0 -1
- package/dist/packem_shared/mailerSendProvider-C4uAo-fc.js +0 -1
- package/dist/packem_shared/mailgunProvider-B7upu_OV.js +0 -1
- package/dist/packem_shared/mailjetProvider-ReErm08u.js +0 -1
- package/dist/packem_shared/mailomatProvider-OlCT_O2i.js +0 -1
- package/dist/packem_shared/mailtrapProvider-hVMV3h6r.js +0 -1
- package/dist/packem_shared/mandrillProvider-DdnbkHZI.js +0 -1
- package/dist/packem_shared/mockProvider-BDWZJpea.js +0 -1
- package/dist/packem_shared/nodemailerProvider-BV21eRGX.js +0 -1
- package/dist/packem_shared/opentelemetryProvider-kAz62mKm.js +0 -1
- package/dist/packem_shared/parseAddress-CATTKGe_.js +0 -1
- package/dist/packem_shared/plunkProvider-Bs6K51lT.js +0 -1
- package/dist/packem_shared/postalProvider-Bcsxp-z6.js +0 -1
- package/dist/packem_shared/postmarkProvider-BUq3wuYD.js +0 -1
- package/dist/packem_shared/provider-base-_hbWXBdK.js +0 -1
- package/dist/packem_shared/readFile-BlZxbhCU-C8bCdiA2.js +0 -1
- package/dist/packem_shared/resendProvider-D-_HQpN_.js +0 -1
- package/dist/packem_shared/retry-D1MBqS49.js +0 -1
- package/dist/packem_shared/roundRobinProvider-CejLM1rZ.js +0 -1
- package/dist/packem_shared/scalewayProvider-1n6ePiGl.js +0 -1
- package/dist/packem_shared/sendGridProvider-B1T62dyX.js +0 -1
- package/dist/packem_shared/smtpProvider-CcAoRrkt.js +0 -23
- package/dist/packem_shared/sweegoProvider-CxFmEUh6.js +0 -1
- package/dist/packem_shared/validateEmailOptions-BzlJECG5.js +0 -1
- package/dist/packem_shared/zeptomailProvider-CWYQPAJk.js +0 -1
- package/dist/utils/compare-priority.d.ts +0 -16
- /package/dist/utils/{validate-email.d.ts → validation/validate-email.d.ts} +0 -0
- /package/dist/{packem_shared/validateEmail-BkVdVioP.js → utils/validation/validate-email.js} +0 -0
package/dist/mail.d.ts
CHANGED
|
@@ -1,326 +1,142 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type { Provider } from
|
|
4
|
-
import type {
|
|
5
|
-
import type { EmailAddress, EmailHeaders, EmailOptions, EmailResult, Priority, Receipt, Result } from './types.d.ts';
|
|
6
|
-
type AddressInput = EmailAddress | EmailAddress[] | string | string[];
|
|
1
|
+
import DraftMailMessage from "./draft-mail-message.d.ts";
|
|
2
|
+
import MailMessage from "./mail-message.d.ts";
|
|
3
|
+
import type { Provider } from "./providers/provider.d.ts";
|
|
4
|
+
import type { EmailAddress, EmailHeaders, EmailOptions, EmailResult, Receipt, Result } from "./types.d.ts";
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* Type alias for messages that can be sent via Mail.send().
|
|
9
7
|
*/
|
|
10
|
-
export
|
|
11
|
-
/**
|
|
12
|
-
* Builds the email message.
|
|
13
|
-
*/
|
|
14
|
-
build: () => Promise<EmailOptions>;
|
|
15
|
-
}
|
|
8
|
+
export type SendableMessage = MailMessage | EmailOptions;
|
|
16
9
|
/**
|
|
17
|
-
*
|
|
10
|
+
* Global email configuration that applies to all emails sent through a Mail instance.
|
|
18
11
|
*/
|
|
19
|
-
export
|
|
20
|
-
private fromAddress?;
|
|
21
|
-
private toAddresses;
|
|
22
|
-
private ccAddresses;
|
|
23
|
-
private bccAddresses;
|
|
24
|
-
private subjectText;
|
|
25
|
-
private textContent?;
|
|
26
|
-
private autoTextEnabled;
|
|
27
|
-
private htmlContent?;
|
|
28
|
-
private headers;
|
|
29
|
-
private attachments;
|
|
30
|
-
private replyToAddress?;
|
|
31
|
-
private priorityValue?;
|
|
32
|
-
private tagsValue;
|
|
33
|
-
private provider?;
|
|
34
|
-
private signer?;
|
|
35
|
-
private encrypter?;
|
|
36
|
-
private logger?;
|
|
37
|
-
/**
|
|
38
|
-
* Sets the sender address.
|
|
39
|
-
* @param address The sender email address (string or EmailAddress object).
|
|
40
|
-
* @returns This instance for method chaining.
|
|
41
|
-
*/
|
|
42
|
-
from(address: EmailAddress | string): this;
|
|
43
|
-
/**
|
|
44
|
-
* Sets the recipient address(es).
|
|
45
|
-
* @param address The recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
46
|
-
* @returns This instance for method chaining.
|
|
47
|
-
*/
|
|
48
|
-
to(address: AddressInput): this;
|
|
12
|
+
export interface MailGlobalConfig {
|
|
49
13
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @param address The CC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
52
|
-
* @returns This instance for method chaining.
|
|
53
|
-
*/
|
|
54
|
-
cc(address: AddressInput): this;
|
|
55
|
-
/**
|
|
56
|
-
* Sets the BCC recipient address(es).
|
|
57
|
-
* @param address The BCC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
58
|
-
* @returns This instance for method chaining.
|
|
14
|
+
* Default from address to use if not specified in the message.
|
|
59
15
|
*/
|
|
60
|
-
|
|
16
|
+
from?: EmailAddress;
|
|
61
17
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @returns This instance for method chaining.
|
|
65
|
-
*/
|
|
66
|
-
subject(text: string): this;
|
|
67
|
-
/**
|
|
68
|
-
* Sets the plain text content of the email.
|
|
69
|
-
* @param content The plain text content to set.
|
|
70
|
-
* @returns This instance for method chaining.
|
|
18
|
+
* Global headers to add to all emails.
|
|
19
|
+
* These will be merged with message-specific headers, with message headers taking precedence.
|
|
71
20
|
*/
|
|
72
|
-
|
|
21
|
+
headers?: EmailHeaders;
|
|
73
22
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param content The HTML content to set.
|
|
76
|
-
* @returns This instance for method chaining.
|
|
23
|
+
* Default reply-to address to use if not specified in the message.
|
|
77
24
|
*/
|
|
78
|
-
|
|
25
|
+
replyTo?: EmailAddress;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mail class - instance-based email sending.
|
|
29
|
+
*/
|
|
30
|
+
export declare class Mail {
|
|
79
31
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
32
|
+
* Extracts error messages from an error object.
|
|
33
|
+
* @param error Error object to extract messages from.
|
|
34
|
+
* @returns Array of error messages.
|
|
35
|
+
* @private
|
|
84
36
|
*/
|
|
85
|
-
|
|
37
|
+
private static extractErrorMessages;
|
|
38
|
+
private provider;
|
|
39
|
+
private logger?;
|
|
40
|
+
private loggerInstance?;
|
|
41
|
+
private globalConfig?;
|
|
86
42
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @param headers The headers to set (Record or ImmutableHeaders).
|
|
90
|
-
* @returns This instance for method chaining.
|
|
43
|
+
* Creates a new Mail instance with a provider.
|
|
44
|
+
* @param provider The email provider instance.
|
|
91
45
|
*/
|
|
92
|
-
|
|
46
|
+
constructor(provider: Provider);
|
|
93
47
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @param filePath The absolute or relative filesystem path to the file to attach.
|
|
97
|
-
* @param options Optional attachment configuration (filename, contentType, etc.).
|
|
48
|
+
* Sets the logger instance for this mail instance.
|
|
49
|
+
* @param logger The logger instance (Console) to use for logging.
|
|
98
50
|
* @returns This instance for method chaining.
|
|
99
51
|
* @example
|
|
100
52
|
* ```ts
|
|
101
|
-
*
|
|
102
|
-
*
|
|
53
|
+
* const mail = createMail(provider);
|
|
54
|
+
* mail.setLogger(console);
|
|
103
55
|
* ```
|
|
104
56
|
*/
|
|
105
|
-
|
|
57
|
+
setLogger(logger: Console): this;
|
|
106
58
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @param content The content to attach (string or Buffer).
|
|
110
|
-
* @param options Attachment options including filename.
|
|
59
|
+
* Sets the default from address for all emails sent through this Mail instance.
|
|
60
|
+
* @param from Default from address to use if not specified in the message.
|
|
111
61
|
* @returns This instance for method chaining.
|
|
112
62
|
* @example
|
|
113
63
|
* ```ts
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
attachData(content: string | Buffer, options: AttachmentDataOptions): this;
|
|
119
|
-
/**
|
|
120
|
-
* Embeds an inline attachment from file path (for images in HTML).
|
|
121
|
-
* Similar to Laravel's embed() method.
|
|
122
|
-
* Returns the Content-ID that can be used in HTML: <img src="cid:{cid}">.
|
|
123
|
-
* @param filePath The path to the file to embed.
|
|
124
|
-
* @param options Optional attachment options (filename, contentType, etc.).
|
|
125
|
-
* @returns The Content-ID string that can be used in HTML.
|
|
126
|
-
* @example
|
|
127
|
-
* ```ts
|
|
128
|
-
* const cid = await message.embedFromPath('/path/to/logo.png')
|
|
129
|
-
* message.html(`<img src="cid:${cid}">`)
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
embedFromPath(filePath: string, options?: Omit<AttachmentOptions, "contentDisposition" | "cid">): Promise<string>;
|
|
133
|
-
/**
|
|
134
|
-
* Embeds raw data as inline attachment (for images in HTML).
|
|
135
|
-
* Similar to Laravel's embedData() method.
|
|
136
|
-
* Returns the Content-ID that can be used in HTML: <img src="cid:{cid}">.
|
|
137
|
-
* @param content The content to embed (string or Buffer).
|
|
138
|
-
* @param filename The filename for the embedded attachment.
|
|
139
|
-
* @param options Optional attachment options (contentType, etc.).
|
|
140
|
-
* @returns The Content-ID string that can be used in HTML.
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* const imageBuffer = Buffer.from('...')
|
|
144
|
-
* const cid = message.embedData(imageBuffer, 'logo.png', { contentType: 'image/png' })
|
|
145
|
-
* message.html(`<img src="cid:${cid}">`)
|
|
64
|
+
* const mail = createMail(provider);
|
|
65
|
+
* mail.setFrom({ email: "noreply@example.com", name: "My App" });
|
|
146
66
|
* ```
|
|
147
67
|
*/
|
|
148
|
-
|
|
68
|
+
setFrom(from: EmailAddress): this;
|
|
149
69
|
/**
|
|
150
|
-
* Sets the reply-to address.
|
|
151
|
-
* @param
|
|
70
|
+
* Sets the default reply-to address for all emails sent through this Mail instance.
|
|
71
|
+
* @param replyTo Default reply-to address to use if not specified in the message.
|
|
152
72
|
* @returns This instance for method chaining.
|
|
153
|
-
*/
|
|
154
|
-
replyTo(address: EmailAddress | string): this;
|
|
155
|
-
/**
|
|
156
|
-
* Sets the email priority.
|
|
157
|
-
* @param priority The priority level ('high', 'normal', or 'low').
|
|
158
|
-
* @returns This instance for method chaining.
|
|
159
|
-
*/
|
|
160
|
-
priority(priority: Priority): this;
|
|
161
|
-
/**
|
|
162
|
-
* Sets email tags for categorization.
|
|
163
|
-
* @param tags The tags to set (string or array of strings).
|
|
164
|
-
* @returns This instance for method chaining.
|
|
165
|
-
*/
|
|
166
|
-
tags(tags: string | string[]): this;
|
|
167
|
-
/**
|
|
168
|
-
* Sets the provider to use for sending.
|
|
169
|
-
* @param provider The email provider instance.
|
|
170
|
-
* @returns This instance for method chaining.
|
|
171
|
-
*/
|
|
172
|
-
mailer(provider: Provider): this;
|
|
173
|
-
/**
|
|
174
|
-
* Signs the email message using a signer (DKIM or S/MIME).
|
|
175
|
-
* @param signer The signer instance to use.
|
|
176
|
-
* @example
|
|
177
|
-
* ```ts
|
|
178
|
-
* import { createDkimSigner } from '@visulima/email/crypto';
|
|
179
|
-
* const signer = createDkimSigner({
|
|
180
|
-
* domainName: 'example.com',
|
|
181
|
-
* keySelector: 'default',
|
|
182
|
-
* privateKey: '-----BEGIN PRIVATE KEY-----...'
|
|
183
|
-
* });
|
|
184
|
-
* message.sign(signer)
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
sign(signer: EmailSigner): this;
|
|
188
|
-
/**
|
|
189
|
-
* Encrypts the email message using an encrypter (S/MIME).
|
|
190
|
-
* @param encrypter The encrypter instance to use.
|
|
191
73
|
* @example
|
|
192
74
|
* ```ts
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* certificates: '/path/to/certificate.crt'
|
|
196
|
-
* });
|
|
197
|
-
* message.encrypt(encrypter)
|
|
75
|
+
* const mail = createMail(provider);
|
|
76
|
+
* mail.setReplyTo({ email: "support@example.com" });
|
|
198
77
|
* ```
|
|
199
78
|
*/
|
|
200
|
-
|
|
79
|
+
setReplyTo(replyTo: EmailAddress): this;
|
|
201
80
|
/**
|
|
202
|
-
* Sets
|
|
203
|
-
*
|
|
81
|
+
* Sets default headers for all emails sent through this Mail instance.
|
|
82
|
+
* These headers will be merged with message-specific headers, with message headers taking precedence.
|
|
83
|
+
* @param headers Default headers to add to all emails.
|
|
204
84
|
* @returns This instance for method chaining.
|
|
205
85
|
* @example
|
|
206
86
|
* ```ts
|
|
207
|
-
*
|
|
87
|
+
* const mail = createMail(provider);
|
|
88
|
+
* mail.setHeaders({ "X-App-Name": "MyApp", "X-Version": "1.0.0" });
|
|
208
89
|
* ```
|
|
209
90
|
*/
|
|
210
|
-
|
|
91
|
+
setHeaders(headers: EmailHeaders): this;
|
|
211
92
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* @param
|
|
215
|
-
* @
|
|
216
|
-
* @param data Optional data/variables to pass to the template.
|
|
217
|
-
* @param options Optional renderer-specific options.
|
|
218
|
-
* @param options.autoText Whether to auto-generate text version from HTML (default: true).
|
|
219
|
-
* @returns This instance for method chaining.
|
|
93
|
+
* Creates a draft email in EML (RFC 822) format without sending it.
|
|
94
|
+
* This is useful for previewing, saving for later, or testing email content.
|
|
95
|
+
* @param message The message to create a draft from (MailMessage or EmailOptions).
|
|
96
|
+
* @returns The email in EML (RFC 822) format as a string with X-Unsent: 1 header.
|
|
220
97
|
* @example
|
|
221
98
|
* ```ts
|
|
222
|
-
*
|
|
223
|
-
* message
|
|
99
|
+
* // Create a draft from MailMessage
|
|
100
|
+
* const message = new MailMessage()
|
|
101
|
+
* .to("user@example.com")
|
|
102
|
+
* .from("sender@example.com")
|
|
103
|
+
* .subject("Hello")
|
|
104
|
+
* .html("<h1>Hello World</h1>");
|
|
224
105
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
106
|
+
* const eml = await mail.draft(message);
|
|
107
|
+
* console.log("Draft EML:", eml);
|
|
227
108
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
|
|
232
|
-
view(render: TemplateRenderer, template: unknown, data?: Record<string, unknown>, options?: {
|
|
233
|
-
[key: string]: unknown;
|
|
234
|
-
autoText?: boolean;
|
|
235
|
-
}): Promise<this>;
|
|
236
|
-
/**
|
|
237
|
-
* Renders a text template and sets as text content.
|
|
238
|
-
* @param render The template renderer function.
|
|
239
|
-
* @param template The text template content.
|
|
240
|
-
* @param data Optional data/variables to pass to the template.
|
|
241
|
-
* @param options Optional renderer-specific options.
|
|
242
|
-
* @returns This instance for method chaining.
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* import { renderHandlebars } from '@visulima/email/template/handlebars';
|
|
246
|
-
* message.viewText(renderHandlebars, 'Hello {{name}}!', { name: 'John' })
|
|
109
|
+
* // Save to file
|
|
110
|
+
* await fs.writeFile("draft.eml", eml);
|
|
111
|
+
*
|
|
112
|
+
* // Or send later by parsing the EML back to EmailOptions
|
|
247
113
|
* ```
|
|
248
114
|
*/
|
|
249
|
-
|
|
115
|
+
draft(message: SendableMessage | DraftMailMessage): Promise<string>;
|
|
250
116
|
/**
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
253
|
-
* @throws {Error} When required fields (from, to, subject, content) are missing.
|
|
254
|
-
*/
|
|
255
|
-
build(): Promise<EmailOptions>;
|
|
256
|
-
/**
|
|
257
|
-
* Sends the email.
|
|
117
|
+
* Sends an email message or email options.
|
|
118
|
+
* @param message The message to send (MailMessage or EmailOptions).
|
|
258
119
|
* @returns A result object containing the email result or error.
|
|
259
|
-
* @throws {Error} When no provider is configured.
|
|
260
|
-
*/
|
|
261
|
-
send(): Promise<Result<EmailResult>>;
|
|
262
|
-
/**
|
|
263
|
-
* Attempts to auto-generate text content from HTML.
|
|
264
|
-
* @param html The HTML content to convert.
|
|
265
|
-
* @private
|
|
266
|
-
*/
|
|
267
|
-
private tryAutoGenerateText;
|
|
268
|
-
/**
|
|
269
|
-
* Creates an error, logs it, and throws it.
|
|
270
|
-
* @param message Error message to throw.
|
|
271
|
-
* @param logMessage Optional log message (defaults to message).
|
|
272
|
-
* @private
|
|
273
|
-
*/
|
|
274
|
-
private throwAndLogError;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Mail class - instance-based email sending.
|
|
278
|
-
*/
|
|
279
|
-
export declare class Mail {
|
|
280
|
-
/**
|
|
281
|
-
* Extracts error messages from an error object.
|
|
282
|
-
* @param error Error object to extract messages from.
|
|
283
|
-
* @returns Array of error messages.
|
|
284
|
-
* @private
|
|
285
|
-
*/
|
|
286
|
-
private static extractErrorMessages;
|
|
287
|
-
private provider;
|
|
288
|
-
private logger?;
|
|
289
|
-
private loggerInstance?;
|
|
290
|
-
/**
|
|
291
|
-
* Creates a new Mail instance with a provider.
|
|
292
|
-
* @param provider The email provider instance.
|
|
293
|
-
*/
|
|
294
|
-
constructor(provider: Provider);
|
|
295
|
-
/**
|
|
296
|
-
* Sets the logger instance for this mail instance.
|
|
297
|
-
* The logger will be passed to all MailMessage instances created via message().
|
|
298
|
-
* @param logger The logger instance (Console) to use for logging.
|
|
299
|
-
* @returns This instance for method chaining.
|
|
300
120
|
* @example
|
|
301
121
|
* ```ts
|
|
302
|
-
*
|
|
303
|
-
*
|
|
122
|
+
* // Using MailMessage
|
|
123
|
+
* const message = new MailMessage()
|
|
124
|
+
* .to("user@example.com")
|
|
125
|
+
* .from("sender@example.com")
|
|
126
|
+
* .subject("Hello")
|
|
127
|
+
* .html("<h1>Hello World</h1>");
|
|
128
|
+
* await mail.send(message);
|
|
129
|
+
*
|
|
130
|
+
* // Using EmailOptions
|
|
131
|
+
* await mail.send({
|
|
132
|
+
* to: "user@example.com",
|
|
133
|
+
* from: "sender@example.com",
|
|
134
|
+
* subject: "Hello",
|
|
135
|
+
* html: "<h1>Hello World</h1>"
|
|
136
|
+
* });
|
|
304
137
|
* ```
|
|
305
138
|
*/
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Creates a new mail message.
|
|
309
|
-
* @returns A new MailMessage instance configured with this provider.
|
|
310
|
-
*/
|
|
311
|
-
message(): MailMessage;
|
|
312
|
-
/**
|
|
313
|
-
* Sends a mailable instance.
|
|
314
|
-
* @param mailable The mailable instance to send.
|
|
315
|
-
* @returns A result object containing the email result or error.
|
|
316
|
-
*/
|
|
317
|
-
send(mailable: Mailable): Promise<Result<EmailResult>>;
|
|
318
|
-
/**
|
|
319
|
-
* Sends email using email options directly.
|
|
320
|
-
* @param options The email options to send.
|
|
321
|
-
* @returns A result object containing the email result or error.
|
|
322
|
-
*/
|
|
323
|
-
sendEmail(options: EmailOptions): Promise<Result<EmailResult>>;
|
|
139
|
+
send(message: SendableMessage): Promise<Result<EmailResult>>;
|
|
324
140
|
/**
|
|
325
141
|
* Sends multiple messages using the email service.
|
|
326
142
|
* Returns an async iterable that yields receipts for each sent message.
|
|
@@ -339,19 +155,52 @@ export declare class Mail {
|
|
|
339
155
|
* }
|
|
340
156
|
* }
|
|
341
157
|
* ```
|
|
342
|
-
* @param messages An iterable of
|
|
158
|
+
* @param messages An iterable of MailMessage instances or email options to send.
|
|
343
159
|
* @param options Optional parameters for sending.
|
|
344
160
|
* @param options.signal Abort signal to cancel the operation.
|
|
345
161
|
* @returns An async iterable that yields receipts for each sent message.
|
|
346
162
|
*/
|
|
347
|
-
sendMany(messages: Iterable<
|
|
163
|
+
sendMany(messages: Iterable<SendableMessage> | AsyncIterable<SendableMessage>, options?: {
|
|
348
164
|
signal?: AbortSignal;
|
|
349
165
|
}): AsyncIterable<Receipt>;
|
|
166
|
+
/**
|
|
167
|
+
* Builds email options from a MailMessage instance for draft creation.
|
|
168
|
+
* Applies global configuration before building to ensure required fields are set.
|
|
169
|
+
* @param message The MailMessage or DraftMailMessage instance.
|
|
170
|
+
* @returns Built email options.
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
private buildDraftFromMessage;
|
|
174
|
+
/**
|
|
175
|
+
* Builds email options from EmailOptions for draft creation.
|
|
176
|
+
* @param options The EmailOptions object.
|
|
177
|
+
* @returns Email options.
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
private buildDraftFromOptions;
|
|
181
|
+
/**
|
|
182
|
+
* Applies global configuration to a MailMessage instance.
|
|
183
|
+
* @param message The MailMessage or DraftMailMessage instance.
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
private applyGlobalConfigToMessage;
|
|
187
|
+
/**
|
|
188
|
+
* Applies global configuration to email options.
|
|
189
|
+
* Global values are only applied if the corresponding field is not already set in the email options.
|
|
190
|
+
* @param emailOptions The email options to apply global configuration to.
|
|
191
|
+
* @returns Email options with global configuration applied.
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
private applyGlobalConfig;
|
|
350
195
|
}
|
|
351
196
|
/**
|
|
352
197
|
* Creates a new Mail instance with a provider.
|
|
353
198
|
* @param provider The email provider instance.
|
|
354
199
|
* @returns A new Mail instance.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* const mail = createMail(provider);
|
|
203
|
+
* mail.setFrom({ email: "noreply@example.com", name: "My App" });
|
|
204
|
+
* ```
|
|
355
205
|
*/
|
|
356
206
|
export declare const createMail: (provider: Provider) => Mail;
|
|
357
|
-
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var v=Object.defineProperty;var m=(o,e)=>v(o,"name",{value:e,configurable:!0});import{createRequire as w}from"node:module";import{B as x}from"./readFile-BlZxbhCU-
|
|
1
|
+
var v=Object.defineProperty;var m=(o,e)=>v(o,"name",{value:e,configurable:!0});import{createRequire as w}from"node:module";import{B as x}from"./readFile-BlZxbhCU-C8Z4K-ib.js";import{i as z}from"./headers-to-record-Qo124ImV.js";const C=w(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=m(o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[e,t]=p.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return p.getBuiltinModule(o)}return C(o)},"__cjs_getBuiltinModule"),{createHash:M,createSign:S,createPrivateKey:_}=T("node:crypto");var H=Object.defineProperty,d=m((o,e)=>H(o,"name",{value:e,configurable:!0}),"l");const I=d((o,e="simple")=>{const t=[];for(const[r,a]of Object.entries(o)){const n=e==="relaxed"?r.toLowerCase().trim():r,s=e==="relaxed"?a.replaceAll(/\s+/g," ").trim():a;t.push(`${n}:${s}`)}return t.join(`\r
|
|
2
2
|
`)},"canonicalizeHeaders"),K=d((o,e="simple")=>{if(e==="simple"){const n=o.replace(/(\r\n|\r|\n)$/,`
|
|
3
3
|
`);let s=n.length;for(;s>0&&n[s-1]===`
|
|
4
4
|
`;)s-=1;const c=n.slice(0,s);return c?`${c}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var b=Object.defineProperty;var l=(o,e)=>b(o,"name",{value:e,configurable:!0});import{MailMessage as f}from"./MailMessage-n7kyh9vB.js";import{z as p}from"./build-mime-message-IYaUqqPJ.js";import{c as m}from"./create-logger-BiWdqFNg.js";import{i as n}from"./headers-to-record-Qo124ImV.js";var y=Object.defineProperty,C=l((o,e)=>y(o,"name",{value:e,configurable:!0}),"s");class h extends f{static{l(this,"DraftMailMessage")}static{C(this,"DraftMailMessage")}constructor(){super(),this.header("X-Unsent","1")}}var M=Object.defineProperty,c=l((o,e)=>M(o,"name",{value:e,configurable:!0}),"n");const v=c((o,e,s)=>{e.success&&e.data?o&&o.info("Email sent successfully",{messageId:e.data.messageId,provider:e.data.provider}):o&&o.error("Email send failed",{error:e.error,provider:s})},"logSendResult");class d{static{l(this,"Mail")}static{c(this,"Mail")}static extractErrorMessages(e){return e instanceof Error?[e.message]:[String(e||"Unknown error")]}provider;logger;loggerInstance;globalConfig;constructor(e){this.provider=e}setLogger(e){return this.loggerInstance=e,this.logger=m("Mail",e),this}setFrom(e){return this.globalConfig||(this.globalConfig={}),this.globalConfig.from=e,this.logger&&this.logger.debug("Default from address updated",{from:e.email}),this}setReplyTo(e){return this.globalConfig||(this.globalConfig={}),this.globalConfig.replyTo=e,this.logger&&this.logger.debug("Default reply-to address updated",{replyTo:e.email}),this}setHeaders(e){if(this.globalConfig||(this.globalConfig={}),this.globalConfig.headers=e,this.logger){const s=n(e);this.logger.debug("Default headers updated",{count:Object.keys(s).length,headers:Object.keys(s)})}return this}async draft(e){let s=e instanceof f||e instanceof h?await this.buildDraftFromMessage(e):await this.buildDraftFromOptions(e);s=this.applyGlobalConfig(s);const t=s.headers?n(s.headers):{};s.headers={...t,"X-Unsent":"1"};const r=await p(s);return this.logger&&this.logger.debug("Draft created successfully in EML format",{from:s.from.email,size:r.length,subject:s.subject,to:Array.isArray(s.to)?s.to.length:1}),r}async send(e){if(e instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");let s;if(e instanceof f)this.logger&&this.logger.debug("Sending MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),s=await e.build();else{const r=e;this.logger&&this.logger.debug("Sending email with options",{subject:r.subject,to:Array.isArray(r.to)?r.to.length:1}),s=r}s=this.applyGlobalConfig(s);const t=await this.provider.sendEmail(s);return v(this.logger,t,this.provider.name||"unknown"),t}async*sendMany(e,s){const t=this.provider.name;let r=0,g=0,i=0;this.logger&&this.logger.debug("Starting batch email send",{provider:t});for await(const u of e){if(u instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");if(s?.signal?.aborted){this.logger&&this.logger.warn("Batch send operation was aborted",{failed:i,processed:r,successful:g}),yield{errorMessages:["Send operation was aborted"],provider:t,successful:!1};return}r+=1;try{const a=await this.send(u);a.success&&a.data?(g+=1,this.logger&&this.logger.debug(`Email ${r} sent successfully`,{messageId:a.data.messageId}),yield{messageId:a.data.messageId,provider:a.data.provider||t,response:a.data.response,successful:!0,timestamp:a.data.timestamp}):(i+=1,this.logger&&this.logger.error(`Email ${r} send failed`,{error:a.error}),yield{errorMessages:d.extractErrorMessages(a.error),provider:t,successful:!1})}catch(a){i+=1,this.logger&&this.logger.error(`Email ${r} send failed with exception`,a),yield{errorMessages:d.extractErrorMessages(a),provider:t,successful:!1}}}this.logger&&this.logger.debug("Batch email send completed",{failureCount:i,processedCount:r,provider:t,successCount:g})}async buildDraftFromMessage(e){return this.logger&&this.logger.debug("Creating draft from MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),this.applyGlobalConfigToMessage(e),await e.build()}async buildDraftFromOptions(e){return this.logger&&this.logger.debug("Creating draft from email options",{subject:e.subject,to:Array.isArray(e.to)?e.to.length:1}),e}applyGlobalConfigToMessage(e){const s=this.globalConfig?.from;s&&!e.getFrom()&&e.from(s);const t=this.globalConfig?.replyTo;if(t&&!e.getReplyTo()&&e.replyTo(t),this.globalConfig?.headers){const r=n(this.globalConfig.headers);Object.entries(r).forEach(([g,i])=>{e.header(g,i)})}}applyGlobalConfig(e){if(!this.globalConfig)return e;const s={...e};if(!s.from&&this.globalConfig.from&&(s.from=this.globalConfig.from,this.logger&&this.logger.debug("Applied global from address",{from:this.globalConfig.from.email})),!s.replyTo&&this.globalConfig.replyTo&&(s.replyTo=this.globalConfig.replyTo,this.logger&&this.logger.debug("Applied global reply-to address",{replyTo:this.globalConfig.replyTo.email})),this.globalConfig.headers){const t=n(this.globalConfig.headers),r=s.headers?n(s.headers):{};s.headers={...t,...r},this.logger&&this.logger.debug("Merged global headers",{globalCount:Object.keys(t).length,messageCount:Object.keys(r).length})}return s}}const D=c(o=>new d(o),"createMail");export{d as Mail,D as createMail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var A=Object.defineProperty;var d=(n,e)=>A(n,"name",{value:e,configurable:!0});import{createRequire as b}from"node:module";import C from"ical-generator";import{readFileAsBuffer as u,detectMimeType as g,generateContentId as m}from"./detectMimeType-CrDG3LaZ.js";import p from"../template-engines/html-to-text.js";import{c as E}from"./create-logger-BiWdqFNg.js";import{i as l}from"./headers-to-record-Qo124ImV.js";const T=b(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=d(n=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,t]=a.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return a.getBuiltinModule(n)}return T(n)},"__cjs_getBuiltinModule"),{basename:c}=f("node:path"),{fileURLToPath:x}=f("node:url");var w=Object.defineProperty,y=d((n,e)=>w(n,"name",{value:e,configurable:!0}),"l");const o=y(n=>Array.isArray(n)?n.map(e=>typeof e=="string"?{email:e}:e):typeof n=="string"?[{email:n}]:[n],"normalizeAddresses");class M{static{d(this,"MailMessage")}static{y(this,"MailMessage")}fromAddress;toAddresses=[];ccAddresses=[];bccAddresses=[];subjectText="";textContent;textCharset="utf8";autoTextEnabled=!0;htmlContent;htmlCharset="utf8";dateValue;returnPathAddress;senderAddress;headers={};attachments=[];replyToAddress;priorityValue;tagsValue=[];signer;encrypter;logger;icalEventData;from(e){return this.fromAddress=typeof e=="string"?{email:e}:e,this}to(e){return this.toAddresses.length=0,this.toAddresses.push(...o(e)),this}cc(e){return this.ccAddresses.length=0,this.ccAddresses.push(...o(e)),this}bcc(e){return this.bccAddresses.length=0,this.bccAddresses.push(...o(e)),this}subject(e){return this.subjectText=e,this}text(e,t="utf8"){return this.textContent=e,this.textCharset=t,this}html(e,t="utf8"){return this.htmlContent=e,this.htmlCharset=t,this}header(e,t){return this.headers[e]=t,this}setHeaders(e){const t=l(e);return Object.assign(this.headers,t),this}async attachFromPath(e,t){try{const s=await u(e),i=t?.filename||c(e)||"attachment",r=t?.contentType||g(i);this.attachments.push({cid:t?.cid,content:s,contentDisposition:t?.contentDisposition||"attachment",contentType:r,encoding:t?.encoding,filename:i,headers:t?.headers}),this.logger&&this.logger.debug(`Attachment added from path: ${e}`,{contentType:r,filename:i})}catch(s){throw this.logger&&this.logger.error(`Failed to attach file from path: ${e}`,s),s}return this}attachData(e,t){const s=t.contentType||g(t.filename);return this.attachments.push({cid:t.cid,content:e,contentDisposition:t.contentDisposition||"attachment",contentType:s,encoding:t.encoding,filename:t.filename,headers:t.headers}),this.logger&&this.logger.debug("Attachment added from data",{contentType:s,filename:t.filename}),this}async embedFromPath(e,t){try{const s=await u(e),i=t?.filename||c(e)||"inline",r=t?.contentType||g(i),h=m(i);return this.attachments.push({cid:h,content:s,contentDisposition:"inline",contentType:r,filename:i}),this.logger&&this.logger.debug(`Inline attachment embedded from path: ${e}`,{cid:h,contentType:r,filename:i}),h}catch(s){throw this.logger&&this.logger.error(`Failed to embed file from path: ${e}`,s),s}}embedData(e,t,s){const i=s?.contentType||g(t),r=m(t);return this.attachments.push({cid:r,content:e,contentDisposition:"inline",contentType:i,filename:t}),this.logger&&this.logger.debug("Inline attachment embedded from data",{cid:r,contentType:i,filename:t}),r}replyTo(e){return this.replyToAddress=typeof e=="string"?{email:e}:e,this}date(e){return this.dateValue=typeof e=="string"?new Date(e):e,this.logger&&this.logger.debug("Date header set",{date:this.dateValue.toISOString()}),this}returnPath(e){return this.returnPathAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Return-path address set",{returnPath:this.returnPathAddress.email}),this}sender(e){return this.senderAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Sender address set",{sender:this.senderAddress.email}),this}addTo(e){return this.toAddresses.push(...o(e)),this}addCc(e){return this.ccAddresses.push(...o(e)),this}addBcc(e){return this.bccAddresses.push(...o(e)),this}addReplyTo(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.replyToAddress=typeof s=="string"?{email:s}:s}return this}addFrom(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.fromAddress=typeof s=="string"?{email:s}:s}return this}priority(e){return this.priorityValue=e,this}tags(e){return this.tagsValue=Array.isArray(e)?e:[e],this}sign(e){return this.signer=e,this.logger&&this.logger.debug("Email signer configured"),this}encrypt(e){return this.encrypter=e,this.logger&&this.logger.debug("Email encrypter configured"),this}setLogger(e){return this.logger=E("MailMessage",e),this}icalEvent(e,t){if(typeof e=="function"){const s=C();e(s),this.icalEventData={content:s.toString(),...t}}else this.icalEventData={content:e,...t};return this.logger&&this.logger.debug("Calendar event attached",{method:t?.method}),this}icalEventFromFile(e,t){const s=typeof e=="string"?e:x(e);return this.icalEventData={path:s,...t},this.logger&&this.logger.debug(`Calendar event attached from file: ${s}`,{method:t?.method}),this}icalEventFromUrl(e,t){return this.icalEventData={href:e,...t},this.logger&&this.logger.debug(`Calendar event attached from URL: ${e}`,{method:t?.method}),this}async view(e,t,s,i){try{const r=i?.autoText!==!1;this.autoTextEnabled=r,this.logger&&this.logger.debug("Rendering template",{autoText:r});const h=await e(t,s,i);this.html(h),r&&h&&this.tryAutoGenerateText(h),this.logger&&this.logger.debug("Template rendered successfully")}catch(r){throw this.logger&&this.logger.error("Failed to render template",r),new Error(`Failed to render template: ${r.message}`)}return this}async viewText(e,t,s,i){try{this.logger&&this.logger.debug("Rendering text template");const r=await e(t,s,i);if(typeof r=="string")this.text(r),this.logger&&this.logger.debug("Text template rendered successfully");else throw new TypeError("Text renderer must return a string")}catch(r){throw this.logger&&this.logger.error("Failed to render text template",r),new Error(`Failed to render text template: ${r.message}`)}return this}async build(){if(this.logger&&this.logger.debug("Building email message"),this.fromAddress||this.throwAndLogError("From address is required","Build failed: from address is required"),this.toAddresses.length===0&&this.throwAndLogError("At least one recipient is required","Build failed: at least one recipient is required"),this.subjectText||this.throwAndLogError("Subject is required","Build failed: subject is required"),this.htmlContent&&!this.textContent&&this.autoTextEnabled)try{this.textContent=p(this.htmlContent),this.logger&&this.logger.debug("Auto-generated text content from HTML")}catch{this.logger&&this.logger.debug("Failed to convert HTML to text; proceeding without text content.")}!this.textContent&&!this.htmlContent&&this.throwAndLogError("Either text or html content is required","Build failed: either text or html content is required");let e={from:this.fromAddress,html:this.htmlContent,subject:this.subjectText,text:this.textContent,to:this.toAddresses.length===1?this.toAddresses[0]:this.toAddresses};return this.ccAddresses.length>0&&(e.cc=this.ccAddresses.length===1?this.ccAddresses[0]:this.ccAddresses),this.bccAddresses.length>0&&(e.bcc=this.bccAddresses.length===1?this.bccAddresses[0]:this.bccAddresses),Object.keys(this.headers).length>0&&(e.headers=this.headers),this.attachments.length>0&&(e.attachments=this.attachments,this.logger&&this.logger.debug(`Email includes ${this.attachments.length} attachment(s)`)),this.replyToAddress&&(e.replyTo=this.replyToAddress),this.priorityValue&&(e.priority=this.priorityValue),this.tagsValue.length>0&&(e.tags=this.tagsValue),this.icalEventData&&(e.icalEvent=this.icalEventData,this.logger&&this.logger.debug("Email includes calendar event")),this.dateValue&&(e.headers={...l(e.headers||{}),Date:this.dateValue.toUTCString()}),this.returnPathAddress&&(e.headers={...l(e.headers||{}),"Return-Path":this.returnPathAddress.email}),this.senderAddress&&(e.headers={...l(e.headers||{}),Sender:this.senderAddress.email}),this.signer&&(this.logger&&this.logger.debug("Signing email message"),e=await this.signer.sign(e),this.logger&&this.logger.debug("Email message signed successfully")),this.encrypter&&(this.logger&&this.logger.debug("Encrypting email message"),e=await this.encrypter.encrypt(e),this.logger&&this.logger.debug("Email message encrypted successfully")),this.logger&&this.logger.debug("Email message built successfully",{bcc:this.bccAddresses.length,cc:this.ccAddresses.length,hasHtml:!!this.htmlContent,hasText:!!this.textContent,to:this.toAddresses.length}),e}getSubject(){return this.subjectText}getFrom(){return this.fromAddress}getTo(){return[...this.toAddresses]}getCc(){return[...this.ccAddresses]}getBcc(){return[...this.bccAddresses]}getReplyTo(){return this.replyToAddress}getSender(){return this.senderAddress}getReturnPath(){return this.returnPathAddress}getDate(){return this.dateValue}getPriority(){return this.priorityValue}getTextBody(){return this.textContent}getTextCharset(){return this.textCharset}getHtmlBody(){return this.htmlContent}getHtmlCharset(){return this.htmlCharset}getAttachments(){return[...this.attachments]}tryAutoGenerateText(e){try{const t=p(e);t&&!this.textContent&&this.text(t),this.logger&&this.logger.debug("Auto-generated text content from HTML template")}catch(t){this.logger&&this.logger.warn("Failed to auto-generate text from HTML template",t)}}throwAndLogError(e,t){const s=new Error(e);throw this.logger&&this.logger.error(t||e),s}}export{M as MailMessage,M as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var K=Object.defineProperty;var g=(s,e)=>K(s,"name",{value:e,configurable:!0});import{createRequire as U}from"node:module";import{B as S}from"./readFile-BlZxbhCU-
|
|
1
|
+
var K=Object.defineProperty;var g=(s,e)=>K(s,"name",{value:e,configurable:!0});import{createRequire as U}from"node:module";import{B as S}from"./readFile-BlZxbhCU-C8Z4K-ib.js";import{fromBER as $,OctetString as T}from"asn1js";import{Certificate as j,EnvelopedData as z,EncryptedContentInfo as J,id_ContentType_Data as Q,RecipientInfo as W,KeyTransRecipientInfo as X,IssuerAndSerialNumber as Y,AlgorithmIdentifier as x,ContentInfo as Z,id_ContentType_EnvelopedData as ee}from"pkijs";const q=U(import.meta.url),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,H=g(s=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,t]=h.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return h.getBuiltinModule(s)}return q(s)},"__cjs_getBuiltinModule"),{randomBytes:I,createCipheriv:L,createPublicKey:G,publicEncrypt:V}=H("node:crypto");var te=Object.defineProperty,y=g((s,e)=>te(s,"name",{value:e,configurable:!0}),"l");const w=globalThis.Buffer!==void 0,N=y(s=>{const e=s.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(w)return Buffer.from(e,"base64");const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n},"pemToDer"),R=y((s,e)=>{let t;if(w)t=Buffer.from(s).toString("base64");else{const r=new Uint8Array(s);let u="";const o=8192;for(let i=0;i<r.length;i+=o){const m=r.subarray(i,Math.min(i+o,r.length));u+=String.fromCharCode.apply(void 0,m)}t=btoa(u)}const n=t.match(/.{1,64}/g)||[];return`-----BEGIN ${e}-----
|
|
2
2
|
${n.join(`
|
|
3
3
|
`)}
|
|
4
4
|
-----END ${e}-----
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var L=Object.defineProperty;var g=(n,e)=>L(n,"name",{value:e,configurable:!0});import{createRequire as V}from"node:module";import{B as b}from"./readFile-BlZxbhCU-
|
|
1
|
+
var L=Object.defineProperty;var g=(n,e)=>L(n,"name",{value:e,configurable:!0});import{createRequire as V}from"node:module";import{B as b}from"./readFile-BlZxbhCU-C8Z4K-ib.js";import{fromBER as B,ObjectIdentifier as Y,OctetString as E,UTCTime as Z}from"asn1js";import{Certificate as N,SignedData as ee,EncapsulatedContentInfo as te,id_ContentType_Data as D,SignerInfo as re,AlgorithmIdentifier as P,IssuerAndSerialNumber as ne,id_sha256 as se,SignedAndUnsignedAttributes as oe,Attribute as A,ContentInfo as ie,id_ContentType_SignedData as ae}from"pkijs";import{a as ce}from"./generate-boundary-Cx8nXYS0.js";const z=V(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,J=g(n=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,t]=u.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return u.getBuiltinModule(n)}return z(n)},"__cjs_getBuiltinModule"),{createPrivateKey:x,createHash:Q,createSign:W,randomBytes:X}=J("node:crypto");var le=Object.defineProperty,y=g((n,e)=>le(n,"name",{value:e,configurable:!0}),"u");const pe="1.2.840.113549.1.9.3",ue="1.2.840.113549.1.9.4",fe="1.2.840.113549.1.9.5",me="1.2.840.113549.1.1.1",de={v1:1},he={v1:1},f=globalThis.Buffer!==void 0,M=y(n=>{const e=n.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(f)return Buffer.from(e,"base64");const t=atob(e),o=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)o[r]=t.codePointAt(r);return o},"pemToDer"),ge=y((n,e)=>{let t;if(f)t=Buffer.from(n).toString("base64");else{const r=new Uint8Array(n);let s="";const a=8192;for(let i=0;i<r.length;i+=a){const d=r.subarray(i,Math.min(i+a,r.length));s+=String.fromCharCode.apply(void 0,d)}t=btoa(s)}const o=t.match(/.{1,64}/g)||[];return`-----BEGIN ${e}-----
|
|
2
2
|
${o.join(`
|
|
3
3
|
`)}
|
|
4
4
|
-----END ${e}-----
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var P=Object.defineProperty;var y=(i,r)=>P(i,"name",{value:r,configurable:!0});import{createRequire as $}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-BDzF9W9D.js";import{c as z,u as b,h as w,P as k}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DfJ7llf8.js";import{defineProvider as K}from"./defineProvider-B9rSklAJ.js";import{f as p,a as B}from"./address-formatter-Cm_E_ZMa.js";const I=$(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=y(i=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,u]=m.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return m.getBuiltinModule(i)}return I(i)},"__cjs_getBuiltinModule"),{Buffer:j}=T("node:buffer"),s="ahasend",C="https://api.ahasend.com",x=3e4,G=3,Q=K((i={})=>{if(!i.apiKey)throw new S(s,"apiKey");const r={apiKey:i.apiKey,debug:i.debug||!1,endpoint:i.endpoint||C,retries:i.retries||G,timeout:i.timeout||x,...i.logger&&{logger:i.logger}},u=new k,n=z(s,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(s,"Email ID is required to retrieve email details"),success:!1};await this.initialize();const o={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>f(`${r.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:r.timeout}),r.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(s,"retrieve email",o,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(s,"AhaSend API not available or invalid API key");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{return n.debug("Checking AhaSend API availability"),!!(await f(`${r.endpoint}/v2/ping`,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"GET",timeout:r.timeout})).success}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=q(e);if(o.length>0)return{error:new c(s,`Invalid email options: ${o.join(", ")}`),success:!1};await this.initialize();const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=B(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const a=E(e.headers);t.headers=a}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async a=>{let d;if(a.content)if(typeof a.content=="string")d=a.content;else if(a.content instanceof Promise){const A=await a.content;d=j.from(A).toString("base64")}else d=a.content.toString("base64");else if(a.raw)d=typeof a.raw=="string"?a.raw:a.raw.toString("base64");else throw new c(s,`Attachment ${a.filename} has no content`);return{content:d,contentType:a.contentType||"application/octet-stream",filename:a.filename,...a.cid&&{cid:a.cid}}}))),n.debug("Sending email via AhaSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},l=await b(async()=>f(`${r.endpoint}/send`,{headers:v,method:"POST",timeout:r.timeout},JSON.stringify(t)),r.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error||new c(s,"Failed to send email"),success:!1};const g=l.data?.body,h=g?.messageId||g?.id||_();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(s,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
1
|
+
var L=Object.defineProperty;var M=(m,a)=>L(m,"name",{value:a,configurable:!0});import{createRequire as V}from"node:module";import T from"./EmailError-zm2ffVav.js";import Q from"./RequiredOptionError-CevW3u2K.js";import{c as X}from"./create-logger-BiWdqFNg.js";import S from"../utils/format-email-address.js";import{i as J}from"./headers-to-record-Qo124ImV.js";import{m as Y}from"./make-request-BDzF9W9D.js";import{s as P,a as Z}from"./sanitize-header-wWav-Scu.js";import{d as ee}from"./validate-email-options-DfJ7llf8.js";import{defineProvider as te}from"./defineProvider-B9rSklAJ.js";const F=V(import.meta.url),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=M(m=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[a,d]=$.versions.node.split(".").map(Number);if(a>22||a===22&&d>=3||a===20&&d>=16)return $.getBuiltinModule(m)}return F(m)},"__cjs_getBuiltinModule"),{randomUUID:q,createHash:k,createHmac:w}=G("node:crypto");var re=Object.defineProperty,f=M((m,a)=>re(m,"name",{value:a,configurable:!0}),"m");const se=globalThis.Buffer!==void 0,j=f(()=>{if(!se)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},"getBuffer"),y="aws-ses",C={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},fe=te((m={})=>{const a={...C,...m},d=X("AWS-SES",m.logger),W=f((e,i,t,s,n)=>{const u=Object.keys(t).toSorted().map(c=>{const l=t[c];return l===void 0?"":`${encodeURIComponent(c)}=${encodeURIComponent(l)}`}).filter(Boolean).join("&"),r=`${Object.keys(s).toSorted().map(c=>`${c.toLowerCase()}:${s[c]}`).join(`
|
|
2
2
|
`)}
|
|
3
|
-
`,o=Object.keys(s).toSorted().map(c=>c.toLowerCase()).join(";"),g=k("sha256").update(
|
|
4
|
-
`)},"createCanonicalRequest"),_=f((e,i,t)=>{const s=e.slice(0,8),
|
|
5
|
-
`)},"createStringToSign"),K=f((e,i,t,s)=>{const
|
|
3
|
+
`,o=Object.keys(s).toSorted().map(c=>c.toLowerCase()).join(";"),g=k("sha256").update(n).digest("hex");return[e,i,u,r,o,g].join(`
|
|
4
|
+
`)},"createCanonicalRequest"),_=f((e,i,t)=>{const s=e.slice(0,8),n=k("sha256").update(t).digest("hex");return["AWS4-HMAC-SHA256",e,`${s}/${i}/ses/aws4_request`,n].join(`
|
|
5
|
+
`)},"createStringToSign"),K=f((e,i,t,s)=>{const n=i.slice(0,8),u=w("sha256",`AWS4${e}`).update(n).digest(),r=w("sha256",u).update(t).digest(),o=w("sha256",r).update("ses").digest(),g=w("sha256",o).update("aws4_request").digest();return w("sha256",g).update(s).digest("hex")},"calculateSignature"),O=f((e,i,t,s,n)=>{const u=i.slice(0,8),r=Object.keys(s).toSorted().map(o=>o.toLowerCase()).join(";");return[`AWS4-HMAC-SHA256 Credential=${e}/${u}/${t}/ses/aws4_request`,`SignedHeaders=${r}`,`Signature=${n}`].join(", ")},"createAuthHeader"),v=f(async(e,i)=>{if(!a.accessKeyId||!a.secretAccessKey)throw d.debug("Missing required credentials: accessKeyId or secretAccessKey"),new Q(y,["accessKeyId","secretAccessKey"]);try{const t=a.region||C.region,s=a.apiVersion||C.apiVersion,n=a.endpoint||`email.${t}.amazonaws.com`,u="/",r="POST";d.debug("Making request to AWS SES:",{action:e,host:n,region:t});const o=new URLSearchParams;o.append("Action",e),o.append("Version",s),Object.entries(i).forEach(([h,p])=>{p!=null&&o.append(h,String(p))});const g=o.toString();d.debug("Request body:",g);const c=new Date().toISOString().replaceAll(/[:-]|\.\d{3}/g,""),l={"Content-Length":j().byteLength(g).toString(),"Content-Type":"application/x-www-form-urlencoded",Host:n,"X-Amz-Date":c};a.sessionToken&&(l["X-Amz-Security-Token"]=a.sessionToken),d.debug("Request headers:",l);const A=W(r,u,{},l,g),B=_(c,t,A),z=K(a.secretAccessKey,c,t,B);l.Authorization=O(a.accessKeyId,c,t,l,z),d.debug("Making HTTPS request to:",`https://${n}${u}`);const D=`https://${n}${u}`,E=await Y(D,{headers:l,method:r},g);if(!E.success)throw E.error||new Error("AWS SES API request failed");const b=E.data?.body;if(!b)throw new Error("No response body from AWS SES");const H=E.data?.statusCode;d.debug("Response status:",H),d.debug("Response data:",b);const I=H;if(I&&I>=200&&I<300){const h={};if(e==="SendRawEmail"){const p=b.match(/<MessageId>(.*?)<\/MessageId>/);if(p){const[,N]=p;h.MessageId=N,d.debug("Extracted MessageId:",h.MessageId)}}else if(e==="GetSendQuota"){const p=b.match(/<Max24HourSend>(.*?)<\/Max24HourSend>/);p&&p[1]&&(h.Max24HourSend=Number.parseFloat(p[1]),d.debug("Extracted Max24HourSend:",h.Max24HourSend))}return h}const x=b.match(/<Message>(.*?)<\/Message>/),R=x?x[1]:"Unknown AWS SES error";throw d.debug("AWS SES Error:",R),new Error(`AWS SES API Error: ${R}`)}catch(t){const s=t instanceof Error?t.message:String(t);throw d.debug("makeAwsRequest exception:",s),t instanceof Error?t:new Error(s)}},"makeAwsRequest"),U=f(e=>{const i=`----=${q().replaceAll("-","")}`,t=new Date().toUTCString(),s=e.from.email.includes("@")?e.from.email.split("@")[1]:"localhost",n=`<${q().replaceAll("-","")}@${s}>`,u=j();let r="";if(r+=`From: ${S(e.from)}\r
|
|
6
6
|
`,r+=Array.isArray(e.to)?`To: ${e.to.map(o=>S(o)).join(", ")}\r
|
|
7
7
|
`:`To: ${S(e.to)}\r
|
|
8
8
|
`,e.cc&&(r+=Array.isArray(e.cc)?`Cc: ${e.cc.map(o=>S(o)).join(", ")}\r
|
|
@@ -11,7 +11,7 @@ var V=Object.defineProperty;var M=(m,n)=>V(m,"name",{value:n,configurable:!0});i
|
|
|
11
11
|
`:`Bcc: ${S(e.bcc)}\r
|
|
12
12
|
`),r+=`Subject: ${P(e.subject)}\r
|
|
13
13
|
`,r+=`Date: ${t}\r
|
|
14
|
-
`,r+=`Message-ID: ${
|
|
14
|
+
`,r+=`Message-ID: ${n}\r
|
|
15
15
|
`,r+=`MIME-Version: 1.0\r
|
|
16
16
|
`,e.headers){const o=J(e.headers);for(const[g,c]of Object.entries(o)){const l=Z(g),A=P(c);r+=`${l}: ${A}\r
|
|
17
17
|
`}}return r+=`Content-Type: multipart/alternative; boundary="${i}"\r
|
|
@@ -29,4 +29,4 @@ var V=Object.defineProperty;var M=(m,n)=>V(m,"name",{value:n,configurable:!0});i
|
|
|
29
29
|
`,r+=`${u.from(e.html,"utf8").toString("base64")}\r
|
|
30
30
|
\r
|
|
31
31
|
`),r+=`--${i}--\r
|
|
32
|
-
`,r},"generateMimeMessage");return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},getInstance:f(()=>{},"getInstance"),initialize(){d.debug("Initializing AWS SES provider with options:",{accessKeyId:
|
|
32
|
+
`,r},"generateMimeMessage");return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},getInstance:f(()=>{},"getInstance"),initialize(){d.debug("Initializing AWS SES provider with options:",{accessKeyId:a.accessKeyId?`***${a.accessKeyId.slice(-4)}`:void 0,endpoint:a.endpoint,region:a.region,secretAccessKey:a.secretAccessKey?"***":void 0})},async isAvailable(){try{return!!(await v("GetSendQuota",{})).Max24HourSend}catch{return!1}},name:y,options:a,async sendEmail(e){const i=f(t=>{const s=[];return t.attachments&&t.attachments.length>0&&s.push("attachments"),t.priority&&s.push("priority"),t.tags&&t.tags.length>0&&s.push("tags (use messageTags instead)"),t.replyTo&&s.push("replyTo"),s},"checkUnsupportedFields");try{const t=ee(e);if(t.length>0)throw new T(y,`Invalid email options: ${t.join(", ")}`);const s=i(e);if(s.length>0)throw new T(y,`Unsupported fields provided: ${s.join(", ")}. These fields are not supported by AWS SES Raw Email API and would be silently ignored.`);const n={};e.configurationSetName&&(n.ConfigurationSetName=e.configurationSetName),e.sourceArn&&(n.SourceArn=e.sourceArn),e.returnPath&&(n.ReturnPath=e.returnPath),e.returnPathArn&&(n.ReturnPathArn=e.returnPathArn),e.messageTags&&Object.keys(e.messageTags).length>0&&Object.entries(e.messageTags).forEach(([c,l],A)=>{n[`Tags.member.${A+1}.Name`]=c,n[`Tags.member.${A+1}.Value`]=l});const u=U(e),r=j().from(u).toString("base64");n["RawMessage.Data"]=r;const o=await v("SendRawEmail",n),g=o.MessageId;return!g||g.trim()===""?{error:new T(y,"AWS SES API returned a response without a MessageId. The email may not have been sent successfully."),success:!1}:{data:{messageId:g,provider:y,response:o,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new T(y,`Failed to send email: ${t instanceof Error?t.message:String(t)}`,{cause:t instanceof Error?t:new Error(String(t))}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{fe as default};
|