@upyo/mailgun 0.1.0-dev.10 → 0.1.0-dev.12
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/README.md +29 -12
- package/dist/index.cjs +6 -6
- package/dist/index.js +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
@upyo/mailgun
|
|
4
4
|
=============
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
7
8
|
|
|
9
|
+
[Mailgun] transport for the [Upyo] email library.
|
|
10
|
+
|
|
11
|
+
[JSR]: https://jsr.io/@upyo/mailgun
|
|
12
|
+
[JSR badge]: https://jsr.io/badges/@upyo/mailgun
|
|
13
|
+
[npm]: https://www.npmjs.com/package/@upyo/mailgun
|
|
14
|
+
[npm badge]: https://img.shields.io/npm/v/@upyo/mailgun?logo=npm
|
|
8
15
|
[Mailgun]: https://www.mailgun.com/
|
|
16
|
+
[Upyo]: https://upyo.org/
|
|
9
17
|
|
|
10
18
|
|
|
11
19
|
Installation
|
|
@@ -24,22 +32,31 @@ Usage
|
|
|
24
32
|
-----
|
|
25
33
|
|
|
26
34
|
~~~~ typescript
|
|
27
|
-
import {
|
|
35
|
+
import { createMessage } from "@upyo/core";
|
|
36
|
+
import { MailgunTransport } from "@upyo/mailgun";
|
|
37
|
+
import fs from "node:fs/promises";
|
|
38
|
+
import process from "node:process";
|
|
39
|
+
|
|
40
|
+
const message = createMessage({
|
|
41
|
+
from: "sender@example.com",
|
|
42
|
+
to: "recipient@example.net",
|
|
43
|
+
subject: "Hello from Upyo!",
|
|
44
|
+
content: { text: "This is a test email." },
|
|
45
|
+
attachments: [
|
|
46
|
+
new File(
|
|
47
|
+
[await fs.readFile("image.jpg"), "image.jpg", { type: "image/jpeg" }]
|
|
48
|
+
)
|
|
49
|
+
],
|
|
50
|
+
});
|
|
28
51
|
|
|
29
52
|
const transport = new MailgunTransport({
|
|
30
|
-
apiKey:
|
|
31
|
-
domain:
|
|
53
|
+
apiKey: process.env.MAILGUN_KEY!,
|
|
54
|
+
domain: process.env.MAILGUN_DOMAIN!,
|
|
55
|
+
region: process.env.MAILGUN_REGION as "us" | "eu",
|
|
32
56
|
});
|
|
33
57
|
|
|
34
|
-
const message = {
|
|
35
|
-
sender: { address: 'sender@example.com' },
|
|
36
|
-
recipients: [{ address: 'recipient@example.com' }],
|
|
37
|
-
subject: 'Hello from Mailgun!',
|
|
38
|
-
content: { text: 'Hello, World!' }
|
|
39
|
-
};
|
|
40
|
-
|
|
41
58
|
const receipt = await transport.send(message);
|
|
42
|
-
console.log(
|
|
59
|
+
console.log("Email sent:", receipt.successful);
|
|
43
60
|
~~~~
|
|
44
61
|
|
|
45
62
|
|
package/dist/index.cjs
CHANGED
|
@@ -162,11 +162,11 @@ var MailgunApiError = class extends Error {
|
|
|
162
162
|
*
|
|
163
163
|
* @example
|
|
164
164
|
* ```typescript
|
|
165
|
-
* const formData = convertMessage(message, config);
|
|
165
|
+
* const formData = await convertMessage(message, config);
|
|
166
166
|
* const response = await fetch(url, { method: 'POST', body: formData });
|
|
167
167
|
* ```
|
|
168
168
|
*/
|
|
169
|
-
function convertMessage(message, config) {
|
|
169
|
+
async function convertMessage(message, config) {
|
|
170
170
|
const formData = new FormData();
|
|
171
171
|
formData.append("from", formatAddress(message.sender));
|
|
172
172
|
for (const recipient of message.recipients) formData.append("to", formatAddress(recipient));
|
|
@@ -191,7 +191,7 @@ function convertMessage(message, config) {
|
|
|
191
191
|
}
|
|
192
192
|
for (const tag of message.tags) formData.append("o:tag", tag);
|
|
193
193
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) formData.append(`h:${key}`, value);
|
|
194
|
-
for (const attachment of message.attachments) appendAttachment(formData, attachment);
|
|
194
|
+
for (const attachment of message.attachments) await appendAttachment(formData, attachment);
|
|
195
195
|
if (config.tracking !== void 0) formData.append("o:tracking", config.tracking ? "yes" : "no");
|
|
196
196
|
if (config.clickTracking !== void 0) formData.append("o:tracking-clicks", config.clickTracking ? "yes" : "no");
|
|
197
197
|
if (config.openTracking !== void 0) formData.append("o:tracking-opens", config.openTracking ? "yes" : "no");
|
|
@@ -216,8 +216,8 @@ function formatAddress(address) {
|
|
|
216
216
|
* @param formData - The FormData to append to
|
|
217
217
|
* @param attachment - The attachment to append
|
|
218
218
|
*/
|
|
219
|
-
function appendAttachment(formData, attachment) {
|
|
220
|
-
const blob = new Blob([attachment.content], { type: attachment.contentType });
|
|
219
|
+
async function appendAttachment(formData, attachment) {
|
|
220
|
+
const blob = new Blob([await attachment.content], { type: attachment.contentType });
|
|
221
221
|
if (attachment.contentId) formData.append("inline", blob, attachment.filename);
|
|
222
222
|
else formData.append("attachment", blob, attachment.filename);
|
|
223
223
|
}
|
|
@@ -314,7 +314,7 @@ var MailgunTransport = class {
|
|
|
314
314
|
async send(message, options) {
|
|
315
315
|
options?.signal?.throwIfAborted();
|
|
316
316
|
try {
|
|
317
|
-
const formData = convertMessage(message, this.config);
|
|
317
|
+
const formData = await convertMessage(message, this.config);
|
|
318
318
|
options?.signal?.throwIfAborted();
|
|
319
319
|
const response = await this.httpClient.sendMessage(formData, options?.signal);
|
|
320
320
|
return {
|
package/dist/index.js
CHANGED
|
@@ -161,11 +161,11 @@ var MailgunApiError = class extends Error {
|
|
|
161
161
|
*
|
|
162
162
|
* @example
|
|
163
163
|
* ```typescript
|
|
164
|
-
* const formData = convertMessage(message, config);
|
|
164
|
+
* const formData = await convertMessage(message, config);
|
|
165
165
|
* const response = await fetch(url, { method: 'POST', body: formData });
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
|
-
function convertMessage(message, config) {
|
|
168
|
+
async function convertMessage(message, config) {
|
|
169
169
|
const formData = new FormData();
|
|
170
170
|
formData.append("from", formatAddress(message.sender));
|
|
171
171
|
for (const recipient of message.recipients) formData.append("to", formatAddress(recipient));
|
|
@@ -190,7 +190,7 @@ function convertMessage(message, config) {
|
|
|
190
190
|
}
|
|
191
191
|
for (const tag of message.tags) formData.append("o:tag", tag);
|
|
192
192
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) formData.append(`h:${key}`, value);
|
|
193
|
-
for (const attachment of message.attachments) appendAttachment(formData, attachment);
|
|
193
|
+
for (const attachment of message.attachments) await appendAttachment(formData, attachment);
|
|
194
194
|
if (config.tracking !== void 0) formData.append("o:tracking", config.tracking ? "yes" : "no");
|
|
195
195
|
if (config.clickTracking !== void 0) formData.append("o:tracking-clicks", config.clickTracking ? "yes" : "no");
|
|
196
196
|
if (config.openTracking !== void 0) formData.append("o:tracking-opens", config.openTracking ? "yes" : "no");
|
|
@@ -215,8 +215,8 @@ function formatAddress(address) {
|
|
|
215
215
|
* @param formData - The FormData to append to
|
|
216
216
|
* @param attachment - The attachment to append
|
|
217
217
|
*/
|
|
218
|
-
function appendAttachment(formData, attachment) {
|
|
219
|
-
const blob = new Blob([attachment.content], { type: attachment.contentType });
|
|
218
|
+
async function appendAttachment(formData, attachment) {
|
|
219
|
+
const blob = new Blob([await attachment.content], { type: attachment.contentType });
|
|
220
220
|
if (attachment.contentId) formData.append("inline", blob, attachment.filename);
|
|
221
221
|
else formData.append("attachment", blob, attachment.filename);
|
|
222
222
|
}
|
|
@@ -313,7 +313,7 @@ var MailgunTransport = class {
|
|
|
313
313
|
async send(message, options) {
|
|
314
314
|
options?.signal?.throwIfAborted();
|
|
315
315
|
try {
|
|
316
|
-
const formData = convertMessage(message, this.config);
|
|
316
|
+
const formData = await convertMessage(message, this.config);
|
|
317
317
|
options?.signal?.throwIfAborted();
|
|
318
318
|
const response = await this.httpClient.sendMessage(formData, options?.signal);
|
|
319
319
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/mailgun",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.12+d36debdf",
|
|
4
4
|
"description": "Mailgun transport for Upyo email library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@upyo/core": "0.1.0-dev.
|
|
56
|
+
"@upyo/core": "0.1.0-dev.12+d36debdf"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@dotenvx/dotenvx": "^1.47.3",
|