@visulima/email 1.0.0-alpha.1

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.
Files changed (217) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE.md +1266 -0
  3. package/README.md +1084 -0
  4. package/dist/attachment-helpers.d.ts +64 -0
  5. package/dist/crypto/dkim-signer.d.ts +48 -0
  6. package/dist/crypto/index.d.ts +4 -0
  7. package/dist/crypto/index.js +1 -0
  8. package/dist/crypto/smime-encrypter.d.ts +53 -0
  9. package/dist/crypto/smime-signer.d.ts +48 -0
  10. package/dist/crypto/types.d.ts +101 -0
  11. package/dist/errors/email-error.d.ts +17 -0
  12. package/dist/errors/required-option-error.d.ts +10 -0
  13. package/dist/index.d.ts +22 -0
  14. package/dist/index.js +1 -0
  15. package/dist/mail.d.ts +357 -0
  16. package/dist/packem_shared/DkimSigner-Z8D4Il10.js +18 -0
  17. package/dist/packem_shared/EmailError-zm2ffVav.js +1 -0
  18. package/dist/packem_shared/MailMessage-Hdgowmvi.js +1 -0
  19. package/dist/packem_shared/RequiredOptionError-CevW3u2K.js +1 -0
  20. package/dist/packem_shared/SmimeEncrypter-CBevU534.js +6 -0
  21. package/dist/packem_shared/SmimeSigner-02aXVi90.js +8 -0
  22. package/dist/packem_shared/address-formatter-Cm_E_ZMa.js +1 -0
  23. package/dist/packem_shared/ahaSendProvider-NUD_kwyT.js +1 -0
  24. package/dist/packem_shared/attachment-processor-2rHmfa7j.js +1 -0
  25. package/dist/packem_shared/awsSesProvider-CkuFOzb0.js +32 -0
  26. package/dist/packem_shared/azureProvider-Ckdrpmw9.js +1 -0
  27. package/dist/packem_shared/brevoProvider-CB3IYW4n.js +1 -0
  28. package/dist/packem_shared/buildMimeMessage-BPtd0pno.js +2 -0
  29. package/dist/packem_shared/comparePriority-BfiwjVsV.js +1 -0
  30. package/dist/packem_shared/createLogger-DlElSVQP.js +1 -0
  31. package/dist/packem_shared/defineProvider-B9rSklAJ.js +1 -0
  32. package/dist/packem_shared/detectMimeType-S8WRsNtY.js +1 -0
  33. package/dist/packem_shared/failoverProvider-sam9n1AG.js +1 -0
  34. package/dist/packem_shared/formatEmailAddress-CHeME3Vk.js +1 -0
  35. package/dist/packem_shared/formatEmailAddresses-UegVOe5A.js +1 -0
  36. package/dist/packem_shared/generateBoundary-CZ8kJuY6.js +1 -0
  37. package/dist/packem_shared/generateMessageId-11Ls5JsR.js +1 -0
  38. package/dist/packem_shared/headersToRecord-BKUTr40L.js +1 -0
  39. package/dist/packem_shared/httpProvider-BhN0RrK-.js +1 -0
  40. package/dist/packem_shared/infobipProvider-D8vYTHV4.js +1 -0
  41. package/dist/packem_shared/isPortAvailable-5kfsfo8u.js +1 -0
  42. package/dist/packem_shared/mailCrabProvider-BEwRjB3F.js +1 -0
  43. package/dist/packem_shared/mailPaceProvider-C47Izgaj.js +1 -0
  44. package/dist/packem_shared/mailerSendProvider-C4uAo-fc.js +1 -0
  45. package/dist/packem_shared/mailgunProvider-B7upu_OV.js +1 -0
  46. package/dist/packem_shared/mailjetProvider-ReErm08u.js +1 -0
  47. package/dist/packem_shared/mailomatProvider-OlCT_O2i.js +1 -0
  48. package/dist/packem_shared/mailtrapProvider-hVMV3h6r.js +1 -0
  49. package/dist/packem_shared/makeRequest-DwxHX0xo.js +1 -0
  50. package/dist/packem_shared/mandrillProvider-DdnbkHZI.js +1 -0
  51. package/dist/packem_shared/mockProvider-BDWZJpea.js +1 -0
  52. package/dist/packem_shared/nodemailerProvider-BV21eRGX.js +1 -0
  53. package/dist/packem_shared/opentelemetryProvider-kAz62mKm.js +1 -0
  54. package/dist/packem_shared/parseAddress-CATTKGe_.js +1 -0
  55. package/dist/packem_shared/plunkProvider-Bs6K51lT.js +1 -0
  56. package/dist/packem_shared/postalProvider-Bcsxp-z6.js +1 -0
  57. package/dist/packem_shared/postmarkProvider-BUq3wuYD.js +1 -0
  58. package/dist/packem_shared/provider-base-_hbWXBdK.js +1 -0
  59. package/dist/packem_shared/readFile-BlZxbhCU-C8bCdiA2.js +1 -0
  60. package/dist/packem_shared/resendProvider-D-_HQpN_.js +1 -0
  61. package/dist/packem_shared/retry-D1MBqS49.js +1 -0
  62. package/dist/packem_shared/roundRobinProvider-CejLM1rZ.js +1 -0
  63. package/dist/packem_shared/sanitize-header-wWav-Scu.js +1 -0
  64. package/dist/packem_shared/scalewayProvider-1n6ePiGl.js +1 -0
  65. package/dist/packem_shared/sendGridProvider-B1T62dyX.js +1 -0
  66. package/dist/packem_shared/smtpProvider-CcAoRrkt.js +23 -0
  67. package/dist/packem_shared/sweegoProvider-CxFmEUh6.js +1 -0
  68. package/dist/packem_shared/validateEmail-BkVdVioP.js +1 -0
  69. package/dist/packem_shared/validateEmailOptions-BzlJECG5.js +1 -0
  70. package/dist/packem_shared/zeptomailProvider-CWYQPAJk.js +1 -0
  71. package/dist/providers/ahasend/index.d.ts +3 -0
  72. package/dist/providers/ahasend/index.js +1 -0
  73. package/dist/providers/ahasend/provider.d.ts +7 -0
  74. package/dist/providers/ahasend/types.d.ts +28 -0
  75. package/dist/providers/aws-ses/index.d.ts +3 -0
  76. package/dist/providers/aws-ses/index.js +1 -0
  77. package/dist/providers/aws-ses/provider.d.ts +8 -0
  78. package/dist/providers/aws-ses/types.d.ts +38 -0
  79. package/dist/providers/azure/index.d.ts +3 -0
  80. package/dist/providers/azure/index.js +1 -0
  81. package/dist/providers/azure/provider.d.ts +7 -0
  82. package/dist/providers/azure/types.d.ts +44 -0
  83. package/dist/providers/brevo/index.d.ts +3 -0
  84. package/dist/providers/brevo/index.js +1 -0
  85. package/dist/providers/brevo/provider.d.ts +7 -0
  86. package/dist/providers/brevo/types.d.ts +50 -0
  87. package/dist/providers/failover/index.d.ts +3 -0
  88. package/dist/providers/failover/index.js +1 -0
  89. package/dist/providers/failover/provider.d.ts +7 -0
  90. package/dist/providers/failover/types.d.ts +19 -0
  91. package/dist/providers/http/index.d.ts +3 -0
  92. package/dist/providers/http/index.js +1 -0
  93. package/dist/providers/http/provider.d.ts +7 -0
  94. package/dist/providers/http/types.d.ts +27 -0
  95. package/dist/providers/infobip/index.d.ts +3 -0
  96. package/dist/providers/infobip/index.js +1 -0
  97. package/dist/providers/infobip/provider.d.ts +7 -0
  98. package/dist/providers/infobip/types.d.ts +48 -0
  99. package/dist/providers/mailcrab/index.d.ts +3 -0
  100. package/dist/providers/mailcrab/index.js +1 -0
  101. package/dist/providers/mailcrab/provider.d.ts +9 -0
  102. package/dist/providers/mailcrab/types.d.ts +22 -0
  103. package/dist/providers/mailersend/index.d.ts +3 -0
  104. package/dist/providers/mailersend/index.js +1 -0
  105. package/dist/providers/mailersend/provider.d.ts +7 -0
  106. package/dist/providers/mailersend/types.d.ts +43 -0
  107. package/dist/providers/mailgun/index.d.ts +3 -0
  108. package/dist/providers/mailgun/index.js +1 -0
  109. package/dist/providers/mailgun/provider.d.ts +7 -0
  110. package/dist/providers/mailgun/types.d.ts +65 -0
  111. package/dist/providers/mailjet/index.d.ts +3 -0
  112. package/dist/providers/mailjet/index.js +1 -0
  113. package/dist/providers/mailjet/provider.d.ts +7 -0
  114. package/dist/providers/mailjet/types.d.ts +64 -0
  115. package/dist/providers/mailomat/index.d.ts +3 -0
  116. package/dist/providers/mailomat/index.js +1 -0
  117. package/dist/providers/mailomat/provider.d.ts +7 -0
  118. package/dist/providers/mailomat/types.d.ts +32 -0
  119. package/dist/providers/mailpace/index.d.ts +3 -0
  120. package/dist/providers/mailpace/index.js +1 -0
  121. package/dist/providers/mailpace/provider.d.ts +7 -0
  122. package/dist/providers/mailpace/types.d.ts +44 -0
  123. package/dist/providers/mailtrap/index.d.ts +3 -0
  124. package/dist/providers/mailtrap/index.js +1 -0
  125. package/dist/providers/mailtrap/provider.d.ts +7 -0
  126. package/dist/providers/mailtrap/types.d.ts +36 -0
  127. package/dist/providers/mandrill/index.d.ts +3 -0
  128. package/dist/providers/mandrill/index.js +1 -0
  129. package/dist/providers/mandrill/provider.d.ts +7 -0
  130. package/dist/providers/mandrill/types.d.ts +79 -0
  131. package/dist/providers/mock/index.d.ts +3 -0
  132. package/dist/providers/mock/index.js +1 -0
  133. package/dist/providers/mock/provider.d.ts +8 -0
  134. package/dist/providers/mock/types.d.ts +50 -0
  135. package/dist/providers/nodemailer/index.d.ts +3 -0
  136. package/dist/providers/nodemailer/index.js +1 -0
  137. package/dist/providers/nodemailer/provider.d.ts +7 -0
  138. package/dist/providers/nodemailer/types.d.ts +30 -0
  139. package/dist/providers/opentelemetry/index.d.ts +3 -0
  140. package/dist/providers/opentelemetry/index.js +1 -0
  141. package/dist/providers/opentelemetry/provider.d.ts +8 -0
  142. package/dist/providers/opentelemetry/types.d.ts +31 -0
  143. package/dist/providers/plunk/index.d.ts +3 -0
  144. package/dist/providers/plunk/index.js +1 -0
  145. package/dist/providers/plunk/provider.d.ts +7 -0
  146. package/dist/providers/plunk/types.d.ts +30 -0
  147. package/dist/providers/postal/index.d.ts +3 -0
  148. package/dist/providers/postal/index.js +1 -0
  149. package/dist/providers/postal/provider.d.ts +7 -0
  150. package/dist/providers/postal/types.d.ts +40 -0
  151. package/dist/providers/postmark/index.d.ts +3 -0
  152. package/dist/providers/postmark/index.js +1 -0
  153. package/dist/providers/postmark/provider.d.ts +7 -0
  154. package/dist/providers/postmark/types.d.ts +52 -0
  155. package/dist/providers/provider.d.ts +27 -0
  156. package/dist/providers/resend/index.d.ts +3 -0
  157. package/dist/providers/resend/index.js +1 -0
  158. package/dist/providers/resend/provider.d.ts +7 -0
  159. package/dist/providers/resend/types.d.ts +43 -0
  160. package/dist/providers/roundrobin/index.d.ts +3 -0
  161. package/dist/providers/roundrobin/index.js +1 -0
  162. package/dist/providers/roundrobin/provider.d.ts +7 -0
  163. package/dist/providers/roundrobin/types.d.ts +19 -0
  164. package/dist/providers/scaleway/index.d.ts +3 -0
  165. package/dist/providers/scaleway/index.js +1 -0
  166. package/dist/providers/scaleway/provider.d.ts +7 -0
  167. package/dist/providers/scaleway/types.d.ts +36 -0
  168. package/dist/providers/sendgrid/index.d.ts +3 -0
  169. package/dist/providers/sendgrid/index.js +1 -0
  170. package/dist/providers/sendgrid/provider.d.ts +7 -0
  171. package/dist/providers/sendgrid/types.d.ts +76 -0
  172. package/dist/providers/smtp/index.d.ts +3 -0
  173. package/dist/providers/smtp/index.js +1 -0
  174. package/dist/providers/smtp/provider.d.ts +7 -0
  175. package/dist/providers/smtp/types.d.ts +63 -0
  176. package/dist/providers/sweego/index.d.ts +3 -0
  177. package/dist/providers/sweego/index.js +1 -0
  178. package/dist/providers/sweego/provider.d.ts +7 -0
  179. package/dist/providers/sweego/types.d.ts +32 -0
  180. package/dist/providers/utils/address-formatter.d.ts +139 -0
  181. package/dist/providers/utils/attachment-processor.d.ts +58 -0
  182. package/dist/providers/utils/index.d.ts +4 -0
  183. package/dist/providers/utils/payload-builder.d.ts +78 -0
  184. package/dist/providers/utils/provider-base.d.ts +69 -0
  185. package/dist/providers/zeptomail/index.d.ts +3 -0
  186. package/dist/providers/zeptomail/index.js +1 -0
  187. package/dist/providers/zeptomail/provider.d.ts +7 -0
  188. package/dist/providers/zeptomail/types.d.ts +29 -0
  189. package/dist/template-engines/handlebars.d.ts +25 -0
  190. package/dist/template-engines/handlebars.js +1 -0
  191. package/dist/template-engines/html-to-text.d.ts +27 -0
  192. package/dist/template-engines/html-to-text.js +1 -0
  193. package/dist/template-engines/mjml.d.ts +12 -0
  194. package/dist/template-engines/mjml.js +1 -0
  195. package/dist/template-engines/react-email.d.ts +11 -0
  196. package/dist/template-engines/react-email.js +1 -0
  197. package/dist/template-engines/types.d.ts +8 -0
  198. package/dist/template-engines/vue-email.d.ts +11 -0
  199. package/dist/template-engines/vue-email.js +1 -0
  200. package/dist/types.d.ts +185 -0
  201. package/dist/utils/build-mime-message.d.ts +8 -0
  202. package/dist/utils/compare-priority.d.ts +16 -0
  203. package/dist/utils/create-logger.d.ts +18 -0
  204. package/dist/utils/format-email-address.d.ts +9 -0
  205. package/dist/utils/format-email-addresses.d.ts +8 -0
  206. package/dist/utils/generate-boundary.d.ts +7 -0
  207. package/dist/utils/generate-message-id.d.ts +6 -0
  208. package/dist/utils/headers-to-record.d.ts +9 -0
  209. package/dist/utils/is-port-available.d.ts +9 -0
  210. package/dist/utils/make-request.d.ts +18 -0
  211. package/dist/utils/parse-address.d.ts +19 -0
  212. package/dist/utils/retry.d.ts +10 -0
  213. package/dist/utils/sanitize-header.d.ts +14 -0
  214. package/dist/utils/to-base64.d.ts +8 -0
  215. package/dist/utils/validate-email-options.d.ts +8 -0
  216. package/dist/utils/validate-email.d.ts +7 -0
  217. package/package.json +269 -0
