@visulima/email 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +246 -0
- package/LICENSE.md +536 -899
- package/README.md +36 -21
- package/dist/crypto/index.d.ts +147 -4
- package/dist/crypto/index.js +1 -1
- package/dist/index.d.ts +785 -9
- package/dist/index.js +1 -1
- package/dist/packem_shared/{DkimSigner-pFd4c3fZ.js → DkimSigner-CT2DSHD1.js} +4 -4
- package/dist/packem_shared/Mail-D93oo_9g.js +1 -0
- package/dist/packem_shared/MailMessage-BvaH5tZZ.js +1 -0
- package/dist/packem_shared/{SmimeEncrypter-CBevU534.js → SmimeEncrypter-ZhHEgDwY.js} +2 -2
- package/dist/packem_shared/{SmimeSigner-CObA4jzT.js → SmimeSigner-CYSVF6ez.js} +1 -1
- package/dist/packem_shared/{ahaSendProvider-DlFKEQ6D.js → ahaSendProvider-DOAAW65O.js} +1 -1
- package/dist/packem_shared/{attachment-processor-2rHmfa7j.js → attachment-processor-DsmIomKc.js} +1 -1
- package/dist/packem_shared/{awsSesProvider-Ba-eVJxZ.js → awsSesProvider-DX1630Ms.js} +7 -7
- package/dist/packem_shared/azureProvider-EkNYKAiF.js +1 -0
- package/dist/packem_shared/{brevoProvider-5p6jjiK9.js → brevoProvider-CkR4U4RD.js} +1 -1
- package/dist/packem_shared/build-mime-message-6xstxaUV.js +2 -0
- package/dist/packem_shared/defineProvider-CtLH0VBE.js +1 -0
- package/dist/packem_shared/detectMimeType-bo5oxfnt.js +1 -0
- package/dist/packem_shared/failoverProvider-W5ctAhdC.js +1 -0
- package/dist/packem_shared/httpProvider-DUg1AQfO.js +1 -0
- package/dist/packem_shared/{infobipProvider-CtLwrUaP.js → infobipProvider-BhTsWi7e.js} +1 -1
- package/dist/packem_shared/{mailCrabProvider-CM_CFDca.js → mailCrabProvider-B7H6HwWu.js} +1 -1
- package/dist/packem_shared/mailPaceProvider-DRt6Z9Hr.js +1 -0
- package/dist/packem_shared/{mailerSendProvider-CeeIXFnW.js → mailerSendProvider-Dx_iHInH.js} +1 -1
- package/dist/packem_shared/mailgunProvider-ChkLGZZW.js +1 -0
- package/dist/packem_shared/mailjetProvider-BMRhNe6H.js +1 -0
- package/dist/packem_shared/{mailomatProvider-DMQmjKHT.js → mailomatProvider-CydV-JB6.js} +1 -1
- package/dist/packem_shared/{mailtrapProvider-BN3UBEQw.js → mailtrapProvider-CuAfJWDr.js} +1 -1
- package/dist/packem_shared/{make-request-BDzF9W9D.js → make-request-CaT4d5oC.js} +1 -1
- package/dist/packem_shared/{mandrillProvider-370y7CLu.js → mandrillProvider-BBeLbaw0.js} +1 -1
- package/dist/packem_shared/mockProvider-C0P1lKOy.js +1 -0
- package/dist/packem_shared/{nodemailerProvider-_w8QXMU-.js → nodemailerProvider-DFcvoVFv.js} +1 -1
- package/dist/packem_shared/{opentelemetryProvider-C_ZXOLSd.js → opentelemetryProvider-Dwv88G3O.js} +1 -1
- package/dist/packem_shared/{plunkProvider-DfJumQ4U.js → plunkProvider-BQyjG6YT.js} +1 -1
- package/dist/packem_shared/{postalProvider-Bavx2FcH.js → postalProvider-DPHQ620q.js} +1 -1
- package/dist/packem_shared/{postmarkProvider-DFC0uvjO.js → postmarkProvider-bMTC2gdJ.js} +1 -1
- package/dist/packem_shared/provider.d-DcfYeGJJ.d.ts +28 -0
- package/dist/packem_shared/readFile-BAVMZg5e-C4whBIPd.js +1 -0
- package/dist/packem_shared/resendProvider-Cns1tvF5.js +1 -0
- package/dist/packem_shared/roundRobinProvider-FvZQKl6n.js +1 -0
- package/dist/packem_shared/{scalewayProvider-be1HPimL.js → scalewayProvider-O1dHz7iJ.js} +1 -1
- package/dist/packem_shared/{sendGridProvider-BVI1sq3n.js → sendGridProvider-DmywC-eT.js} +1 -1
- package/dist/packem_shared/{smtpProvider-BV-ufR53.js → smtpProvider-Unjao_fn.js} +8 -8
- package/dist/packem_shared/sweegoProvider-D086G6xG.js +1 -0
- package/dist/packem_shared/types.d-CNnnk-Ya.d.ts +102 -0
- package/dist/packem_shared/types.d-nyR1ty1Q.d.ts +9 -0
- package/dist/packem_shared/types.d-wwpgA3to.d.ts +204 -0
- package/dist/packem_shared/validate-email-options-DPo3SgC0.js +1 -0
- package/dist/packem_shared/zeptomailProvider-DKKEpEsW.js +1 -0
- package/dist/providers/ahasend/index.d.ts +36 -3
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/aws-ses/index.d.ts +47 -3
- package/dist/providers/aws-ses/index.js +1 -1
- package/dist/providers/azure/index.d.ts +52 -3
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.d.ts +65 -3
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/failover/index.d.ts +27 -3
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/http/index.d.ts +35 -3
- package/dist/providers/http/index.js +1 -1
- package/dist/providers/infobip/index.d.ts +56 -3
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/mailcrab/index.d.ts +32 -3
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.d.ts +51 -3
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.d.ts +73 -3
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.d.ts +72 -3
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.d.ts +40 -3
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.d.ts +52 -3
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.d.ts +44 -3
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.d.ts +87 -3
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/mock/index.d.ts +59 -3
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/nodemailer/index.d.ts +38 -3
- package/dist/providers/nodemailer/index.js +1 -1
- package/dist/providers/opentelemetry/index.d.ts +529 -3
- package/dist/providers/opentelemetry/index.js +1 -1
- package/dist/providers/plunk/index.d.ts +38 -3
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.d.ts +48 -3
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.d.ts +60 -3
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.d.ts +51 -3
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/roundrobin/index.d.ts +27 -3
- package/dist/providers/roundrobin/index.js +1 -1
- package/dist/providers/scaleway/index.d.ts +44 -3
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.d.ts +84 -3
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.d.ts +71 -3
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sweego/index.d.ts +40 -3
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.d.ts +37 -3
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/template-engines/handlebars.d.ts +23 -22
- package/dist/template-engines/handlebars.js +1 -1
- package/dist/template-engines/html-to-text.d.ts +24 -24
- package/dist/template-engines/mjml.d.ts +10 -10
- package/dist/template-engines/react-email.d.ts +9 -9
- package/dist/template-engines/vue-email.d.ts +9 -9
- package/dist/utils/cache.d.ts +49 -48
- package/dist/utils/format-email-address.d.ts +8 -7
- package/dist/utils/normalize-email-aliases.d.ts +20 -20
- package/dist/utils/parse-address.d.ts +18 -17
- package/dist/utils/parse-address.js +1 -1
- package/dist/utils/validation/check-mx-records.d.ts +36 -35
- package/dist/utils/validation/disposable-email-domains.d.ts +1 -13
- package/dist/utils/validation/role-accounts.d.ts +18 -18
- package/dist/utils/validation/validate-email.d.ts +5 -5
- package/dist/utils/validation/verify-email.d.ts +45 -42
- package/dist/utils/validation/verify-email.js +1 -1
- package/dist/utils/validation/verify-smtp.d.ts +35 -34
- package/dist/utils/validation/verify-smtp.js +1 -1
- package/package.json +61 -61
- package/dist/attachment-helpers.d.ts +0 -64
- package/dist/crypto/dkim-signer.d.ts +0 -48
- package/dist/crypto/smime-encrypter.d.ts +0 -53
- package/dist/crypto/smime-signer.d.ts +0 -48
- package/dist/crypto/types.d.ts +0 -101
- package/dist/draft-mail-message.d.ts +0 -13
- package/dist/errors/email-error.d.ts +0 -17
- package/dist/errors/required-option-error.d.ts +0 -10
- package/dist/mail-message.d.ts +0 -425
- package/dist/mail.d.ts +0 -206
- package/dist/packem_shared/Mail-6Bltpy_p.js +0 -1
- package/dist/packem_shared/MailMessage-B76GPBBA.js +0 -1
- package/dist/packem_shared/azureProvider-CQYAkgVF.js +0 -1
- package/dist/packem_shared/build-mime-message-IYaUqqPJ.js +0 -2
- package/dist/packem_shared/defineProvider-B9rSklAJ.js +0 -1
- package/dist/packem_shared/detectMimeType-S8WRsNtY.js +0 -1
- package/dist/packem_shared/failoverProvider-CAHQQueo.js +0 -1
- package/dist/packem_shared/httpProvider-CZD6LZX3.js +0 -1
- package/dist/packem_shared/mailPaceProvider-B6yKvh6z.js +0 -1
- package/dist/packem_shared/mailgunProvider-mmjKzouh.js +0 -1
- package/dist/packem_shared/mailjetProvider-DwN6i0VA.js +0 -1
- package/dist/packem_shared/mockProvider-DN5ZwutD.js +0 -1
- package/dist/packem_shared/readFile-BlZxbhCU-C8bCdiA2.js +0 -1
- package/dist/packem_shared/resendProvider-CfqU7UdE.js +0 -1
- package/dist/packem_shared/roundRobinProvider-1WQnuKR8.js +0 -1
- package/dist/packem_shared/sweegoProvider-7419CSAq.js +0 -1
- package/dist/packem_shared/validate-email-options-DfJ7llf8.js +0 -1
- package/dist/packem_shared/zeptomailProvider-C2lh0Xmo.js +0 -1
- package/dist/providers/ahasend/provider.d.ts +0 -7
- package/dist/providers/ahasend/types.d.ts +0 -28
- package/dist/providers/aws-ses/provider.d.ts +0 -8
- package/dist/providers/aws-ses/types.d.ts +0 -38
- package/dist/providers/azure/provider.d.ts +0 -7
- package/dist/providers/azure/types.d.ts +0 -44
- package/dist/providers/brevo/provider.d.ts +0 -7
- package/dist/providers/brevo/types.d.ts +0 -57
- package/dist/providers/failover/provider.d.ts +0 -7
- package/dist/providers/failover/types.d.ts +0 -19
- package/dist/providers/http/provider.d.ts +0 -7
- package/dist/providers/http/types.d.ts +0 -27
- package/dist/providers/infobip/provider.d.ts +0 -7
- package/dist/providers/infobip/types.d.ts +0 -48
- package/dist/providers/mailcrab/provider.d.ts +0 -9
- package/dist/providers/mailcrab/types.d.ts +0 -22
- package/dist/providers/mailersend/provider.d.ts +0 -7
- package/dist/providers/mailersend/types.d.ts +0 -43
- package/dist/providers/mailgun/provider.d.ts +0 -7
- package/dist/providers/mailgun/types.d.ts +0 -65
- package/dist/providers/mailjet/provider.d.ts +0 -7
- package/dist/providers/mailjet/types.d.ts +0 -64
- package/dist/providers/mailomat/provider.d.ts +0 -7
- package/dist/providers/mailomat/types.d.ts +0 -32
- package/dist/providers/mailpace/provider.d.ts +0 -7
- package/dist/providers/mailpace/types.d.ts +0 -44
- package/dist/providers/mailtrap/provider.d.ts +0 -7
- package/dist/providers/mailtrap/types.d.ts +0 -36
- package/dist/providers/mandrill/provider.d.ts +0 -7
- package/dist/providers/mandrill/types.d.ts +0 -79
- package/dist/providers/mock/provider.d.ts +0 -8
- package/dist/providers/mock/types.d.ts +0 -50
- package/dist/providers/nodemailer/provider.d.ts +0 -7
- package/dist/providers/nodemailer/types.d.ts +0 -30
- package/dist/providers/opentelemetry/provider.d.ts +0 -8
- package/dist/providers/opentelemetry/types.d.ts +0 -31
- package/dist/providers/plunk/provider.d.ts +0 -7
- package/dist/providers/plunk/types.d.ts +0 -30
- package/dist/providers/postal/provider.d.ts +0 -7
- package/dist/providers/postal/types.d.ts +0 -40
- package/dist/providers/postmark/provider.d.ts +0 -7
- package/dist/providers/postmark/types.d.ts +0 -52
- package/dist/providers/provider.d.ts +0 -27
- package/dist/providers/resend/provider.d.ts +0 -7
- package/dist/providers/resend/types.d.ts +0 -43
- package/dist/providers/roundrobin/provider.d.ts +0 -7
- package/dist/providers/roundrobin/types.d.ts +0 -19
- package/dist/providers/scaleway/provider.d.ts +0 -7
- package/dist/providers/scaleway/types.d.ts +0 -36
- package/dist/providers/sendgrid/provider.d.ts +0 -7
- package/dist/providers/sendgrid/types.d.ts +0 -76
- package/dist/providers/smtp/provider.d.ts +0 -7
- package/dist/providers/smtp/types.d.ts +0 -63
- package/dist/providers/sweego/provider.d.ts +0 -7
- package/dist/providers/sweego/types.d.ts +0 -32
- package/dist/providers/utils/address-formatter.d.ts +0 -139
- package/dist/providers/utils/attachment-processor.d.ts +0 -58
- package/dist/providers/utils/index.d.ts +0 -4
- package/dist/providers/utils/payload-builder.d.ts +0 -78
- package/dist/providers/utils/provider-base.d.ts +0 -69
- package/dist/providers/zeptomail/provider.d.ts +0 -7
- package/dist/providers/zeptomail/types.d.ts +0 -29
- package/dist/template-engines/types.d.ts +0 -8
- package/dist/types.d.ts +0 -203
- package/dist/utils/build-mime-message.d.ts +0 -8
- package/dist/utils/create-logger.d.ts +0 -16
- package/dist/utils/format-email-addresses.d.ts +0 -8
- package/dist/utils/generate-boundary.d.ts +0 -7
- package/dist/utils/generate-message-id.d.ts +0 -6
- package/dist/utils/headers-to-record.d.ts +0 -9
- package/dist/utils/is-port-available.d.ts +0 -9
- package/dist/utils/make-request.d.ts +0 -18
- package/dist/utils/retry.d.ts +0 -10
- package/dist/utils/sanitize-header.d.ts +0 -14
- package/dist/utils/to-base64.d.ts +0 -8
- package/dist/utils/validation/validate-email-options.d.ts +0 -8
package/dist/mail-message.d.ts
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import type { ICalCalendar } from "ical-generator";
|
|
2
|
-
import type { AttachmentDataOptions, AttachmentOptions } from './attachment-helpers.d.ts';
|
|
3
|
-
import type { EmailEncrypter, EmailSigner } from './crypto/index.d.ts';
|
|
4
|
-
import type { TemplateRenderer } from './template-engines/types.d.ts';
|
|
5
|
-
import type { Attachment, CalendarEventOptions, EmailAddress, EmailHeaders, EmailOptions, Priority } from './types.d.ts';
|
|
6
|
-
type AddressInput = EmailAddress | EmailAddress[] | string | string[];
|
|
7
|
-
/**
|
|
8
|
-
* Mail message builder - provides fluent interface for building emails.
|
|
9
|
-
*/
|
|
10
|
-
export declare class MailMessage {
|
|
11
|
-
private fromAddress?;
|
|
12
|
-
private toAddresses;
|
|
13
|
-
private ccAddresses;
|
|
14
|
-
private bccAddresses;
|
|
15
|
-
private subjectText;
|
|
16
|
-
private textContent?;
|
|
17
|
-
private textCharset;
|
|
18
|
-
private autoTextEnabled;
|
|
19
|
-
private htmlContent?;
|
|
20
|
-
private htmlCharset;
|
|
21
|
-
private dateValue?;
|
|
22
|
-
private returnPathAddress?;
|
|
23
|
-
private senderAddress?;
|
|
24
|
-
private headers;
|
|
25
|
-
private attachments;
|
|
26
|
-
private replyToAddress?;
|
|
27
|
-
private priorityValue?;
|
|
28
|
-
private tagsValue;
|
|
29
|
-
private signer?;
|
|
30
|
-
private encrypter?;
|
|
31
|
-
private logger?;
|
|
32
|
-
private icalEventData?;
|
|
33
|
-
/**
|
|
34
|
-
* Sets the sender address.
|
|
35
|
-
* @param address The sender email address (string or EmailAddress object).
|
|
36
|
-
* @returns This instance for method chaining.
|
|
37
|
-
*/
|
|
38
|
-
from(address: EmailAddress | string): this;
|
|
39
|
-
/**
|
|
40
|
-
* Sets the recipient address(es).
|
|
41
|
-
* @param address The recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
42
|
-
* @returns This instance for method chaining.
|
|
43
|
-
*/
|
|
44
|
-
to(address: AddressInput): this;
|
|
45
|
-
/**
|
|
46
|
-
* Sets the CC recipient address(es).
|
|
47
|
-
* @param address The CC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
48
|
-
* @returns This instance for method chaining.
|
|
49
|
-
*/
|
|
50
|
-
cc(address: AddressInput): this;
|
|
51
|
-
/**
|
|
52
|
-
* Sets the BCC recipient address(es).
|
|
53
|
-
* @param address The BCC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
54
|
-
* @returns This instance for method chaining.
|
|
55
|
-
*/
|
|
56
|
-
bcc(address: AddressInput): this;
|
|
57
|
-
/**
|
|
58
|
-
* Sets the subject line for the email message.
|
|
59
|
-
* @param text The subject text to set.
|
|
60
|
-
* @returns This instance for method chaining.
|
|
61
|
-
*/
|
|
62
|
-
subject(text: string): this;
|
|
63
|
-
/**
|
|
64
|
-
* Sets the plain text content of the email.
|
|
65
|
-
* @param content The plain text content to set.
|
|
66
|
-
* @param charset Optional charset for the text content (default: 'utf8').
|
|
67
|
-
* @returns This instance for method chaining.
|
|
68
|
-
*/
|
|
69
|
-
text(content: string, charset?: string): this;
|
|
70
|
-
/**
|
|
71
|
-
* Sets the HTML content of the email.
|
|
72
|
-
* @param content The HTML content to set.
|
|
73
|
-
* @param charset Optional charset for the HTML content (default: 'utf8').
|
|
74
|
-
* @returns This instance for method chaining.
|
|
75
|
-
*/
|
|
76
|
-
html(content: string, charset?: string): this;
|
|
77
|
-
/**
|
|
78
|
-
* Sets a custom email header.
|
|
79
|
-
* @param name The header name to set.
|
|
80
|
-
* @param value The header value to set.
|
|
81
|
-
* @returns This instance for method chaining.
|
|
82
|
-
*/
|
|
83
|
-
header(name: string, value: string): this;
|
|
84
|
-
/**
|
|
85
|
-
* Sets multiple headers.
|
|
86
|
-
* Accepts both Record<string, string> and ImmutableHeaders.
|
|
87
|
-
* @param headers The headers to set (Record or ImmutableHeaders).
|
|
88
|
-
* @returns This instance for method chaining.
|
|
89
|
-
*/
|
|
90
|
-
setHeaders(headers: EmailHeaders): this;
|
|
91
|
-
/**
|
|
92
|
-
* Attaches a file from path (reads file from filesystem).
|
|
93
|
-
* Similar to Laravel's attach() method.
|
|
94
|
-
* @param filePath The absolute or relative filesystem path to the file to attach.
|
|
95
|
-
* @param options Optional attachment configuration (filename, contentType, etc.).
|
|
96
|
-
* @returns This instance for method chaining.
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* message.attachFromPath('/path/to/file.pdf')
|
|
100
|
-
* message.attachFromPath('/path/to/file.pdf', { filename: 'custom-name.pdf' })
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
attachFromPath(filePath: string, options?: AttachmentOptions): Promise<this>;
|
|
104
|
-
/**
|
|
105
|
-
* Attaches raw data (string or Buffer).
|
|
106
|
-
* Similar to Laravel's attachData() method.
|
|
107
|
-
* @param content The content to attach (string or Buffer).
|
|
108
|
-
* @param options Attachment options including filename.
|
|
109
|
-
* @returns This instance for method chaining.
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* message.attachData(Buffer.from('content'), 'file.txt')
|
|
113
|
-
* message.attachData('content', 'file.txt', { contentType: 'text/plain' })
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
attachData(content: string | Buffer, options: AttachmentDataOptions): this;
|
|
117
|
-
/**
|
|
118
|
-
* Embeds an inline attachment from file path (for images in HTML).
|
|
119
|
-
* Similar to Laravel's embed() method.
|
|
120
|
-
* Returns the Content-ID that can be used in HTML: <img src="cid:{cid}">.
|
|
121
|
-
* @param filePath The path to the file to embed.
|
|
122
|
-
* @param options Optional attachment options (filename, contentType, etc.).
|
|
123
|
-
* @returns The Content-ID string that can be used in HTML.
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* const cid = await message.embedFromPath('/path/to/logo.png')
|
|
127
|
-
* message.html(`<img src="cid:${cid}">`)
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
embedFromPath(filePath: string, options?: Omit<AttachmentOptions, "contentDisposition" | "cid">): Promise<string>;
|
|
131
|
-
/**
|
|
132
|
-
* Embeds raw data as inline attachment (for images in HTML).
|
|
133
|
-
* Similar to Laravel's embedData() method.
|
|
134
|
-
* Returns the Content-ID that can be used in HTML: <img src="cid:{cid}">.
|
|
135
|
-
* @param content The content to embed (string or Buffer).
|
|
136
|
-
* @param filename The filename for the embedded attachment.
|
|
137
|
-
* @param options Optional attachment options (contentType, etc.).
|
|
138
|
-
* @returns The Content-ID string that can be used in HTML.
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* const imageBuffer = Buffer.from('...')
|
|
142
|
-
* const cid = message.embedData(imageBuffer, 'logo.png', { contentType: 'image/png' })
|
|
143
|
-
* message.html(`<img src="cid:${cid}">`)
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
embedData(content: string | Buffer, filename: string, options?: Omit<AttachmentDataOptions, "filename" | "contentDisposition" | "cid">): string;
|
|
147
|
-
/**
|
|
148
|
-
* Sets the reply-to address.
|
|
149
|
-
* @param address The reply-to email address (string or EmailAddress object).
|
|
150
|
-
* @returns This instance for method chaining.
|
|
151
|
-
*/
|
|
152
|
-
replyTo(address: EmailAddress | string): this;
|
|
153
|
-
/**
|
|
154
|
-
* Sets the date header for the email.
|
|
155
|
-
* @param date The date to set (Date object or ISO string).
|
|
156
|
-
* @returns This instance for method chaining.
|
|
157
|
-
*/
|
|
158
|
-
date(date: Date | string): this;
|
|
159
|
-
/**
|
|
160
|
-
* Sets the return-path address (bounce address).
|
|
161
|
-
* @param address The return-path email address (string or EmailAddress object).
|
|
162
|
-
* @returns This instance for method chaining.
|
|
163
|
-
*/
|
|
164
|
-
returnPath(address: EmailAddress | string): this;
|
|
165
|
-
/**
|
|
166
|
-
* Sets the sender address (different from From - used when From contains multiple addresses).
|
|
167
|
-
* @param address The sender email address (string or EmailAddress object).
|
|
168
|
-
* @returns This instance for method chaining.
|
|
169
|
-
*/
|
|
170
|
-
sender(address: EmailAddress | string): this;
|
|
171
|
-
/**
|
|
172
|
-
* Adds recipient address(es) without replacing existing ones.
|
|
173
|
-
* @param address The recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
174
|
-
* @returns This instance for method chaining.
|
|
175
|
-
*/
|
|
176
|
-
addTo(address: AddressInput): this;
|
|
177
|
-
/**
|
|
178
|
-
* Adds CC recipient address(es) without replacing existing ones.
|
|
179
|
-
* @param address The CC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
180
|
-
* @returns This instance for method chaining.
|
|
181
|
-
*/
|
|
182
|
-
addCc(address: AddressInput): this;
|
|
183
|
-
/**
|
|
184
|
-
* Adds BCC recipient address(es) without replacing existing ones.
|
|
185
|
-
* @param address The BCC recipient email address(es) (string, EmailAddress, or arrays of either).
|
|
186
|
-
* @returns This instance for method chaining.
|
|
187
|
-
*/
|
|
188
|
-
addBcc(address: AddressInput): this;
|
|
189
|
-
/**
|
|
190
|
-
* Adds reply-to address(es) without replacing existing ones.
|
|
191
|
-
* @param address The reply-to email address(es) (string, EmailAddress, or arrays of either).
|
|
192
|
-
* @returns This instance for method chaining.
|
|
193
|
-
*/
|
|
194
|
-
addReplyTo(address: EmailAddress | string | (EmailAddress | string)[]): this;
|
|
195
|
-
/**
|
|
196
|
-
* Adds from address(es) without replacing existing ones.
|
|
197
|
-
* @param address The sender email address(es) (string, EmailAddress, or arrays of either).
|
|
198
|
-
* @returns This instance for method chaining.
|
|
199
|
-
*/
|
|
200
|
-
addFrom(address: EmailAddress | string | (EmailAddress | string)[]): this;
|
|
201
|
-
/**
|
|
202
|
-
* Sets the email priority.
|
|
203
|
-
* @param priority The priority level ('high', 'normal', or 'low').
|
|
204
|
-
* @returns This instance for method chaining.
|
|
205
|
-
*/
|
|
206
|
-
priority(priority: Priority): this;
|
|
207
|
-
/**
|
|
208
|
-
* Sets email tags for categorization.
|
|
209
|
-
* @param tags The tags to set (string or array of strings).
|
|
210
|
-
* @returns This instance for method chaining.
|
|
211
|
-
*/
|
|
212
|
-
tags(tags: string | string[]): this;
|
|
213
|
-
/**
|
|
214
|
-
* Signs the email message using a signer (DKIM or S/MIME).
|
|
215
|
-
* @param signer The signer instance to use.
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* import { createDkimSigner } from '@visulima/email/crypto';
|
|
219
|
-
* const signer = createDkimSigner({
|
|
220
|
-
* domainName: 'example.com',
|
|
221
|
-
* keySelector: 'default',
|
|
222
|
-
* privateKey: '-----BEGIN PRIVATE KEY-----...'
|
|
223
|
-
* });
|
|
224
|
-
* message.sign(signer)
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
sign(signer: EmailSigner): this;
|
|
228
|
-
/**
|
|
229
|
-
* Encrypts the email message using an encrypter (S/MIME).
|
|
230
|
-
* @param encrypter The encrypter instance to use.
|
|
231
|
-
* @example
|
|
232
|
-
* ```ts
|
|
233
|
-
* import { createSmimeEncrypter } from '@visulima/email/crypto';
|
|
234
|
-
* const encrypter = createSmimeEncrypter({
|
|
235
|
-
* certificates: '/path/to/certificate.crt'
|
|
236
|
-
* });
|
|
237
|
-
* message.encrypt(encrypter)
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
encrypt(encrypter: EmailEncrypter): this;
|
|
241
|
-
/**
|
|
242
|
-
* Sets the logger instance for this message.
|
|
243
|
-
* @param logger The logger instance (Console) to use for logging.
|
|
244
|
-
* @returns This instance for method chaining.
|
|
245
|
-
* @example
|
|
246
|
-
* ```ts
|
|
247
|
-
* message.logger(console)
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
setLogger(logger: Console): this;
|
|
251
|
-
/**
|
|
252
|
-
* Attach a calendar event and define contents as string or function.
|
|
253
|
-
* @param contents The calendar content as a string or a function that receives an ICalCalendar instance.
|
|
254
|
-
* @param options Optional calendar event options (method, alternativeText).
|
|
255
|
-
* @returns This instance for method chaining.
|
|
256
|
-
* @example
|
|
257
|
-
* ```ts
|
|
258
|
-
* message.icalEvent((calendar) => {
|
|
259
|
-
* calendar.createEvent({
|
|
260
|
-
* start: new Date(),
|
|
261
|
-
* summary: 'Meeting'
|
|
262
|
-
* });
|
|
263
|
-
* })
|
|
264
|
-
* message.icalEvent('BEGIN:VCALENDAR...')
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
|
-
icalEvent(contents: ((calendar: ICalCalendar) => void) | string, options?: CalendarEventOptions): this;
|
|
268
|
-
/**
|
|
269
|
-
* Attach a calendar event and load contents from a file.
|
|
270
|
-
* @param file The file path (string or URL) to load the calendar event from.
|
|
271
|
-
* @param options Optional calendar event options (method, alternativeText).
|
|
272
|
-
* @returns This instance for method chaining.
|
|
273
|
-
* @example
|
|
274
|
-
* ```ts
|
|
275
|
-
* message.icalEventFromFile('/path/to/event.ics')
|
|
276
|
-
* message.icalEventFromFile(new URL('file:///path/to/event.ics'))
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
icalEventFromFile(file: string | URL, options?: CalendarEventOptions): this;
|
|
280
|
-
/**
|
|
281
|
-
* Attach a calendar event and load contents from a URL.
|
|
282
|
-
* @param url The URL to fetch the calendar event from.
|
|
283
|
-
* @param options Optional calendar event options (method, alternativeText).
|
|
284
|
-
* @returns This instance for method chaining.
|
|
285
|
-
* @example
|
|
286
|
-
* ```ts
|
|
287
|
-
* message.icalEventFromUrl('https://example.com/event.ics')
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
icalEventFromUrl(url: string, options?: CalendarEventOptions): this;
|
|
291
|
-
/**
|
|
292
|
-
* Renders a template and sets as HTML content.
|
|
293
|
-
* Accepts a render function for flexible template engine support.
|
|
294
|
-
* @param render The template renderer function.
|
|
295
|
-
* @param template The template content (string, React component, etc.).
|
|
296
|
-
* @param data Optional data/variables to pass to the template.
|
|
297
|
-
* @param options Optional renderer-specific options.
|
|
298
|
-
* @param options.autoText Whether to auto-generate text version from HTML (default: true).
|
|
299
|
-
* @returns This instance for method chaining.
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* import { renderHandlebars } from '@visulima/email/template/handlebars';
|
|
303
|
-
* message.view(renderHandlebars, '<h1>Hello {{name}}!</h1>', { name: 'John' })
|
|
304
|
-
*
|
|
305
|
-
* import { renderMjml } from '@visulima/email/template/mjml';
|
|
306
|
-
* message.view(renderMjml, mjmlTemplate)
|
|
307
|
-
*
|
|
308
|
-
* import { renderReactEmail } from '@visulima/email/template/react-email';
|
|
309
|
-
* message.view(renderReactEmail, <WelcomeEmail name="John" />)
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
view(render: TemplateRenderer, template: unknown, data?: Record<string, unknown>, options?: {
|
|
313
|
-
[key: string]: unknown;
|
|
314
|
-
autoText?: boolean;
|
|
315
|
-
}): Promise<this>;
|
|
316
|
-
/**
|
|
317
|
-
* Renders a text template and sets as text content.
|
|
318
|
-
* @param render The template renderer function.
|
|
319
|
-
* @param template The text template content.
|
|
320
|
-
* @param data Optional data/variables to pass to the template.
|
|
321
|
-
* @param options Optional renderer-specific options.
|
|
322
|
-
* @returns This instance for method chaining.
|
|
323
|
-
* @example
|
|
324
|
-
* ```ts
|
|
325
|
-
* import { renderHandlebars } from '@visulima/email/template/handlebars';
|
|
326
|
-
* message.viewText(renderHandlebars, 'Hello {{name}}!', { name: 'John' })
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
viewText(render: TemplateRenderer, template: string, data?: Record<string, unknown>, options?: Record<string, unknown>): Promise<this>;
|
|
330
|
-
/**
|
|
331
|
-
* Builds the email options.
|
|
332
|
-
* @returns The built email options ready for sending.
|
|
333
|
-
* @throws {Error} When required fields (from, to, subject, content) are missing.
|
|
334
|
-
*/
|
|
335
|
-
build(): Promise<EmailOptions>;
|
|
336
|
-
/**
|
|
337
|
-
* Gets the subject of the email.
|
|
338
|
-
* @returns The subject text or empty string if not set.
|
|
339
|
-
*/
|
|
340
|
-
getSubject(): string;
|
|
341
|
-
/**
|
|
342
|
-
* Gets the from address.
|
|
343
|
-
* @returns The from address or undefined if not set.
|
|
344
|
-
*/
|
|
345
|
-
getFrom(): EmailAddress | undefined;
|
|
346
|
-
/**
|
|
347
|
-
* Gets the recipient addresses.
|
|
348
|
-
* @returns Array of recipient addresses.
|
|
349
|
-
*/
|
|
350
|
-
getTo(): EmailAddress[];
|
|
351
|
-
/**
|
|
352
|
-
* Gets the CC recipient addresses.
|
|
353
|
-
* @returns Array of CC recipient addresses.
|
|
354
|
-
*/
|
|
355
|
-
getCc(): EmailAddress[];
|
|
356
|
-
/**
|
|
357
|
-
* Gets the BCC recipient addresses.
|
|
358
|
-
* @returns Array of BCC recipient addresses.
|
|
359
|
-
*/
|
|
360
|
-
getBcc(): EmailAddress[];
|
|
361
|
-
/**
|
|
362
|
-
* Gets the reply-to address.
|
|
363
|
-
* @returns The reply-to address or undefined if not set.
|
|
364
|
-
*/
|
|
365
|
-
getReplyTo(): EmailAddress | undefined;
|
|
366
|
-
/**
|
|
367
|
-
* Gets the sender address.
|
|
368
|
-
* @returns The sender address or undefined if not set.
|
|
369
|
-
*/
|
|
370
|
-
getSender(): EmailAddress | undefined;
|
|
371
|
-
/**
|
|
372
|
-
* Gets the return-path address.
|
|
373
|
-
* @returns The return-path address or undefined if not set.
|
|
374
|
-
*/
|
|
375
|
-
getReturnPath(): EmailAddress | undefined;
|
|
376
|
-
/**
|
|
377
|
-
* Gets the date header.
|
|
378
|
-
* @returns The date or undefined if not set.
|
|
379
|
-
*/
|
|
380
|
-
getDate(): Date | undefined;
|
|
381
|
-
/**
|
|
382
|
-
* Gets the priority of the email.
|
|
383
|
-
* @returns The priority ('high', 'normal', 'low') or undefined if not set.
|
|
384
|
-
*/
|
|
385
|
-
getPriority(): Priority | undefined;
|
|
386
|
-
/**
|
|
387
|
-
* Gets the plain text content.
|
|
388
|
-
* @returns The text content or undefined if not set.
|
|
389
|
-
*/
|
|
390
|
-
getTextBody(): string | undefined;
|
|
391
|
-
/**
|
|
392
|
-
* Gets the charset for the text content.
|
|
393
|
-
* @returns The text charset (default: 'utf8').
|
|
394
|
-
*/
|
|
395
|
-
getTextCharset(): string;
|
|
396
|
-
/**
|
|
397
|
-
* Gets the HTML content.
|
|
398
|
-
* @returns The HTML content or undefined if not set.
|
|
399
|
-
*/
|
|
400
|
-
getHtmlBody(): string | undefined;
|
|
401
|
-
/**
|
|
402
|
-
* Gets the charset for the HTML content.
|
|
403
|
-
* @returns The HTML charset (default: 'utf8').
|
|
404
|
-
*/
|
|
405
|
-
getHtmlCharset(): string;
|
|
406
|
-
/**
|
|
407
|
-
* Gets the attachments.
|
|
408
|
-
* @returns Array of attachments.
|
|
409
|
-
*/
|
|
410
|
-
getAttachments(): Attachment[];
|
|
411
|
-
/**
|
|
412
|
-
* Attempts to auto-generate text content from HTML.
|
|
413
|
-
* @param html The HTML content to convert.
|
|
414
|
-
* @private
|
|
415
|
-
*/
|
|
416
|
-
private tryAutoGenerateText;
|
|
417
|
-
/**
|
|
418
|
-
* Creates an error, logs it, and throws it.
|
|
419
|
-
* @param message Error message to throw.
|
|
420
|
-
* @param logMessage Optional log message (defaults to message).
|
|
421
|
-
* @private
|
|
422
|
-
*/
|
|
423
|
-
private throwAndLogError;
|
|
424
|
-
}
|
|
425
|
-
export default MailMessage;
|
package/dist/mail.d.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
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";
|
|
5
|
-
/**
|
|
6
|
-
* Type alias for messages that can be sent via Mail.send().
|
|
7
|
-
*/
|
|
8
|
-
export type SendableMessage = MailMessage | EmailOptions;
|
|
9
|
-
/**
|
|
10
|
-
* Global email configuration that applies to all emails sent through a Mail instance.
|
|
11
|
-
*/
|
|
12
|
-
export interface MailGlobalConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Default from address to use if not specified in the message.
|
|
15
|
-
*/
|
|
16
|
-
from?: EmailAddress;
|
|
17
|
-
/**
|
|
18
|
-
* Global headers to add to all emails.
|
|
19
|
-
* These will be merged with message-specific headers, with message headers taking precedence.
|
|
20
|
-
*/
|
|
21
|
-
headers?: EmailHeaders;
|
|
22
|
-
/**
|
|
23
|
-
* Default reply-to address to use if not specified in the message.
|
|
24
|
-
*/
|
|
25
|
-
replyTo?: EmailAddress;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Mail class - instance-based email sending.
|
|
29
|
-
*/
|
|
30
|
-
export declare class Mail {
|
|
31
|
-
/**
|
|
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
|
|
36
|
-
*/
|
|
37
|
-
private static extractErrorMessages;
|
|
38
|
-
private provider;
|
|
39
|
-
private logger?;
|
|
40
|
-
private loggerInstance?;
|
|
41
|
-
private globalConfig?;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a new Mail instance with a provider.
|
|
44
|
-
* @param provider The email provider instance.
|
|
45
|
-
*/
|
|
46
|
-
constructor(provider: Provider);
|
|
47
|
-
/**
|
|
48
|
-
* Sets the logger instance for this mail instance.
|
|
49
|
-
* @param logger The logger instance (Console) to use for logging.
|
|
50
|
-
* @returns This instance for method chaining.
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const mail = createMail(provider);
|
|
54
|
-
* mail.setLogger(console);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
setLogger(logger: Console): this;
|
|
58
|
-
/**
|
|
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.
|
|
61
|
-
* @returns This instance for method chaining.
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* const mail = createMail(provider);
|
|
65
|
-
* mail.setFrom({ email: "noreply@example.com", name: "My App" });
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
setFrom(from: EmailAddress): this;
|
|
69
|
-
/**
|
|
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.
|
|
72
|
-
* @returns This instance for method chaining.
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* const mail = createMail(provider);
|
|
76
|
-
* mail.setReplyTo({ email: "support@example.com" });
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
setReplyTo(replyTo: EmailAddress): this;
|
|
80
|
-
/**
|
|
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.
|
|
84
|
-
* @returns This instance for method chaining.
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const mail = createMail(provider);
|
|
88
|
-
* mail.setHeaders({ "X-App-Name": "MyApp", "X-Version": "1.0.0" });
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
setHeaders(headers: EmailHeaders): this;
|
|
92
|
-
/**
|
|
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.
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
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>");
|
|
105
|
-
*
|
|
106
|
-
* const eml = await mail.draft(message);
|
|
107
|
-
* console.log("Draft EML:", eml);
|
|
108
|
-
*
|
|
109
|
-
* // Save to file
|
|
110
|
-
* await fs.writeFile("draft.eml", eml);
|
|
111
|
-
*
|
|
112
|
-
* // Or send later by parsing the EML back to EmailOptions
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
draft(message: SendableMessage | DraftMailMessage): Promise<string>;
|
|
116
|
-
/**
|
|
117
|
-
* Sends an email message or email options.
|
|
118
|
-
* @param message The message to send (MailMessage or EmailOptions).
|
|
119
|
-
* @returns A result object containing the email result or error.
|
|
120
|
-
* @example
|
|
121
|
-
* ```ts
|
|
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
|
-
* });
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
send(message: SendableMessage): Promise<Result<EmailResult>>;
|
|
140
|
-
/**
|
|
141
|
-
* Sends multiple messages using the email service.
|
|
142
|
-
* Returns an async iterable that yields receipts for each sent message.
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* const messages = [
|
|
146
|
-
* { from: "sender@example.com", to: "user1@example.com", subject: "Hello 1", html: "<h1>Hello</h1>" },
|
|
147
|
-
* { from: "sender@example.com", to: "user2@example.com", subject: "Hello 2", html: "<h1>Hello</h1>" },
|
|
148
|
-
* ];
|
|
149
|
-
*
|
|
150
|
-
* for await (const receipt of mail.sendMany(messages)) {
|
|
151
|
-
* if (receipt.successful) {
|
|
152
|
-
* console.log("Sent:", receipt.messageId);
|
|
153
|
-
* } else {
|
|
154
|
-
* console.error("Failed:", receipt.errorMessages);
|
|
155
|
-
* }
|
|
156
|
-
* }
|
|
157
|
-
* ```
|
|
158
|
-
* @param messages An iterable of MailMessage instances or email options to send.
|
|
159
|
-
* @param options Optional parameters for sending.
|
|
160
|
-
* @param options.signal Abort signal to cancel the operation.
|
|
161
|
-
* @returns An async iterable that yields receipts for each sent message.
|
|
162
|
-
*/
|
|
163
|
-
sendMany(messages: Iterable<SendableMessage> | AsyncIterable<SendableMessage>, options?: {
|
|
164
|
-
signal?: AbortSignal;
|
|
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;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Creates a new Mail instance with a provider.
|
|
198
|
-
* @param provider The email provider instance.
|
|
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
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
export declare const createMail: (provider: Provider) => Mail;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var b=Object.defineProperty;var l=(o,e)=>b(o,"name",{value:e,configurable:!0});import{MailMessage as f}from"./MailMessage-B76GPBBA.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};
|
|
@@ -1 +0,0 @@
|
|
|
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-S8WRsNtY.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};
|