emailjs 4.0.3 โ 5.0.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.
- package/README.md +215 -247
- package/dist/address.d.ts +6 -0
- package/dist/address.js +183 -0
- package/dist/address.js.map +1 -0
- package/dist/address.test.d.ts +1 -0
- package/dist/address.test.js +120 -0
- package/dist/address.test.js.map +1 -0
- package/dist/auth.integration.test.d.ts +1 -0
- package/dist/auth.integration.test.js +137 -0
- package/dist/auth.integration.test.js.map +1 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.integration.test.d.ts +1 -0
- package/dist/client.integration.test.js +198 -0
- package/dist/client.integration.test.js.map +1 -0
- package/dist/client.js +202 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +293 -0
- package/dist/client.test.js.map +1 -0
- package/dist/connection.commands.integration.test.d.ts +1 -0
- package/dist/connection.commands.integration.test.js +79 -0
- package/dist/connection.commands.integration.test.js.map +1 -0
- package/dist/connection.d.ts +83 -0
- package/dist/connection.errors.integration.test.d.ts +1 -0
- package/dist/connection.errors.integration.test.js +186 -0
- package/dist/connection.errors.integration.test.js.map +1 -0
- package/dist/connection.greylist.integration.test.d.ts +1 -0
- package/dist/connection.greylist.integration.test.js +53 -0
- package/dist/connection.greylist.integration.test.js.map +1 -0
- package/dist/connection.integration.test.d.ts +1 -0
- package/dist/connection.integration.test.js +223 -0
- package/dist/connection.integration.test.js.map +1 -0
- package/dist/connection.js +492 -0
- package/dist/connection.js.map +1 -0
- package/dist/connection.test.d.ts +1 -0
- package/dist/connection.test.js +50 -0
- package/dist/connection.test.js.map +1 -0
- package/dist/date.d.ts +3 -0
- package/dist/date.js +26 -0
- package/dist/date.js.map +1 -0
- package/dist/date.test.d.ts +1 -0
- package/dist/date.test.js +26 -0
- package/dist/date.test.js.map +1 -0
- package/dist/error.d.ts +20 -0
- package/dist/error.js +31 -0
- package/dist/error.js.map +1 -0
- package/dist/error.test.d.ts +1 -0
- package/dist/error.test.js +23 -0
- package/dist/error.test.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/message.d.ts +71 -0
- package/dist/message.integration.test.d.ts +1 -0
- package/dist/message.integration.test.js +401 -0
- package/dist/message.integration.test.js.map +1 -0
- package/dist/message.js +456 -0
- package/dist/message.js.map +1 -0
- package/dist/message.test.d.ts +1 -0
- package/dist/message.test.js +258 -0
- package/dist/message.test.js.map +1 -0
- package/dist/mime.d.ts +2 -0
- package/dist/mime.js +145 -0
- package/dist/mime.js.map +1 -0
- package/dist/mime.test.d.ts +1 -0
- package/dist/mime.test.js +76 -0
- package/dist/mime.test.js.map +1 -0
- package/dist/response.d.ts +6 -0
- package/dist/response.js +93 -0
- package/dist/response.js.map +1 -0
- package/dist/response.test.d.ts +1 -0
- package/dist/response.test.js +177 -0
- package/dist/response.test.js.map +1 -0
- package/package.json +30 -28
- package/email.js +0 -2126
- package/email.ts +0 -8
- package/smtp/address.ts +0 -237
- package/smtp/client.ts +0 -365
- package/smtp/connection.ts +0 -937
- package/smtp/date.ts +0 -51
- package/smtp/error.ts +0 -57
- package/smtp/message.ts +0 -774
- package/smtp/mime.ts +0 -234
- package/smtp/response.ts +0 -112
package/README.md
CHANGED
|
@@ -1,320 +1,288 @@
|
|
|
1
|
-
# emailjs
|
|
1
|
+
# emailjs ๐งโจ
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Send emails with ease!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This library lets you send rich HTML emails,
|
|
6
|
+
attachments (from files, streams, or strings), and plain text messages to any
|
|
7
|
+
SMTP server.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
[](https://github.com/eleith/emailjs/actions/workflows/check.yml)
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## What's to expect from emailjs? ๐
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
* **SSL and TLS Support:** Secure connections to your SMTP servers.
|
|
14
|
+
* **Authentication Galore:** Supports popular SMTP authentication methods like
|
|
15
|
+
`PLAIN`, `LOGIN`, `CRAM-MD5`, and `XOAUTH2`.
|
|
16
|
+
* **Asynchronous Sending:** Emails are queued and sent in the
|
|
17
|
+
background.
|
|
18
|
+
* **Rich Content:** Send HTML emails and include multiple attachments.
|
|
19
|
+
* **Flexible Attachments:** Attachments can be files, data streams, or plain
|
|
20
|
+
strings.
|
|
21
|
+
* **UTF-8 Ready:** Full support for UTF-8 in headers and body.
|
|
22
|
+
* **Built-in Type Declarations:** first-class TypeScript support.
|
|
23
|
+
* **Greylisting Awareness:** Automatically handles
|
|
24
|
+
[greylisting](http://projects.puremagic.com/greylisting/whitepaper.html) to
|
|
25
|
+
improve deliverability.
|
|
19
26
|
|
|
20
|
-
##
|
|
27
|
+
## Get Started! ๐ ๏ธ
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
- if your service (ex: gmail) uses two-step authentication, use an application specific password
|
|
29
|
+
### Installing
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
It's super simple!
|
|
26
32
|
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const client = new SMTPClient({
|
|
31
|
-
user: 'user',
|
|
32
|
-
password: 'password',
|
|
33
|
-
host: 'smtp.your-email.com',
|
|
34
|
-
ssl: true,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// send the message and get a callback with an error or details of the message that was sent
|
|
38
|
-
client.send(
|
|
39
|
-
{
|
|
40
|
-
text: 'i hope this works',
|
|
41
|
-
from: 'you <username@your-email.com>',
|
|
42
|
-
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
|
|
43
|
-
cc: 'else <else@your-email.com>',
|
|
44
|
-
subject: 'testing emailjs',
|
|
45
|
-
},
|
|
46
|
-
(err, message) => {
|
|
47
|
-
console.log(err || message);
|
|
48
|
-
}
|
|
49
|
-
);
|
|
33
|
+
```bash
|
|
34
|
+
npm install emailjs
|
|
50
35
|
```
|
|
51
36
|
|
|
52
|
-
|
|
37
|
+
### Requirements
|
|
53
38
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
* Access to an SMTP Server.
|
|
40
|
+
* If your email service (like Gmail) uses two-step verification, you'll need an
|
|
41
|
+
application-specific password.
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
user: 'user',
|
|
60
|
-
password: 'password',
|
|
61
|
-
host: 'smtp.your-email.com',
|
|
62
|
-
ssl: true,
|
|
63
|
-
});
|
|
43
|
+
### Quick Examples ๐งโ๐ป
|
|
64
44
|
|
|
65
|
-
|
|
66
|
-
const message = await client.sendAsync({
|
|
67
|
-
text: 'i hope this works',
|
|
68
|
-
from: 'you <username@your-email.com>',
|
|
69
|
-
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
|
|
70
|
-
cc: 'else <else@your-email.com>',
|
|
71
|
-
subject: 'testing emailjs',
|
|
72
|
-
});
|
|
73
|
-
console.log(message);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
console.error(err);
|
|
76
|
-
}
|
|
77
|
-
```
|
|
45
|
+
Here's how easy it is to send emails:
|
|
78
46
|
|
|
79
|
-
|
|
47
|
+
#### Text-Only Emails
|
|
80
48
|
|
|
81
|
-
```
|
|
49
|
+
```javascript
|
|
82
50
|
import { SMTPClient } from 'emailjs';
|
|
83
51
|
|
|
84
52
|
const client = new SMTPClient({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
53
|
+
user: 'your-username',
|
|
54
|
+
password: 'your-password',
|
|
55
|
+
host: 'smtp.your-email.com',
|
|
56
|
+
ssl: true, // Use SSL for secure connection
|
|
89
57
|
});
|
|
90
58
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// you can continue to send more messages with successive calls to 'client.send',
|
|
109
|
-
// they will be queued on the same smtp connection
|
|
59
|
+
async function sendMyEmail() {
|
|
60
|
+
try {
|
|
61
|
+
const message = await client.sendAsync({
|
|
62
|
+
text: 'Hello from emailjs! This is a test message.',
|
|
63
|
+
from: 'You <your-email@example.com>',
|
|
64
|
+
to: 'Someone <someone@example.com>',
|
|
65
|
+
subject: 'Exciting News from emailjs! ๐',
|
|
66
|
+
});
|
|
67
|
+
console.log('Email sent successfully:', message);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error('Failed to send email:', err);
|
|
70
|
+
} finally {
|
|
71
|
+
client.smtp.close(); // Don't forget to close the connection!
|
|
72
|
+
}
|
|
73
|
+
}
|
|
110
74
|
|
|
111
|
-
|
|
75
|
+
sendMyEmail();
|
|
112
76
|
```
|
|
113
77
|
|
|
114
|
-
|
|
78
|
+
#### HTML Emails & Attachments
|
|
115
79
|
|
|
116
|
-
```
|
|
80
|
+
```javascript
|
|
117
81
|
import { SMTPClient, Message } from 'emailjs';
|
|
118
82
|
|
|
119
83
|
const client = new SMTPClient({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
ciphers: 'SSLv3',
|
|
125
|
-
},
|
|
84
|
+
user: 'your-username',
|
|
85
|
+
password: 'your-password',
|
|
86
|
+
host: 'smtp.your-email.com',
|
|
87
|
+
tls: true,
|
|
126
88
|
});
|
|
127
89
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
90
|
+
async function sendRichEmail() {
|
|
91
|
+
const htmlContent = `
|
|
92
|
+
<h1>Greetings!</h1>
|
|
93
|
+
<p>This is an <b>HTML email</b> with a lovely picture and an attachment.</p>
|
|
94
|
+
<img src="cid:my-image" alt="Embedded Image" width="150" height="100">
|
|
95
|
+
<p>Check out the attached file!</p>
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
const message = new Message({
|
|
99
|
+
from: 'You <your-email@example.com>',
|
|
100
|
+
to: 'Someone <someone@example.com>',
|
|
101
|
+
subject: 'Your Awesome HTML Email! ๐ผ๏ธ๐',
|
|
102
|
+
attachment: [
|
|
103
|
+
{
|
|
104
|
+
data: htmlContent,
|
|
105
|
+
alternative: true, // This part is the HTML body
|
|
106
|
+
contentType: 'text/html',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
path: 'path/to/your/document.pdf', // Attach a file from disk
|
|
110
|
+
type: 'application/pdf',
|
|
111
|
+
name: 'document.pdf',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
path: 'path/to/your/image.jpg', // Embed an image for the HTML
|
|
115
|
+
type: 'image/jpeg',
|
|
116
|
+
name: 'cool_image.jpg',
|
|
117
|
+
// Reference in HTML with cid:my-image
|
|
118
|
+
headers: { 'Content-ID': '<my-image>' },
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await client.sendAsync(message);
|
|
125
|
+
console.log('Rich email sent successfully!');
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.error('Failed to send rich email:', err);
|
|
128
|
+
} finally {
|
|
129
|
+
client.smtp.close();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
139
132
|
|
|
140
|
-
|
|
141
|
-
client.send(message, (err, message) => {
|
|
142
|
-
console.log(err || message);
|
|
143
|
-
});
|
|
133
|
+
sendRichEmail();
|
|
144
134
|
```
|
|
145
135
|
|
|
146
|
-
##
|
|
136
|
+
## API Reference ๐
|
|
147
137
|
|
|
148
|
-
|
|
149
|
-
|
|
138
|
+
The `emailjs` library is fully typed, here is a brief overview of most likely to
|
|
139
|
+
be used methods
|
|
150
140
|
|
|
151
|
-
|
|
152
|
-
user: 'user',
|
|
153
|
-
password: 'password',
|
|
154
|
-
host: 'smtp-mail.outlook.com',
|
|
155
|
-
tls: {
|
|
156
|
-
ciphers: 'SSLv3',
|
|
157
|
-
},
|
|
158
|
-
});
|
|
141
|
+
### `new SMTPClient(options)`
|
|
159
142
|
|
|
160
|
-
|
|
161
|
-
text: 'i hope this works',
|
|
162
|
-
from: 'you <username@outlook.com>',
|
|
163
|
-
to: 'someone <someone@your-email.com>, another <another@your-email.com>',
|
|
164
|
-
cc: 'else <else@your-email.com>',
|
|
165
|
-
subject: 'testing emailjs',
|
|
166
|
-
attachment: [
|
|
167
|
-
{
|
|
168
|
-
data:
|
|
169
|
-
'<html>i <i>hope</i> this works! here is an image: <img src="cid:my-image" width="100" height ="50"> </html>',
|
|
170
|
-
},
|
|
171
|
-
{ path: 'path/to/file.zip', type: 'application/zip', name: 'renamed.zip' },
|
|
172
|
-
{
|
|
173
|
-
path: 'path/to/image.jpg',
|
|
174
|
-
type: 'image/jpg',
|
|
175
|
-
headers: { 'Content-ID': '<my-image>' },
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
});
|
|
143
|
+
Create a new client instance to connect to your SMTP server.
|
|
179
144
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
145
|
+
```javascript
|
|
146
|
+
const options = {
|
|
147
|
+
user: 'your-username', // ๐ Username for logging into SMTP
|
|
148
|
+
password: 'your-password', // ๐คซ Password for logging into SMTP
|
|
149
|
+
host: 'smtp.your-email.com', // ๐ SMTP server host (defaults to 'localhost')
|
|
150
|
+
port: 587, // ๐ SMTP port (defaults: 25 unencrypted, 465 SSL, 587 TLS)
|
|
151
|
+
ssl: true, // ๐ Boolean or object for immediate SSL connection
|
|
152
|
+
tls: true, // ๐ Boolean or object (see typescript types) to initiate STARTTLS
|
|
153
|
+
timeout: 5000, // โณ Max milliseconds to wait for SMTP responses
|
|
154
|
+
domain: 'your-domain.com', // ๐ Domain to greet SMTP with (defaults to os.hostname)
|
|
155
|
+
authentication: ['PLAIN', 'LOGIN'], // ๐ค Preferred authentication methods
|
|
156
|
+
logger: console, // ๐ Override the built-in logger (e.g., custom logging)
|
|
157
|
+
};
|
|
184
158
|
```
|
|
185
159
|
|
|
186
|
-
#
|
|
160
|
+
### `SMTPClient#send(message, callback)`
|
|
187
161
|
|
|
188
|
-
|
|
162
|
+
Sends an email message. You can pass a `Message` instance or a headers object.
|
|
189
163
|
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
host, // smtp host (defaults to 'localhost')
|
|
196
|
-
port, // smtp port (defaults to 25 for unencrypted, 465 for `ssl`, and 587 for `tls`)
|
|
197
|
-
ssl, // boolean or object (if true or object, ssl connection will be made)
|
|
198
|
-
tls, // boolean or object (if true or object, starttls will be initiated)
|
|
199
|
-
timeout, // max number of milliseconds to wait for smtp responses (defaults to 5000)
|
|
200
|
-
domain, // domain to greet smtp with (defaults to os.hostname)
|
|
201
|
-
authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
|
|
202
|
-
logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
|
|
203
|
-
};
|
|
204
|
-
// ssl/tls objects are an abbreviated form of [`tls.connect`](https://nodejs.org/dist/latest-v14.x/docs/api/tls.html#tls_tls_connect_options_callback)'s options
|
|
205
|
-
// the missing items are: `port`, `host`, `path`, `socket`, `timeout` and `secureContext`
|
|
206
|
-
// NOTE: `host` is trimmed before being used to establish a connection;
|
|
207
|
-
// however, the original untrimmed value will still be visible in configuration.
|
|
164
|
+
```javascript
|
|
165
|
+
client.send(messageObject, (err, details) => {
|
|
166
|
+
if (err) console.error(err);
|
|
167
|
+
else console.log('Message sent:', details);
|
|
168
|
+
});
|
|
208
169
|
```
|
|
209
170
|
|
|
210
|
-
|
|
171
|
+
### `SMTPClient#sendAsync(message)`
|
|
211
172
|
|
|
212
|
-
|
|
213
|
-
// message can be a smtp.Message (as returned by email.message.create)
|
|
214
|
-
// or an object identical to the first argument accepted by email.message.create
|
|
173
|
+
a promise-based way to send emails! โจ
|
|
215
174
|
|
|
216
|
-
|
|
217
|
-
|
|
175
|
+
```javascript
|
|
176
|
+
try {
|
|
177
|
+
const details = await client.sendAsync(messageObject);
|
|
178
|
+
console.log('Message sent:', details);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
console.error('Failed to send:', err);
|
|
181
|
+
}
|
|
218
182
|
```
|
|
219
183
|
|
|
220
|
-
|
|
184
|
+
### `new Message(headers)`
|
|
185
|
+
|
|
186
|
+
Constructs an RFC2822-compliant message object.
|
|
221
187
|
|
|
222
|
-
```
|
|
223
|
-
// headers is an object with the following recognized schema:
|
|
188
|
+
```javascript
|
|
224
189
|
const headers = {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
190
|
+
from: 'sender@example.com', // ๐ Sender (required!)
|
|
191
|
+
to: 'recipient@example.com', // ๐ฌ Recipients (at least one of to, cc, or bcc)
|
|
192
|
+
cc: 'carbon-copy@example.com', // ๐ฅ CC recipients
|
|
193
|
+
bcc: 'blind-copy@example.com', // ๐ต๏ธโโ๏ธ BCC recipients
|
|
194
|
+
subject: 'Your Subject Here', // ๐ Email subject
|
|
195
|
+
text: 'Plain text body.', // ๐๏ธ Plain text content
|
|
196
|
+
attachment: [{ data: 'Hello!' }], // ๐ One or more attachments
|
|
232
197
|
};
|
|
233
|
-
// the `from` field is required.
|
|
234
|
-
// at least one `to`, `cc`, or `bcc` header is also required.
|
|
235
|
-
// you can also add whatever other headers you want.
|
|
236
198
|
```
|
|
237
199
|
|
|
238
|
-
|
|
200
|
+
### `Message#attach(options)`
|
|
239
201
|
|
|
240
|
-
Can be called multiple times
|
|
202
|
+
Adds an attachment to the message. Can be called multiple times.
|
|
241
203
|
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
type, // string of the file mime type
|
|
254
|
-
name, // name to give the file as perceived by the recipient
|
|
255
|
-
charset, // charset to encode attatchment in
|
|
256
|
-
method, // method to send attachment as (used by calendar invites)
|
|
257
|
-
alternative, // if true, will be attached inline as an alternative (also defaults type='text/html')
|
|
258
|
-
inline, // if true, will be attached inline
|
|
259
|
-
encoded, // set this to true if the data is already base64 encoded, (avoid this if possible)
|
|
260
|
-
headers, // object containing header=>value pairs for inclusion in this attachment's header
|
|
261
|
-
related, // an array of attachments that you want to be related to the parent attachment
|
|
262
|
-
};
|
|
204
|
+
```javascript
|
|
205
|
+
message.attach({
|
|
206
|
+
path: 'path/to/file.zip', // ๐ Path to a file on disk
|
|
207
|
+
data: 'Binary content as string or buffer', // ๐ Raw data
|
|
208
|
+
stream: fs.createReadStream('file.jpg'), // ๐ A readable stream
|
|
209
|
+
type: 'application/zip', // MIME type
|
|
210
|
+
name: 'custom-name.zip', // Filename perceived by recipient
|
|
211
|
+
alternative: true, // attach inline as an alternative (e.g., HTML body)
|
|
212
|
+
inline: true, // If true, attached inline (e.g., for <img src="cid:...">)
|
|
213
|
+
headers: { 'X-Custom-Header': 'value' }, // Custom attachment headers
|
|
214
|
+
});
|
|
263
215
|
```
|
|
264
216
|
|
|
265
|
-
|
|
217
|
+
### `Message#checkValidity()`
|
|
266
218
|
|
|
267
|
-
Synchronously
|
|
219
|
+
Synchronously validates that a `Message` is properly formed before sending.
|
|
268
220
|
|
|
269
|
-
```
|
|
270
|
-
const message = new Message(options);
|
|
221
|
+
```javascript
|
|
271
222
|
const { isValid, validationError } = message.checkValidity();
|
|
272
|
-
if (isValid) {
|
|
273
|
-
|
|
274
|
-
} else {
|
|
275
|
-
// first error encountered
|
|
276
|
-
console.error(validationError);
|
|
223
|
+
if (!isValid) {
|
|
224
|
+
console.error('Message is invalid:', validationError);
|
|
277
225
|
}
|
|
278
226
|
```
|
|
279
227
|
|
|
280
|
-
##
|
|
228
|
+
## Authors โ๏ธ
|
|
281
229
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
authentication, // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
|
|
294
|
-
logger, // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
|
|
295
|
-
};
|
|
296
|
-
// ssl/tls objects are an abbreviated form of [`tls.connect`](https://nodejs.org/dist/latest-v14.x/docs/api/tls.html#tls_tls_connect_options_callback)'s options
|
|
297
|
-
// the missing items are: `port`, `host`, `path`, `socket`, `timeout` and `secureContext`
|
|
298
|
-
// NOTE: `host` is trimmed before being used to establish a connection;
|
|
299
|
-
// however, the original untrimmed value will still be visible in configuration.
|
|
230
|
+
* eleith
|
|
231
|
+
* zackschuster
|
|
232
|
+
|
|
233
|
+
## Testing ๐งช
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Run all tests
|
|
237
|
+
npm test
|
|
238
|
+
|
|
239
|
+
# Run tests with code coverage report
|
|
240
|
+
npm run test:coverage
|
|
300
241
|
```
|
|
301
242
|
|
|
302
|
-
|
|
243
|
+
## Development ๐งโ๐ป๐ฑ
|
|
244
|
+
|
|
245
|
+
for a local smtp testing experience, use our
|
|
246
|
+
[Mailpit](https://mailpit.axllent.org/) compose service
|
|
247
|
+
|
|
248
|
+
### 1. Start Mailpit with Docker Compose
|
|
249
|
+
|
|
250
|
+
Ensure you have Docker and Docker Compose installed.
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# From the project root, start Mailpit
|
|
254
|
+
docker compose up
|
|
255
|
+
```
|
|
303
256
|
|
|
304
|
-
|
|
257
|
+
Mailpit will be accessible via:
|
|
305
258
|
|
|
306
|
-
|
|
259
|
+
* **Web UI:** `http://localhost:8025`
|
|
260
|
+
* **SMTP Server:** `localhost:1025`
|
|
307
261
|
|
|
308
|
-
|
|
262
|
+
### 2. Run Example Sending Scripts
|
|
309
263
|
|
|
310
|
-
|
|
311
|
-
|
|
264
|
+
You can use the provided scripts to send different types of emails to your local
|
|
265
|
+
Mailpit instance.
|
|
312
266
|
|
|
313
|
-
|
|
267
|
+
First, make sure the `emailjs` library is built:
|
|
314
268
|
|
|
315
|
-
|
|
316
|
-
|
|
269
|
+
```bash
|
|
270
|
+
npm run build
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Then, run any of the example scripts:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Send a plain text email
|
|
277
|
+
node scripts/send-text.js
|
|
278
|
+
|
|
279
|
+
# Send an HTML email
|
|
280
|
+
node scripts/send-html.js
|
|
281
|
+
|
|
282
|
+
# Send an email with attachments
|
|
283
|
+
node scripts/send-attachment.js
|
|
284
|
+
```
|
|
317
285
|
|
|
318
|
-
|
|
286
|
+
After running a script, open your Mailpit Web UI (`http://localhost:8025`) to
|
|
287
|
+
see the emails stream in! ๐ฉ
|
|
319
288
|
|
|
320
|
-
issues and pull requests are welcome
|