package/README.md ADDED
@@ -0,0 +1,1084 @@
1
+ <div align="center">
2
+ <h3>visulima email</h3>
3
+ <p>
4
+ Email sending package with multiple provider support
5
+ </p>
6
+ </div>
7
+
8
+ <br />
9
+
10
+ <div align="center">
11
+
12
+ [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ <div align="center">
19
+ <p>
20
+ <sup>
21
+ Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
22
+ </sup>
23
+ </p>
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ npm install @visulima/email
32
+ ```
33
+
34
+ ```sh
35
+ yarn add @visulima/email
36
+ ```
37
+
38
+ ```sh
39
+ pnpm add @visulima/email
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Basic Usage
45
+
46
+ ```typescript
47
+ import { createMail, resendProvider } from "@visulima/email";
48
+
49
+ // Create a provider
50
+ const resend = resendProvider({
51
+ apiKey: "re_xxx",
52
+ });
53
+
54
+ // Create a Mail instance
55
+ const mail = createMail(resend);
56
+
57
+ // Send an email using the message builder
58
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Hello").html("<h1>Hello World</h1>").send();
59
+
60
+ if (result.success) {
61
+ console.log("Email sent:", result.data?.messageId);
62
+ }
63
+ ```
64
+
65
+ ### Using Different Providers
66
+
67
+ ```typescript
68
+ import { createMail, smtpProvider, resendProvider } from "@visulima/email";
69
+
70
+ // SMTP provider
71
+ const smtp = smtpProvider({
72
+ host: "smtp.example.com",
73
+ port: 587,
74
+ secure: true,
75
+ user: "user@example.com",
76
+ password: "password",
77
+ });
78
+
79
+ // Resend provider
80
+ const resend = resendProvider({
81
+ apiKey: "re_xxx",
82
+ });
83
+
84
+ // Create Mail instances for each provider
85
+ const smtpMail = createMail(smtp);
86
+ const resendMail = createMail(resend);
87
+
88
+ // Send via specific provider
89
+ await resendMail.message().to("user@example.com").from("sender@example.com").subject("Hello").html("<h1>Hello World</h1>").send();
90
+ ```
91
+
92
+ ### Using Mailable Classes
93
+
94
+ ```typescript
95
+ import { createMail, type Mailable, type EmailOptions } from "@visulima/email";
96
+ import { resendProvider } from "@visulima/email";
97
+
98
+ class WelcomeEmail implements Mailable {
99
+ constructor(private user: { name: string; email: string }) {}
100
+
101
+ build(): EmailOptions {
102
+ return {
103
+ from: { email: "noreply@example.com" },
104
+ to: { email: this.user.email, name: this.user.name },
105
+ subject: "Welcome!",
106
+ html: `<h1>Welcome ${this.user.name}!</h1>`,
107
+ };
108
+ }
109
+ }
110
+
111
+ const mail = createMail(resendProvider({ apiKey: "re_xxx" }));
112
+ const result = await mail.send(new WelcomeEmail({ name: "John", email: "john@example.com" }));
113
+ ```
114
+
115
+ ### Direct Email Sending
116
+
117
+ ```typescript
118
+ import { createMail, resendProvider, type EmailOptions } from "@visulima/email";
119
+
120
+ const mail = createMail(resendProvider({ apiKey: "re_xxx" }));
121
+
122
+ const emailOptions: EmailOptions = {
123
+ from: { email: "sender@example.com" },
124
+ to: { email: "user@example.com" },
125
+ subject: "Hello",
126
+ html: "<h1>Hello World</h1>",
127
+ };
128
+
129
+ const result = await mail.sendEmail(emailOptions);
130
+ ```
131
+
132
+ ### Failover Provider
133
+
134
+ The failover provider allows you to configure multiple email providers as backups. If the primary provider fails, it will automatically try the next provider in the list.
135
+
136
+ ```typescript
137
+ import { createMail, failoverProvider, resendProvider, smtpProvider } from "@visulima/email";
138
+
139
+ // Create individual providers
140
+ const resend = resendProvider({ apiKey: "re_xxx" });
141
+ const smtp = smtpProvider({
142
+ host: "smtp.example.com",
143
+ port: 587,
144
+ user: "user@example.com",
145
+ password: "password",
146
+ });
147
+
148
+ // Create failover provider with multiple mailers
149
+ const failover = failoverProvider({
150
+ mailers: [
151
+ resend, // Try Resend first
152
+ smtp, // Fallback to SMTP if Resend fails
153
+ ],
154
+ retryAfter: 60, // Wait 60ms before trying next provider (default: 60)
155
+ });
156
+
157
+ // Use failover provider
158
+ const mail = createMail(failover);
159
+
160
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Hello").html("<h1>Hello World</h1>").send();
161
+
162
+ // The failover provider will try Resend first, and if it fails,
163
+ // automatically try SMTP
164
+ ```
165
+
166
+ You can also use provider factories directly:
167
+
168
+ ```typescript
169
+ import { failoverProvider, resendProvider, smtpProvider } from "@visulima/email";
170
+
171
+ const failover = failoverProvider({
172
+ mailers: [
173
+ resendProvider({ apiKey: "re_xxx" }), // Provider factory
174
+ smtpProvider({
175
+ // Provider factory
176
+ host: "smtp.example.com",
177
+ port: 587,
178
+ user: "user@example.com",
179
+ password: "password",
180
+ }),
181
+ ],
182
+ retryAfter: 100, // Wait 100ms between attempts
183
+ });
184
+ ```
185
+
186
+ ### Round-Robin Provider
187
+
188
+ The round-robin provider distributes your email sending workload across multiple providers. Each email is sent using the next available provider in rotation, providing load balancing across your mailers.
189
+
190
+ ```typescript
191
+ import { createMail, roundRobinProvider, resendProvider, smtpProvider } from "@visulima/email";
192
+
193
+ // Create individual providers
194
+ const resend = resendProvider({ apiKey: "re_xxx" });
195
+ const smtp = smtpProvider({
196
+ host: "smtp.example.com",
197
+ port: 587,
198
+ user: "user@example.com",
199
+ password: "password",
200
+ });
201
+
202
+ // Create round-robin provider with multiple mailers
203
+ const roundRobin = roundRobinProvider({
204
+ mailers: [
205
+ resend, // First provider
206
+ smtp, // Second provider
207
+ ],
208
+ retryAfter: 60, // Wait 60ms before trying next provider if current is unavailable (default: 60)
209
+ });
210
+
211
+ // Use round-robin provider
212
+ const mail = createMail(roundRobin);
213
+
214
+ // Each email will be distributed across providers in rotation
215
+ await mail.message().to("user1@example.com").from("sender@example.com").subject("Email 1").html("<h1>Email 1</h1>").send();
216
+ // Uses resend (or random start)
217
+
218
+ await mail.message().to("user2@example.com").from("sender@example.com").subject("Email 2").html("<h1>Email 2</h1>").send();
219
+ // Uses smtp (next in rotation)
220
+
221
+ await mail.message().to("user3@example.com").from("sender@example.com").subject("Email 3").html("<h1>Email 3</h1>").send();
222
+ // Uses resend (back to first)
223
+ ```
224
+
225
+ You can also use provider factories directly:
226
+
227
+ ```typescript
228
+ import { roundRobinProvider, resendProvider, smtpProvider } from "@visulima/email";
229
+
230
+ const roundRobin = roundRobinProvider({
231
+ mailers: [
232
+ resendProvider({ apiKey: "re_xxx" }), // Provider factory
233
+ smtpProvider({
234
+ // Provider factory
235
+ host: "smtp.example.com",
236
+ port: 587,
237
+ user: "user@example.com",
238
+ password: "password",
239
+ }),
240
+ ],
241
+ retryAfter: 100, // Wait 100ms between attempts
242
+ });
243
+ ```
244
+
245
+ **Note:** The round-robin provider starts at a random provider and then rotates through providers for each subsequent email. If a provider is unavailable, it will automatically try the next provider in the rotation.
246
+
247
+ ### Mailgun Provider
248
+
249
+ Mailgun is a developer-friendly email API service built for transactional emails and automated messaging.
250
+
251
+ ```typescript
252
+ import { createMail, mailgunProvider } from "@visulima/email/providers/mailgun";
253
+
254
+ // Create Mailgun provider
255
+ const mailgun = mailgunProvider({
256
+ apiKey: "your-mailgun-api-key",
257
+ domain: "your-domain.com", // Required: Your Mailgun domain
258
+ endpoint: "https://api.mailgun.net", // Optional: Use https://api.eu.mailgun.net for EU accounts
259
+ });
260
+
261
+ // Use Mailgun provider
262
+ const mail = createMail(mailgun);
263
+
264
+ // Send email with Mailgun-specific options
265
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
266
+
267
+ // Or use Mailgun-specific features
268
+ import type { MailgunEmailOptions } from "@visulima/email/providers/mailgun";
269
+
270
+ const mailgunOptions: MailgunEmailOptions = {
271
+ from: { email: "sender@example.com" },
272
+ to: { email: "user@example.com" },
273
+ subject: "Welcome",
274
+ html: "<h1>Welcome!</h1>",
275
+ template: "welcome-template", // Use Mailgun template
276
+ templateVariables: { name: "John" }, // Template variables
277
+ tags: ["welcome", "user"], // Tags for categorization
278
+ clickTracking: true, // Enable click tracking
279
+ openTracking: true, // Enable open tracking
280
+ deliveryTime: Math.floor(Date.now() / 1000) + 3600, // Schedule for 1 hour from now
281
+ };
282
+
283
+ await mail.sendEmail(mailgunOptions);
284
+ ```
285
+
286
+ ### Mailjet Provider
287
+
288
+ Mailjet combines email marketing and transactional email capabilities, featuring a user-friendly email editor and support for SMTP relay.
289
+
290
+ ```typescript
291
+ import { createMail, mailjetProvider } from "@visulima/email/providers/mailjet";
292
+
293
+ // Create Mailjet provider
294
+ const mailjet = mailjetProvider({
295
+ apiKey: "your-mailjet-api-key",
296
+ apiSecret: "your-mailjet-api-secret",
297
+ endpoint: "https://api.mailjet.com", // Optional, defaults to this
298
+ });
299
+
300
+ // Use Mailjet provider
301
+ const mail = createMail(mailjet);
302
+
303
+ // Send email with Mailjet-specific options
304
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
305
+
306
+ // Or use Mailjet-specific features
307
+ import type { MailjetEmailOptions } from "@visulima/email/providers/mailjet";
308
+
309
+ const mailjetOptions: MailjetEmailOptions = {
310
+ from: { email: "sender@example.com" },
311
+ to: { email: "user@example.com" },
312
+ subject: "Welcome",
313
+ html: "<h1>Welcome!</h1>",
314
+ templateId: 12345, // Use Mailjet template ID
315
+ templateVariables: { name: "John" }, // Template variables
316
+ tags: ["welcome", "user"], // Tags (as CustomCampaign)
317
+ campaign: "welcome-campaign", // Campaign name
318
+ customId: "custom-123", // Custom tracking ID
319
+ priority: 1, // Priority (1-5)
320
+ deliveryTime: Math.floor(Date.now() / 1000) + 3600, // Schedule for 1 hour from now
321
+ };
322
+
323
+ await mail.sendEmail(mailjetOptions);
324
+ ```
325
+
326
+ ### MailerSend Provider
327
+
328
+ MailerSend is a modern email API designed for developers, offering comprehensive email delivery with templates, personalization, and analytics.
329
+
330
+ ```typescript
331
+ import { createMail, mailerSendProvider } from "@visulima/email/providers/mailersend";
332
+
333
+ // Create MailerSend provider
334
+ const mailerSend = mailerSendProvider({
335
+ apiToken: "your-mailersend-api-token",
336
+ endpoint: "https://api.mailersend.com", // Optional, defaults to this
337
+ });
338
+
339
+ // Use MailerSend provider
340
+ const mail = createMail(mailerSend);
341
+
342
+ // Send email with MailerSend-specific options
343
+ import type { MailerSendEmailOptions } from "@visulima/email/providers/mailersend";
344
+
345
+ const mailerSendOptions: MailerSendEmailOptions = {
346
+ from: { email: "sender@example.com" },
347
+ to: { email: "user@example.com" },
348
+ subject: "Welcome",
349
+ html: "<h1>Welcome!</h1>",
350
+ templateId: "template-uuid", // Use MailerSend template UUID
351
+ templateVariables: { name: "John" }, // Template variables
352
+ personalization: [
353
+ {
354
+ email: "user@example.com",
355
+ data: { name: "John", orderId: "123" },
356
+ },
357
+ ],
358
+ tags: ["welcome", "user"],
359
+ scheduledAt: Math.floor(Date.now() / 1000) + 3600, // Schedule for 1 hour from now
360
+ };
361
+
362
+ await mail.sendEmail(mailerSendOptions);
363
+ ```
364
+
365
+ ### Mandrill Provider (Mailchimp Transactional)
366
+
367
+ Mandrill is Mailchimp's transactional email service, providing powerful email delivery with template support and merge variables.
368
+
369
+ ```typescript
370
+ import { createMail, mandrillProvider } from "@visulima/email/providers/mandrill";
371
+
372
+ // Create Mandrill provider
373
+ const mandrill = mandrillProvider({
374
+ apiKey: "your-mandrill-api-key",
375
+ endpoint: "https://mandrillapp.com/api/1.0", // Optional, defaults to this
376
+ });
377
+
378
+ // Use Mandrill provider
379
+ const mail = createMail(mandrill);
380
+
381
+ // Send email with Mandrill-specific options
382
+ import type { MandrillEmailOptions } from "@visulima/email/providers/mandrill";
383
+
384
+ const mandrillOptions: MandrillEmailOptions = {
385
+ from: { email: "sender@example.com" },
386
+ to: { email: "user@example.com" },
387
+ subject: "Welcome",
388
+ html: "<h1>Welcome!</h1>",
389
+ templateName: "welcome-template", // Use Mandrill template
390
+ templateVariables: [{ name: "name", content: "John" }],
391
+ globalMergeVars: [{ name: "company", content: "Acme Inc" }],
392
+ tags: ["welcome", "user"],
393
+ metadata: { orderId: "123" },
394
+ };
395
+
396
+ await mail.sendEmail(mandrillOptions);
397
+ ```
398
+
399
+ ### Postal Provider
400
+
401
+ Postal is a self-hosted email server that provides a complete email solution with webhooks, tracking, and more.
402
+
403
+ ```typescript
404
+ import { createMail, postalProvider } from "@visulima/email/providers/postal";
405
+
406
+ // Create Postal provider
407
+ const postal = postalProvider({
408
+ host: "your-postal-server.com",
409
+ apiKey: "your-postal-api-key",
410
+ endpoint: "https://your-postal-server.com/api/v1", // Optional, auto-generated from host
411
+ });
412
+
413
+ // Use Postal provider
414
+ const mail = createMail(postal);
415
+
416
+ // Send email with Postal-specific options
417
+ import type { PostalEmailOptions } from "@visulima/email/providers/postal";
418
+
419
+ const postalOptions: PostalEmailOptions = {
420
+ from: { email: "sender@example.com" },
421
+ to: { email: "user@example.com" },
422
+ subject: "Welcome",
423
+ html: "<h1>Welcome!</h1>",
424
+ templateId: 123, // Use Postal template ID
425
+ templateVariables: { name: "John" },
426
+ tags: ["welcome"],
427
+ };
428
+
429
+ await mail.sendEmail(postalOptions);
430
+ ```
431
+
432
+ ### Mailtrap Provider
433
+
434
+ Mailtrap is an email testing platform that captures emails in development, making it perfect for testing email functionality.
435
+
436
+ ```typescript
437
+ import { createMail, mailtrapProvider } from "@visulima/email/providers/mailtrap";
438
+
439
+ // Create Mailtrap provider
440
+ const mailtrap = mailtrapProvider({
441
+ apiToken: "your-mailtrap-api-token",
442
+ endpoint: "https://send.api.mailtrap.io", // Optional, defaults to this
443
+ });
444
+
445
+ // Use Mailtrap provider
446
+ const mail = createMail(mailtrap);
447
+
448
+ // Send email with Mailtrap-specific options
449
+ import type { MailtrapEmailOptions } from "@visulima/email/providers/mailtrap";
450
+
451
+ const mailtrapOptions: MailtrapEmailOptions = {
452
+ from: { email: "sender@example.com" },
453
+ to: { email: "user@example.com" },
454
+ subject: "Welcome",
455
+ html: "<h1>Welcome!</h1>",
456
+ templateUuid: "template-uuid", // Use Mailtrap template UUID
457
+ templateVariables: { name: "John" },
458
+ category: "welcome",
459
+ customVariables: { orderId: "123" },
460
+ tags: ["welcome"],
461
+ };
462
+
463
+ await mail.sendEmail(mailtrapOptions);
464
+ ```
465
+
466
+ ### MailPace Provider
467
+
468
+ MailPace is a simple transactional email service focused on ease of use and reliability.
469
+
470
+ ```typescript
471
+ import { createMail, mailPaceProvider } from "@visulima/email/providers/mailpace";
472
+
473
+ // Create MailPace provider
474
+ const mailPace = mailPaceProvider({
475
+ apiToken: "your-mailpace-api-token",
476
+ endpoint: "https://app.mailpace.com/api/v1", // Optional, defaults to this
477
+ });
478
+
479
+ // Use MailPace provider
480
+ const mail = createMail(mailPace);
481
+
482
+ // Send email with MailPace-specific options
483
+ import type { MailPaceEmailOptions } from "@visulima/email/providers/mailpace";
484
+
485
+ const mailPaceOptions: MailPaceEmailOptions = {
486
+ from: { email: "sender@example.com" },
487
+ to: { email: "user@example.com" },
488
+ subject: "Welcome",
489
+ html: "<h1>Welcome!</h1>",
490
+ templateId: 123, // Use MailPace template ID
491
+ templateVariables: { name: "John" },
492
+ tags: ["welcome"],
493
+ listUnsubscribe: "<mailto:unsubscribe@example.com>",
494
+ };
495
+
496
+ await mail.sendEmail(mailPaceOptions);
497
+ ```
498
+
499
+ ### Azure Communication Services Provider
500
+
501
+ Azure Communication Services provides email sending capabilities integrated with Microsoft Azure infrastructure.
502
+
503
+ ```typescript
504
+ import { createMail, azureProvider } from "@visulima/email/providers/azure";
505
+
506
+ // Create Azure provider with access token
507
+ const azure = azureProvider({
508
+ accessToken: "your-azure-access-token",
509
+ region: "eastus", // Azure region (e.g., "eastus", "westus")
510
+ endpoint: "https://eastus.communication.azure.com", // Optional, auto-generated from region
511
+ });
512
+
513
+ // Or use connection string
514
+ const azureWithConnectionString = azureProvider({
515
+ connectionString: "endpoint=https://...;accesskey=...",
516
+ region: "eastus",
517
+ });
518
+
519
+ // Use Azure provider
520
+ const mail = createMail(azure);
521
+
522
+ // Send email with Azure-specific options
523
+ import type { AzureEmailOptions } from "@visulima/email/providers/azure";
524
+
525
+ const azureOptions: AzureEmailOptions = {
526
+ from: { email: "sender@example.com" },
527
+ to: { email: "user@example.com" },
528
+ subject: "Welcome",
529
+ html: "<h1>Welcome!</h1>",
530
+ importance: "high", // "normal" or "high"
531
+ };
532
+
533
+ await mail.sendEmail(azureOptions);
534
+ ```
535
+
536
+ ### Infobip Provider
537
+
538
+ Infobip is a global communication platform offering email delivery with comprehensive tracking and analytics.
539
+
540
+ ```typescript
541
+ import { createMail, infobipProvider } from "@visulima/email/providers/infobip";
542
+
543
+ // Create Infobip provider
544
+ const infobip = infobipProvider({
545
+ apiKey: "your-infobip-api-key",
546
+ baseUrl: "https://api.infobip.com", // Optional, defaults to this
547
+ });
548
+
549
+ // Use Infobip provider
550
+ const mail = createMail(infobip);
551
+
552
+ // Send email with Infobip-specific options
553
+ import type { InfobipEmailOptions } from "@visulima/email/providers/infobip";
554
+
555
+ const infobipOptions: InfobipEmailOptions = {
556
+ from: { email: "sender@example.com" },
557
+ to: { email: "user@example.com" },
558
+ subject: "Welcome",
559
+ html: "<h1>Welcome!</h1>",
560
+ templateId: 123,
561
+ templateVariables: { name: "John" },
562
+ trackingUrl: "https://example.com/track",
563
+ notifyUrl: "https://example.com/webhook",
564
+ sendAt: Date.now() + 3600000, // Schedule for 1 hour from now (milliseconds)
565
+ };
566
+
567
+ await mail.sendEmail(infobipOptions);
568
+ ```
569
+
570
+ ### Scaleway Provider
571
+
572
+ Scaleway provides email services as part of their European cloud platform.
573
+
574
+ ```typescript
575
+ import { createMail, scalewayProvider } from "@visulima/email/providers/scaleway";
576
+
577
+ // Create Scaleway provider
578
+ const scaleway = scalewayProvider({
579
+ apiKey: "your-scaleway-api-key",
580
+ region: "fr-par", // Scaleway region (e.g., "fr-par", "nl-ams")
581
+ });
582
+
583
+ // Use Scaleway provider
584
+ const mail = createMail(scaleway);
585
+
586
+ // Send email with Scaleway-specific options
587
+ import type { ScalewayEmailOptions } from "@visulima/email/providers/scaleway";
588
+
589
+ const scalewayOptions: ScalewayEmailOptions = {
590
+ from: { email: "sender@example.com" },
591
+ to: { email: "user@example.com" },
592
+ subject: "Welcome",
593
+ html: "<h1>Welcome!</h1>",
594
+ templateId: "template-uuid",
595
+ templateVariables: { name: "John" },
596
+ projectId: "project-uuid", // Optional
597
+ };
598
+
599
+ await mail.sendEmail(scalewayOptions);
600
+ ```
601
+
602
+ ### AhaSend Provider
603
+
604
+ AhaSend is an email delivery service with template support and tracking capabilities.
605
+
606
+ ```typescript
607
+ import { createMail, ahaSendProvider } from "@visulima/email/providers/ahasend";
608
+
609
+ // Create AhaSend provider
610
+ const ahaSend = ahaSendProvider({
611
+ apiKey: "your-ahasend-api-key",
612
+ endpoint: "https://api.ahasend.com", // Optional, defaults to this
613
+ });
614
+
615
+ // Use AhaSend provider
616
+ const mail = createMail(ahaSend);
617
+
618
+ // Send email with AhaSend-specific options
619
+ import type { AhaSendEmailOptions } from "@visulima/email/providers/ahasend";
620
+
621
+ const ahaSendOptions: AhaSendEmailOptions = {
622
+ from: { email: "sender@example.com" },
623
+ to: { email: "user@example.com" },
624
+ subject: "Welcome",
625
+ html: "<h1>Welcome!</h1>",
626
+ templateId: "template-id",
627
+ templateVariables: { name: "John" },
628
+ tags: ["welcome"],
629
+ };
630
+
631
+ await mail.sendEmail(ahaSendOptions);
632
+ ```
633
+
634
+ ### Mailomat Provider
635
+
636
+ Mailomat is an email service provider with webhook support and tracking features.
637
+
638
+ ```typescript
639
+ import { createMail, mailomatProvider } from "@visulima/email/providers/mailomat";
640
+
641
+ // Create Mailomat provider
642
+ const mailomat = mailomatProvider({
643
+ apiKey: "your-mailomat-api-key",
644
+ endpoint: "https://api.mailomat.com", // Optional, defaults to this
645
+ });
646
+
647
+ // Use Mailomat provider
648
+ const mail = createMail(mailomat);
649
+
650
+ // Send email with Mailomat-specific options
651
+ import type { MailomatEmailOptions } from "@visulima/email/providers/mailomat";
652
+
653
+ const mailomatOptions: MailomatEmailOptions = {
654
+ from: { email: "sender@example.com" },
655
+ to: { email: "user@example.com" },
656
+ subject: "Welcome",
657
+ html: "<h1>Welcome!</h1>",
658
+ templateId: "template-id",
659
+ templateVariables: { name: "John" },
660
+ tags: ["welcome"],
661
+ };
662
+
663
+ await mail.sendEmail(mailomatOptions);
664
+ ```
665
+
666
+ ### Sweego Provider
667
+
668
+ Sweego is an email delivery service with template support and tracking capabilities.
669
+
670
+ ```typescript
671
+ import { createMail, sweegoProvider } from "@visulima/email/providers/sweego";
672
+
673
+ // Create Sweego provider
674
+ const sweego = sweegoProvider({
675
+ apiKey: "your-sweego-api-key",
676
+ endpoint: "https://api.sweego.com", // Optional, defaults to this
677
+ });
678
+
679
+ // Use Sweego provider
680
+ const mail = createMail(sweego);
681
+
682
+ // Send email with Sweego-specific options
683
+ import type { SweegoEmailOptions } from "@visulima/email/providers/sweego";
684
+
685
+ const sweegoOptions: SweegoEmailOptions = {
686
+ from: { email: "sender@example.com" },
687
+ to: { email: "user@example.com" },
688
+ subject: "Welcome",
689
+ html: "<h1>Welcome!</h1>",
690
+ templateId: "template-id",
691
+ templateVariables: { name: "John" },
692
+ tags: ["welcome"],
693
+ };
694
+
695
+ await mail.sendEmail(sweegoOptions);
696
+ ```
697
+
698
+ ### Brevo Provider (formerly Sendinblue)
699
+
700
+ Brevo is a comprehensive email marketing and transactional email platform with a robust API.
701
+
702
+ ```typescript
703
+ import { createMail, brevoProvider } from "@visulima/email/providers/brevo";
704
+
705
+ // Create Brevo provider
706
+ const brevo = brevoProvider({
707
+ apiKey: "your-brevo-api-key",
708
+ endpoint: "https://api.brevo.com/v3", // Optional, defaults to this
709
+ });
710
+
711
+ // Use Brevo provider
712
+ const mail = createMail(brevo);
713
+
714
+ // Send email with Brevo-specific options
715
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
716
+
717
+ // Or use Brevo-specific features
718
+ import type { BrevoEmailOptions } from "@visulima/email/providers/brevo";
719
+
720
+ const brevoOptions: BrevoEmailOptions = {
721
+ from: { email: "sender@example.com" },
722
+ to: { email: "user@example.com" },
723
+ subject: "Welcome",
724
+ html: "<h1>Welcome!</h1>",
725
+ templateId: 12345, // Use Brevo template ID
726
+ templateParams: { name: "John" }, // Template parameters
727
+ tags: ["welcome", "user"], // Tags for categorization
728
+ scheduledAt: Math.floor(Date.now() / 1000) + 3600, // Schedule for 1 hour from now
729
+ };
730
+
731
+ await mail.sendEmail(brevoOptions);
732
+ ```
733
+
734
+ ### Postmark Provider
735
+
736
+ Postmark specializes in transactional email delivery with a focus on speed and reliability, offering a developer-friendly API and real-time analytics.
737
+
738
+ ```typescript
739
+ import { createMail, postmarkProvider } from "@visulima/email/providers/postmark";
740
+
741
+ // Create Postmark provider
742
+ const postmark = postmarkProvider({
743
+ serverToken: "your-postmark-server-token",
744
+ endpoint: "https://api.postmarkapp.com", // Optional, defaults to this
745
+ });
746
+
747
+ // Use Postmark provider
748
+ const mail = createMail(postmark);
749
+
750
+ // Send email with Postmark-specific options
751
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
752
+
753
+ // Or use Postmark-specific features
754
+ import type { PostmarkEmailOptions } from "@visulima/email/providers/postmark";
755
+
756
+ const postmarkOptions: PostmarkEmailOptions = {
757
+ from: { email: "sender@example.com" },
758
+ to: { email: "user@example.com" },
759
+ subject: "Welcome",
760
+ html: "<h1>Welcome!</h1>",
761
+ templateId: 12345, // Use Postmark template ID
762
+ templateAlias: "welcome-template", // Or use template alias
763
+ templateModel: { name: "John" }, // Template variables
764
+ tags: ["welcome"], // Tag (Postmark supports single tag)
765
+ trackOpens: true, // Enable open tracking
766
+ trackLinks: "HtmlAndText", // Track links in HTML and text
767
+ metadata: { userId: "123" }, // Custom metadata
768
+ };
769
+
770
+ await mail.sendEmail(postmarkOptions);
771
+ ```
772
+
773
+ ### SendGrid Provider
774
+
775
+ SendGrid is a cloud-based email service for transactional and marketing emails, known for its scalability and robust API.
776
+
777
+ ```typescript
778
+ import { createMail, sendGridProvider } from "@visulima/email/providers/sendgrid";
779
+
780
+ // Create SendGrid provider
781
+ const sendgrid = sendGridProvider({
782
+ apiKey: "your-sendgrid-api-key",
783
+ endpoint: "https://api.sendgrid.com/v3", // Optional, defaults to this
784
+ });
785
+
786
+ // Use SendGrid provider
787
+ const mail = createMail(sendgrid);
788
+
789
+ // Send email with SendGrid-specific options
790
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
791
+
792
+ // Or use SendGrid-specific features
793
+ import type { SendGridEmailOptions } from "@visulima/email/providers/sendgrid";
794
+
795
+ const sendGridOptions: SendGridEmailOptions = {
796
+ from: { email: "sender@example.com" },
797
+ to: { email: "user@example.com" },
798
+ subject: "Welcome",
799
+ html: "<h1>Welcome!</h1>",
800
+ templateId: "template-id", // Use SendGrid template
801
+ templateData: { name: "John" }, // Template data
802
+ sendAt: Math.floor(Date.now() / 1000) + 3600, // Schedule for 1 hour from now
803
+ tags: ["welcome", "user"], // Tags as custom args
804
+ trackingSettings: {
805
+ clickTracking: { enable: true },
806
+ openTracking: { enable: true },
807
+ },
808
+ };
809
+
810
+ await mail.sendEmail(sendGridOptions);
811
+ ```
812
+
813
+ ### Plunk Provider
814
+
815
+ Plunk is a modern email platform built on top of AWS SES, offering transactional emails, automations, and broadcasts.
816
+
817
+ ```typescript
818
+ import { createMail, plunkProvider } from "@visulima/email/providers/plunk";
819
+
820
+ // Create Plunk provider
821
+ const plunk = plunkProvider({
822
+ apiKey: "your-plunk-api-key",
823
+ endpoint: "https://api.useplunk.com/v1", // Optional, defaults to this
824
+ });
825
+
826
+ // Use Plunk provider
827
+ const mail = createMail(plunk);
828
+
829
+ // Send email with Plunk-specific options
830
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Welcome").html("<h1>Welcome!</h1>").send();
831
+
832
+ // Or use Plunk-specific features
833
+ import type { PlunkEmailOptions } from "@visulima/email/providers/plunk";
834
+
835
+ const plunkOptions: PlunkEmailOptions = {
836
+ from: { email: "sender@example.com" },
837
+ to: { email: "user@example.com" },
838
+ subject: "Welcome",
839
+ html: "<h1>Welcome!</h1>",
840
+ subscriber: "user@example.com", // For tracking
841
+ subscriberId: "user-123", // Optional subscriber ID
842
+ templateId: "template-id", // Use template
843
+ data: { name: "John" }, // Template data
844
+ };
845
+
846
+ await mail.sendEmail(plunkOptions);
847
+ ```
848
+
849
+ ### Mock Provider (for Testing)
850
+
851
+ The mock provider is designed for testing and development. It stores emails in memory without actually sending them, allowing you to test your email logic without hitting real email services.
852
+
853
+ ```typescript
854
+ import { createMail, mockProvider } from "@visulima/email/providers/mock";
855
+
856
+ // Create mock provider
857
+ const mock = mockProvider({
858
+ debug: true, // Enable debug logging
859
+ delay: 100, // Simulate 100ms delay
860
+ failureRate: 0.1, // 10% failure rate for testing error handling
861
+ });
862
+
863
+ // Use mock provider
864
+ const mail = createMail(mock);
865
+
866
+ // Send email (stored in memory)
867
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Test").html("<h1>Test</h1>").send();
868
+
869
+ // Access stored emails
870
+ const sentEmails = mock.getSentEmails();
871
+ console.log(`Sent ${sentEmails.length} emails`);
872
+
873
+ // Get last sent message
874
+ const lastMessage = mock.getLastSentMessage();
875
+ console.log("Last subject:", lastMessage?.options.subject);
876
+
877
+ // Find messages by criteria
878
+ const welcomeEmails = mock.getMessagesBySubject("Welcome");
879
+ const userEmails = mock.getMessagesTo("user@example.com");
880
+
881
+ // Simulate failures for testing
882
+ mock.setFailureRate(1.0); // Always fail
883
+ mock.setNextResponse({
884
+ successful: false,
885
+ errorMessages: ["Test error"],
886
+ });
887
+
888
+ // Clear stored messages
889
+ mock.clearSentMessages();
890
+
891
+ // Reset provider to initial state
892
+ mock.reset();
893
+ ```
894
+
895
+ **Mock Provider Helper Methods:**
896
+
897
+ - `getSentEmails()` / `getSentMessages()` - Get all sent emails
898
+ - `getLastSentMessage()` - Get the last sent message
899
+ - `getSentMessagesCount()` - Get count of sent messages
900
+ - `clearSentMessages()` - Clear all stored messages
901
+ - `setNextResponse(receipt)` - Set response for next send (one-time)
902
+ - `setDefaultResponse(receipt)` - Set default response
903
+ - `setFailureRate(rate)` - Set failure rate (0.0 to 1.0)
904
+ - `setDelay(ms)` - Set fixed delay
905
+ - `setRandomDelay(min, max)` - Set random delay range
906
+ - `findMessageBy(predicate)` - Find first matching message
907
+ - `findMessagesBy(predicate)` - Find all matching messages
908
+ - `getMessagesTo(email)` - Get messages sent to email
909
+ - `getMessagesBySubject(subject)` - Get messages by subject
910
+ - `waitForMessageCount(count, timeout)` - Wait for message count
911
+ - `waitForMessage(predicate, timeout)` - Wait for matching message
912
+ - `reset()` - Reset to initial state
913
+
914
+ ### MailCrab Provider (for Development)
915
+
916
+ MailCrab is a local SMTP server for testing emails during development. This provider is a convenience wrapper around the SMTP provider with MailCrab defaults.
917
+
918
+ ```typescript
919
+ import { createMail, mailCrabProvider } from "@visulima/email";
920
+
921
+ // Create MailCrab provider with default settings (localhost:1025)
922
+ const mailCrab = mailCrabProvider({});
923
+
924
+ // Or customize the connection
925
+ const customMailCrab = mailCrabProvider({
926
+ host: "localhost",
927
+ port: 1025, // Default MailCrab port
928
+ secure: false, // Typically false for development
929
+ });
930
+
931
+ // Use MailCrab provider
932
+ const mail = createMail(mailCrab);
933
+
934
+ const result = await mail.message().to("user@example.com").from("sender@example.com").subject("Test Email").html("<h1>Test</h1>").send();
935
+ ```
936
+
937
+ **Note:** Make sure MailCrab is running locally before using this provider. MailCrab can be installed via Docker or as a standalone application.
938
+
939
+ ## Supported Providers
940
+
941
+ - **AWS SES** - Amazon Simple Email Service
942
+ - **Brevo** - Email marketing and transactional email platform (formerly Sendinblue)
943
+ - **Failover** - Automatic failover between multiple providers
944
+ - **HTTP** - Generic HTTP API provider
945
+ - **MailCrab** - Local development email testing (SMTP wrapper)
946
+ - **Mailgun** - Developer-friendly email API service
947
+ - **Mailjet** - Email marketing and transactional email platform
948
+ - **MailerSend** - Modern email API for developers
949
+ - **Mandrill** - Mailchimp Transactional Email (formerly Mandrill)
950
+ - **MailPace** - Simple transactional email service
951
+ - **Mailtrap** - Email testing and development tool
952
+ - **Mock** - In-memory provider for testing (no actual emails sent)
953
+ - **Azure** - Microsoft Azure Communication Services
954
+ - **Infobip** - Global communication platform
955
+ - **Scaleway** - European cloud provider email service
956
+ - **AhaSend** - Email delivery service
957
+ - **Mailomat** - Email service provider
958
+ - **Sweego** - Email delivery service
959
+ - **Postal** - Self-hosted email server
960
+ - **Nodemailer** - Popular Node.js email library wrapper
961
+ - **Plunk** - Modern email platform built on AWS SES
962
+ - **Postmark** - Transactional email service focused on deliverability
963
+ - **Resend** - Resend email service
964
+ - **Round Robin** - Load balancing across multiple providers
965
+ - **OpenTelemetry** - OpenTelemetry instrumentation wrapper for observability
966
+ - **SendGrid** - Cloud-based email service for transactional and marketing emails
967
+ - **SMTP** - Standard SMTP protocol
968
+ - **Zeptomail** - Zeptomail email service
969
+
970
+ ## Runtime Support
971
+
972
+ @visulima/email is designed to work across multiple JavaScript runtimes. However, some providers have specific runtime requirements:
973
+
974
+ ### Universal Providers (All Runtimes)
975
+
976
+ These providers work in **Node.js**, **Deno**, **Bun**, and **Cloudflare Workers**:
977
+
978
+ - ✅ **Resend** - Uses Fetch API
979
+ - ✅ **HTTP** - Uses Fetch API
980
+ - ✅ **Zeptomail** - Uses Fetch API
981
+ - ✅ **Brevo** - Uses Fetch API
982
+ - ✅ **Mailgun** - Uses Fetch API
983
+ - ✅ **Mailjet** - Uses Fetch API
984
+ - ✅ **MailerSend** - Uses Fetch API
985
+ - ✅ **Mandrill** - Uses Fetch API
986
+ - ✅ **MailPace** - Uses Fetch API
987
+ - ✅ **Mailtrap** - Uses Fetch API
988
+ - ✅ **Postal** - Uses Fetch API
989
+ - ✅ **Postmark** - Uses Fetch API
990
+ - ✅ **Azure** - Uses Fetch API (requires OAuth2 token or connection string)
991
+ - ✅ **Infobip** - Uses Fetch API
992
+ - ✅ **Scaleway** - Uses Fetch API
993
+ - ✅ **AhaSend** - Uses Fetch API
994
+ - ✅ **Mailomat** - Uses Fetch API
995
+ - ✅ **Sweego** - Uses Fetch API
996
+ - ✅ **SendGrid** - Uses Fetch API
997
+ - ✅ **Plunk** - Uses Fetch API
998
+ - ✅ **Mock** - In-memory provider, works everywhere
999
+ - ✅ **Failover** - Runtime depends on wrapped providers (works if all wrapped providers support the runtime)
1000
+ - ✅ **Round Robin** - Runtime depends on wrapped providers (works if all wrapped providers support the runtime)
1001
+ - ✅ **OpenTelemetry** - Runtime depends on wrapped provider (works if wrapped provider supports the runtime)
1002
+
1003
+ ### Node.js Only Providers
1004
+
1005
+ These providers require Node.js built-in modules and only work in **Node.js**:
1006
+
1007
+ - ⚠️ **AWS SES** - Requires `node:crypto` for AWS Signature V4 signing
1008
+ - ⚠️ **SMTP** - Requires `node:net` and `node:tls` for SMTP connections
1009
+ - ⚠️ **MailCrab** - Wraps SMTP provider (requires Node.js)
1010
+ - ⚠️ **Nodemailer** - Requires the `nodemailer` package (Node.js only)
1011
+
1012
+ ### Template Engines
1013
+
1014
+ Template engines are optional peer dependencies and work where their underlying packages are supported:
1015
+
1016
+ - **Handlebars** - Works in Node.js, Deno, Bun (where `handlebars` package is available)
1017
+ - **MJML** - Works in Node.js, Deno, Bun (where `mjml` package is available)
1018
+ - **React Email** - Works in Node.js, Deno, Bun (where `@react-email/render` package is available)
1019
+ - **Vue Email** - Works in Node.js, Deno, Bun (where `@vue-email/render` package is available)
1020
+ - **HTML-to-Text** - Works in Node.js, Deno, Bun (where `html-to-text` package is available)
1021
+
1022
+ ### Runtime Requirements Summary
1023
+
1024
+ | Provider | Node.js | Deno | Bun | Cloudflare Workers |
1025
+ | ------------- | ------- | ---- | ---- | ------------------ |
1026
+ | Resend | ✅ | ✅ | ✅ | ✅ |
1027
+ | HTTP | ✅ | ✅ | ✅ | ✅ |
1028
+ | Zeptomail | ✅ | ✅ | ✅ | ✅ |
1029
+ | Brevo | ✅ | ✅ | ✅ | ✅ |
1030
+ | Mailgun | ✅ | ✅ | ✅ | ✅ |
1031
+ | Mailjet | ✅ | ✅ | ✅ | ✅ |
1032
+ | MailerSend | ✅ | ✅ | ✅ | ✅ |
1033
+ | Mandrill | ✅ | ✅ | ✅ | ✅ |
1034
+ | MailPace | ✅ | ✅ | ✅ | ✅ |
1035
+ | Mailtrap | ✅ | ✅ | ✅ | ✅ |
1036
+ | Postal | ✅ | ✅ | ✅ | ✅ |
1037
+ | Postmark | ✅ | ✅ | ✅ | ✅ |
1038
+ | Azure | ✅ | ✅ | ✅ | ✅ |
1039
+ | Infobip | ✅ | ✅ | ✅ | ✅ |
1040
+ | Scaleway | ✅ | ✅ | ✅ | ✅ |
1041
+ | AhaSend | ✅ | ✅ | ✅ | ✅ |
1042
+ | Mailomat | ✅ | ✅ | ✅ | ✅ |
1043
+ | Sweego | ✅ | ✅ | ✅ | ✅ |
1044
+ | SendGrid | ✅ | ✅ | ✅ | ✅ |
1045
+ | Plunk | ✅ | ✅ | ✅ | ✅ |
1046
+ | Mock | ✅ | ✅ | ✅ | ✅ |
1047
+ | AWS SES | ✅ | ❌ | ❌ | ❌ |
1048
+ | SMTP | ✅ | ❌ | ❌ | ❌ |
1049
+ | MailCrab | ✅ | ❌ | ❌ | ❌ |
1050
+ | Nodemailer | ✅ | ❌ | ❌ | ❌ |
1051
+ | Failover | ✅\* | ✅\* | ✅\* | ✅\* |
1052
+ | Round Robin | ✅\* | ✅\* | ✅\* | ✅\* |
1053
+ | OpenTelemetry | ✅\* | ✅\* | ✅\* | ✅\* |
1054
+
1055
+ \* Runtime support depends on the wrapped providers. Works if all wrapped providers support the runtime.
1056
+
1057
+ ## Related
1058
+
1059
+ ## Supported Node.js Versions
1060
+
1061
+ Libraries in this ecosystem make the best effort to track [Node.js' release schedule](https://github.com/nodejs/release#release-schedule).
1062
+ Here's [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
1063
+
1064
+ ## Contributing
1065
+
1066
+ If you would like to help take a look at the [list of issues](https://github.com/visulima/visulima/issues) and check our [Contributing](.github/CONTRIBUTING.md) guidelines.
1067
+
1068
+ > **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
1069
+
1070
+ ## Credits
1071
+
1072
+ - [Daniel Bannert](https://github.com/prisis)
1073
+ - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
1074
+
1075
+ ## License
1076
+
1077
+ The visulima email is open-sourced software licensed under the [MIT][license-url]
1078
+
1079
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
1080
+ [typescript-url]: https://www.typescriptlang.org/ "TypeScript"
1081
+ [license-image]: https://img.shields.io/npm/l/@visulima/email?color=blueviolet&style=for-the-badge
1082
+ [license-url]: LICENSE.md "license"
1083
+ [npm-image]: https://img.shields.io/npm/v/@visulima/email/latest.svg?style=for-the-badge&logo=npm
1084
+ [npm-url]: https://www.npmjs.com/package/@visulima/email/v/latest "npm"