Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 524 lines (385 sloc) 19.769 kb
ca1f7d8 v0.1
andris9 authored
1 Nodemailer
2 ==========
3
3c3cca5 updated readme
Andris Reinman authored
4 **Nodemailer** is an easy to use module to send e-mails with Node.JS (using
21c545d Andris Reinman Update README.md
authored
5 SMTP or sendmail or Amazon SES) and is unicode friendly - You can use any characters you like ✔
3c3cca5 updated readme
Andris Reinman authored
6
06eb6cb some minor housekeeping
Andris Reinman authored
7 Nodemailer is Windows friendly, you can install it with *npm* on Windows just like any other module, there are no compiled dependencies. Use it from Azure or from your Windows box hassle free.
8
cc5b5ae updated readme
Andris Reinman authored
9 Version v0.3 of Nodemailer is built from scratch and might break some existing scripts, so beware while upgrading. Nodemailer should be backwards compatible - if your script worked before, then it should work now, even if Nodemailer documentation differs from your code (method names, properties etc.).
93f2d1f Updated docs etc
Andris Reinman authored
10
3c3cca5 updated readme
Andris Reinman authored
11 Use [DocumentUp](http://documentup.com/andris9/nodemailer/) to read this README
12 in a more structured way (with TOC).
13
14 [![Build Status](https://secure.travis-ci.org/andris9/Nodemailer.png)](http://travis-ci.org/andris9/Nodemailer)
15
16 ## Nodemailer supports
17
18 * **Unicode** to use any characters
19 * **HTML content** as well as **plain text** alternative
20 * **Attachments** (including attachment **streaming** for sending larger files)
21 * **Embedded images** in HTML
efc9c37 updated readme
Andris Reinman authored
22 * **SSL/STARTTLS** for secure e-mail delivery
3c3cca5 updated readme
Andris Reinman authored
23 * Different transport methods - **SMTP**, **sendmail** and **Amazon SES**
efc9c37 updated readme
Andris Reinman authored
24 * SMTP **Connection pool** and connection reuse for rapid delivery
25 * **Preconfigured** services for using SMTP with Gmail, Hotmail etc.
21c545d Andris Reinman Update README.md
authored
26 * Use objects as header values for **SendGrid** SMTP API
a9acb36 Updated Readme
Andris Reinman authored
27 * **XOAUTH** authentication support and token generation (3-legged OAuth) - useful with Gmail
52cf687 Added DKIM signing support
Andris Reinman authored
28 * **DKIM** signing
3c3cca5 updated readme
Andris Reinman authored
29
30 ## Check out my other mail related modules
31
32 If you want to parse generated or received e-mail instead of sending it, check
33 out [MailParser](https://github.com/andris9/mailparser).
34
35 If you only want to generate the raw e-mail stream, check out
36 [MailComposer](https://github.com/andris9/mailcomposer).
37
38 If you only want to communicate with the SMTP (both as client and the server),
39 check out [simplesmtp](https://github.com/andris9/simplesmtp).
40
7b87567 Updated readme
Andris Reinman authored
41 ## Example
42
7782176 Updated readme
Andris Reinman authored
43 This is a complete example to send an e-mail with plaintext and HTML body
7b87567 Updated readme
Andris Reinman authored
44
45 var nodemailer = require("nodemailer");
46
0d22389 Andris Reinman Update README.md
authored
47 // create reusable transport method (opens pool of SMTP connections)
07db51a updated sending api, backwards compatible
Andris Reinman authored
48 var smtpTransport = nodemailer.createTransport("SMTP",{
7b87567 Updated readme
Andris Reinman authored
49 service: "Gmail",
50 auth: {
51 user: "gmail.user@gmail.com",
52 pass: "userpass"
53 }
54 });
55
1f6a511 Andris Reinman Update README.md
authored
56 // setup e-mail data with unicode symbols
7b87567 Updated readme
Andris Reinman authored
57 var mailOptions = {
0d22389 Andris Reinman Update README.md
authored
58 from: "Sender Name ✔ <sender@example.com>", // sender address
7b87567 Updated readme
Andris Reinman authored
59 to: "receiver1@example.com, receiver2@example.com", // list of receivers
0d22389 Andris Reinman Update README.md
authored
60 subject: "Hello ✔", // Subject line
61 text: "Hello world ✔", // plaintext body
62 html: "<b>Hello world ✔</b>" // html body
7b87567 Updated readme
Andris Reinman authored
63 }
64
07db51a updated sending api, backwards compatible
Andris Reinman authored
65 // send mail with defined transport object
0d22389 Andris Reinman Update README.md
authored
66 smtpTransport.sendMail(mailOptions, function(error, response){
7b87567 Updated readme
Andris Reinman authored
67 if(error){
68 console.log(error);
69 }else{
0d22389 Andris Reinman Update README.md
authored
70 console.log("Message sent: " + response.message);
7b87567 Updated readme
Andris Reinman authored
71 }
a8d5f64 Andris Reinman Update README.md
authored
72 smtpTransport.close(); // shut down the connection pool, no more messages
7b87567 Updated readme
Andris Reinman authored
73 });
74
4a35e99 Readme update
Andris Reinman authored
75 See also the [examples folder](https://github.com/andris9/Nodemailer/tree/master/examples)
c4cc33b Readme update
Andris Reinman authored
76 for full featured examples
4a35e99 Readme update
Andris Reinman authored
77
3c3cca5 updated readme
Andris Reinman authored
78 ## Installation
79
80 Install through NPM
81
82 npm install nodemailer
83
84 ## Usage
85
86 Include the module
87
88 var nodemailer = require("nodemailer");
89
07db51a updated sending api, backwards compatible
Andris Reinman authored
90 An e-mail can be sent with `sendMail(mailOptions[, callback])` command
3c3cca5 updated readme
Andris Reinman authored
91
07db51a updated sending api, backwards compatible
Andris Reinman authored
92 transport.sendMail(mailOptions, callback);
3c3cca5 updated readme
Andris Reinman authored
93
94 Where
95
eb7d4fd Andris Reinman Update README.md
authored
96 * `transport` is a transport method defined with `nodemailer.createTransport`
efc9c37 updated readme
Andris Reinman authored
97 * **mailOptions** defines the e-mail (set its subject, body text, receivers etc.), see **E-mail Message Fields** for details
98 * **callback** is the callback function that will be run after the e-mail is sent or the sending failed (see **Return callback** for details)
3c3cca5 updated readme
Andris Reinman authored
99
100 ## Setting up a transport method
101
d3c4871 Updated readme
Andris Reinman authored
102 Before you can send any e-mails you need to set up a transport method. This can
d768813 Changed new Transport to createTransport
Andris Reinman authored
103 be done with `nodemailer.createTransport(type, options)` where `type` indicates
e328b6d updated readme
Andris Reinman authored
104 the transport protocol and `options` defines how it is used.
3c3cca5 updated readme
Andris Reinman authored
105
d768813 Changed new Transport to createTransport
Andris Reinman authored
106 var transport = nodemailer.createTransport("SMTP", {smtp_options});
3c3cca5 updated readme
Andris Reinman authored
107
108 The same transport object can and should be reused several times.
109
eb7d4fd Andris Reinman Update README.md
authored
110 When the transport method is defined, it can be used to send e-mail with `sendMail`
3c3cca5 updated readme
Andris Reinman authored
111
d768813 Changed new Transport to createTransport
Andris Reinman authored
112 var transport = nodemailer.createTransport("SMTP", {smtp_options});
3c3cca5 updated readme
Andris Reinman authored
113
eb7d4fd Andris Reinman Update README.md
authored
114 transport.sendMail({
3c3cca5 updated readme
Andris Reinman authored
115 from: "sender@tr.ee",
40b7b48 Updated readme
Andris Reinman authored
116 to: "receiver@tr.ee"
117 ...
eb7d4fd Andris Reinman Update README.md
authored
118 });
3c3cca5 updated readme
Andris Reinman authored
119
120 ### Possible transport methods
121
40b7b48 Updated readme
Andris Reinman authored
122 Required `type` parameter can be one of the following:
3c3cca5 updated readme
Andris Reinman authored
123
124 * **SMTP** for using SMTP
125 * **SES** for using Amazon SES
126 * **Sendmail** for utilizing systems *sendmail* command
127
128 ### Setting up SMTP
129
130 SMTP is different from the other transport mechanisms, as in its case a connection
131 pool is created. All the connections try to stay alive as long as possible and
40b7b48 Updated readme
Andris Reinman authored
132 are reusable to minimize the protocol overhead delay - for example setting up
3c3cca5 updated readme
Andris Reinman authored
133 TLS for authenticating is relatively lengthy process (in CPU terms, not by human
134 terms), you do not want to do it several times.
135
136 Possible SMTP options are the following:
137
65cfdab Updated readme
Andris Reinman authored
138 * **service** - an optional well known service identifier ("Gmail", "Hotmail" etc., see **Well known Services** for a list of supported services) to auto-configure host, port and secure connection settings
3c3cca5 updated readme
Andris Reinman authored
139 * **host** - hostname of the SMTP server (defaults to "localhost", not needed with `service`)
140 * **port** - port of the SMTP server (defaults to 25, not needed with `service`)
9f30440 Updated README about secureConnection option
Andris Reinman authored
141 * **secureConnection** - use SSL (default is `false`, not needed with `service`). If you're using port 587 then keep `secureConnection` false, since the connection is started in insecure plain text mode and only later upgraded with STARTTLS
3c3cca5 updated readme
Andris Reinman authored
142 * **name** - the name of the client server (defaults to machine name)
c075b9b Added XOAuthToken auth option for Gmail XOAUTH support
Andris Reinman authored
143 * **auth** - authentication object as `{user:"...", pass:"..."}` or `{XOAuthToken: "base64data"}`
3c3cca5 updated readme
Andris Reinman authored
144 * **ignoreTLS** - ignore server support for STARTTLS (defaults to `false`)
145 * **debug** - output client and server messages to console
146 * **maxConnections** - how many connections to keep in the pool (defaults to 5)
147
148 Example:
149
d768813 Changed new Transport to createTransport
Andris Reinman authored
150 var transport = nodemailer.createTransport("SMTP", {
3c3cca5 updated readme
Andris Reinman authored
151 service: "Gmail",
152 auth: {
153 user: "gmail.user@gmail.com",
154 pass: "userpass"
155 }
156 });
157
4a35e99 Readme update
Andris Reinman authored
158 or the same without `service` parameter
159
d768813 Changed new Transport to createTransport
Andris Reinman authored
160 var transport = nodemailer.createTransport("SMTP", {
4a35e99 Readme update
Andris Reinman authored
161 host: "smtp.gmail.com", // hostname
162 secureConnection: true, // use SSL
163 port: 465, // port for secure SMTP
164 auth: {
165 user: "gmail.user@gmail.com",
166 pass: "userpass"
167 }
168 });
169
3c3cca5 updated readme
Andris Reinman authored
170 **NB!** if you want to close the pool (cancel all open connections) you can use
171 `transport.close()`
172
d768813 Changed new Transport to createTransport
Andris Reinman authored
173 var transport = nodemailer.createTransport("SMTP",{});
3c3cca5 updated readme
Andris Reinman authored
174 ...
175 transport.close(); // close the pool
176
26794a7 Fixed XOAUTH generator defaults bug, updated README
Andris Reinman authored
177
178 #### SMTP XOAUTH and token generation
179
180 **nodemailer** supports XOAUTH authentication for SMTP. To use this, include
181 `XOAuthToken` option in `auth` instead of the regular `user` and `pass`.
182
9fdff73 updated README
Andris Reinman authored
183 var transportOptions = {
26794a7 Fixed XOAUTH generator defaults bug, updated README
Andris Reinman authored
184 ...,
185 auth: {
186 XOAuthToken: "R0VUIGh0dHBzOi8vbWFpbC5nb29...."
187 }
188 }
189
190 **nodemailer** includes also built in XOAUTH token generator which can be used
191 with `nodemailer.createXOAuthGenerator()`. The function is preconfigured for
192 Gmail, so in this case only mandatory options are `user`, `token` and `tokenSecret`.
193
194 var XOAuthTokenGenerator = nodemailer.createXOAuthGenerator({
195 user: "test.nodemailer@gmail.com",
196 // requestUrl: "https://oauth.access.point",
197 // consumerKey: "anonymous",
198 // consumerSecret: "anonymous",
199 token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
200 tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c"
201 });
202
203 One of `user` or `requestUrl` is mandatory. `consumerKey` and `consumerSecret` both
204 default to `"anonymous"`.
205
9fdff73 updated README
Andris Reinman authored
206 var transportOptions = {
207 service: "Gmail",
26794a7 Fixed XOAUTH generator defaults bug, updated README
Andris Reinman authored
208 auth: {
209 XOAuthToken: nodemailer.createXOAuthGenerator({
210 user: "test.nodemailer@gmail.com",
211 token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
212 tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c"
213 });
214 }
215 }
216
3c3cca5 updated readme
Andris Reinman authored
217 ### Setting up SES
218
219 SES is actually a HTTP based protocol, the compiled e-mail and related info
220 (signatures and such) are sent as a HTTP request to SES servers.
221
222 Possible SES options are the following:
223
224 * **AWSAccessKeyID** - AWS access key (required)
225 * **AWSSecretKey** - AWS secret (required)
2685865 Updated readme
Andris Reinman authored
226 * **ServiceUrl** - optional API end point URL (defaults to *"https://email.us-east-1.amazonaws.com"*)
3c3cca5 updated readme
Andris Reinman authored
227
228 Example:
229
d768813 Changed new Transport to createTransport
Andris Reinman authored
230 var transport = nodemailer.createTransport("SES", {
3c3cca5 updated readme
Andris Reinman authored
231 AWSAccessKeyID: "AWSACCESSKEY",
232 AWSSecretKey: "AWS/Secret/key"
233 });
234
235 ### Setting up Sendmail
236
2685865 Updated readme
Andris Reinman authored
237 Sendmail transport method streams the compiled message to the *stdin* of *sendmail*
3c3cca5 updated readme
Andris Reinman authored
238 command.
239
240 Configuration is really easy, the options parameter is optional but you can
241 use it to define the path to the *sendmail* command
242
d768813 Changed new Transport to createTransport
Andris Reinman authored
243 var transport = nodemailer.createTransport("Sendmail", "/usr/bin/sendmail");
3c3cca5 updated readme
Andris Reinman authored
244
52cf687 Added DKIM signing support
Andris Reinman authored
245 ### DKIM Signing
246
247 **Nodemailer** supports DKIM signing with very simple setup. Use this with caution
248 though since the generated message needs to be buffered entirely before it can be
249 signed - in this case the streaming capability offered by mailcomposer is illusionary,
250 there will only be one `'data'` event with the entire message. Not a big deal with
251 small messages but might consume a lot of RAM when using larger attachments.
252
253 Set up the DKIM signing with `useDKIM` method for a transport object:
254
255 transport.useDKIM(dkimOptions)
256
257 Where `dkimOptions` includes necessary options for signing
258
259 * **domainName** - the domainname that is being used for signing
260 * **keySelector** - key selector. If you have set up a TXT record with DKIM public key at *zzz._domainkey.example.com* then `zzz` is the selector
261 * **privateKey** - DKIM private key that is used for signing as a string
262 * **headerFieldNames** - optional colon separated list of header fields to sign, by default all fields suggested by RFC4871 #5.5 are used
263
264 All messages transmitted through this transport objects are from now on DKIM signed.
265
266 **NB!** Currently if several header fields with the same name exists, only the last one (the one in the bottom) is signed.
267
268 Example:
269
270 var transport = nodemailer.createTransport("Sendmail");
271
272 transport.useDKIM({
273 domainName: "node.ee",
274 keySelector: "dkim",
275 privateKey: fs.readFileSync("private_key.pem")
276 });
277
278 transport.sendMail(mailOptions);
279
280 See examples/example_dkim.js for a complete example.
281
3c3cca5 updated readme
Andris Reinman authored
282 ### Well known services for SMTP
93f2d1f Updated docs etc
Andris Reinman authored
283
284 If you want to use a well known service as the SMTP host, you do not need
5fef793 readme update
Andris Reinman authored
285 to enter the hostname or port number, just use the `service` parameter (**NB!** case sensitive).
93f2d1f Updated docs etc
Andris Reinman authored
286
287 Currently cupported services are:
288
289 * **"Gmail"** for Google Mail
290 * **"hot.ee"** for www.hot.ee
291 * **"Hotmail"** for Microsoft Live Hotmail
292 * **"iCloud"** for Apple iCloud
293 * **"mail.ee"** for www.mail.ee
294 * **"Postmark"** for Postmark App
295 * **"SendGrid"** for SendGrid
296 * **"SES"** for Amazon SES
297 * **"Yahoo"** for Yahoo Mail
298 * **"Zoho"** for Zoho Mail
299
3c3cca5 updated readme
Andris Reinman authored
300 Predefined service data covers `host`, `port` and secure connection settings,
301 any other parameters (ie. `auth`) need to be set separately.
93f2d1f Updated docs etc
Andris Reinman authored
302
3c3cca5 updated readme
Andris Reinman authored
303 ## E-mail message fields
93f2d1f Updated docs etc
Andris Reinman authored
304
3c3cca5 updated readme
Andris Reinman authored
305 The following are the possible fields of an e-mail message:
306
307 - **from** - The e-mail address of the sender. All e-mail addresses can be plain `sender@server.com` or formatted `Sender Name <sender@server.com>`
308 - **to** - Comma separated list of recipients e-mail addresses that will appear on the `To:` field
309 - **cc** - Comma separated list of recipients e-mail addresses that will appear on the `Cc:` field
310 - **bcc** - Comma separated list of recipients e-mail addresses that will appear on the `Bcc:` field
311 - **replyTo** - An e-mail address that will appear on the `Reply-To:` field
312 - **subject** - The subject of the e-mail
313 - **text** - The plaintext version of the message
314 - **html** - The HTML version of the message
aae3749 regenerated docs
Andris Reinman authored
315 - **generateTextFromHTML** - if set to true uses HTML to generate plain text body part from the HTML if the text is not defined
3c3cca5 updated readme
Andris Reinman authored
316 - **headers** - An object of additional header fields `{"X-Key-Name": "key value"}` (NB! values as passed as is, you should do your own encoding to 7bit if needed)
317 - **attachments** - An array of attachment objects.
9285f5c updated mailcomposer dependency to support envelope property
Andris Reinman authored
318 - **envelope** - optional SMTP envelope, if auto generated envelope is not suitable
2b9a3c9 Added messageId option
Andris Reinman authored
319 - **messageId** - optional Message-Id value, random value will be generated if not set
3c3cca5 updated readme
Andris Reinman authored
320
321 All text fields (e-mail addresses, plaintext body, html body) use UTF-8 as the encoding.
322 Attachments are streamed as binary.
323
324 Example:
325
d768813 Changed new Transport to createTransport
Andris Reinman authored
326 var transport = nodemailer.createTransport("Sendmail");
3c3cca5 updated readme
Andris Reinman authored
327
328 var mailOptions = {
329 from: "me@tr.ee",
330 to: "me@tr.ee",
331 subject: "Hello world!",
2685865 Updated readme
Andris Reinman authored
332 text: "Plaintext body"
3c3cca5 updated readme
Andris Reinman authored
333 }
334
07db51a updated sending api, backwards compatible
Andris Reinman authored
335 transport.sendMail(mailOptions);
3c3cca5 updated readme
Andris Reinman authored
336
ecfeb0e updated README for SendGrid support
Andris Reinman authored
337 ### SendGrid support
338
339 Nodemailer supports SendGrid [SMTP API](http://docs.sendgrid.com/documentation/api/smtp-api/) out of the box - you can
340 use objects as header values and these are automatically JSONized (and mime encoded if needed).
341
342 var mailOptions = {
343 ...,
344 headers: {
345 'X-SMTPAPI': {
346 category : "newuser",
347 sub:{
348 "%name%": ["Žiguli Õllepruul"]
349 }
350 }
3c9462a updated README for SendGrid support
Andris Reinman authored
351 },
352 subject: "Hello, %name%"
ecfeb0e updated README for SendGrid support
Andris Reinman authored
353 }
354
3c9462a updated README for SendGrid support
Andris Reinman authored
355 This also applies to any other service that expects a JSON string as a header value for specified key.
356
d1f45e1 Andris Reinman Update README.md
authored
357 ### Generate Text from HTML
358
359 If `generateTextFromHTML` option is set to true, then HTML contents of the mail is automatically converted
360 to plaintext format when plaintext content is empty or missing.
361
362 For example
363
364 mailOptions = {
365 ...,
366 generateTextFromHTML: true,
367 html: '<h1>Hello world</h1><p><b>How</b> are you?',
368 // text: '' // no text part
369 }
370
371 is automatically converted in the backround by Nodemailer to:
372
373 mailOptions = {
374 ...,
375 // source html:
376 html: '<h1>Hello world</h1><p><b>How</b> are you?',
377 // automatically generated plaintext message:
378 text: "Hello world\n"+
379 "===========\n"+
380 "\n"+
381 "**How** are you?"
382 }
383
384 As you can see the output syntax for `generateTextFromHTML` looks similar to markdown, and that
385 is exactly the case here - Nodemailer includes a simple HTML to markdown converter. But don't
386 expect too much from it, it's not full featured or perfect, just some regexes here and there.
387
3c3cca5 updated readme
Andris Reinman authored
388 ### Attachment fields
389
2685865 Updated readme
Andris Reinman authored
390 Attahcment object consists of the following properties:
3c3cca5 updated readme
Andris Reinman authored
391
392 * **fileName** - filename to be reported as the name of the attached file, use of unicode is allowed (except when using Amazon SES which doesn't like it)
393 * **cid** - optional content id for using inline images in HTML message source
394 * **contents** - String or a Buffer contents for the attachment
395 * **filePath** - path to a file if you want to stream the file instead of including it (better for larger attachments)
80bd5a3 added support for binary streams for attachments
Andris Reinman authored
396 * **streamSource** - Stream object for arbitrary binary streams if you want to stream the contents (needs to support *pause*/*resume*)
2b9a3c9 Added messageId option
Andris Reinman authored
397 * **contentType** - optional content type for the attachment, if not set will be derived from the `fileName` property
398 * **contentDisposition** - optional content disposition type for the attachment, defaults to "attachment"
3c3cca5 updated readme
Andris Reinman authored
399
80bd5a3 added support for binary streams for attachments
Andris Reinman authored
400 One of `contents`, `filePath` or `streamSource` must be specified, if none is
401 present, the attachment will be discarded. Other fields are optional.
3c3cca5 updated readme
Andris Reinman authored
402
403 Attachments can be added as many as you want.
404
4a35e99 Readme update
Andris Reinman authored
405 var mailOptions = {
406 ...
407 attachments: [
408 {
409 fileName: "text1.txt",
410 contents: "hello world!
411 },
412 {
413 fileName: "text2.txt",
414 contents: new Buffer("hello world!,"utf-8")
415 },
416 {
417 fileName: "text3.txt",
418 filePath: "/path/to/file.txt" // stream this file
419 },
420 {
80bd5a3 added support for binary streams for attachments
Andris Reinman authored
421 fileName: "text4.txt",
422 streamSource: fs.createReadStream("file.txt")
423 },
424 {
4a35e99 Readme update
Andris Reinman authored
425 fileName: "text",
426 contents: "hello world!,
427 contentType: "text/plain"
428 }
429 ]
430 }
431
3c3cca5 updated readme
Andris Reinman authored
432 ### Address Formatting
433
434 All the e-mail addresses can be plain e-mail address
435
436 username@example.com
437
438 or with formatted name (includes unicode support)
439
440 "Ноде Майлер" <username@example.com>
441
442 To, Cc and Bcc fields accept comma separated list of e-mails. Formatting can be mixed.
443
444 username@example.com, "Ноде Майлер" <username@example.com>, "Name, User" <username@example.com>
445
446 You can even use unicode domain and user names, these are automatically converted
4a35e99 Readme update
Andris Reinman authored
447 to the supported form
3c3cca5 updated readme
Andris Reinman authored
448
449 "Uncode Domain" <info@müriaad-polüteism.info>
450
9285f5c updated mailcomposer dependency to support envelope property
Andris Reinman authored
451 ### SMTP envelope
452
453 SMTP envelope is usually auto generated from `from`, `to`, `cc` and `bcc` fields but
454 if for some reason you want to specify it yourself, you can do it with `envelope` property.
455
456 `envelope` is an object with the following params: `from`, `to`, `cc` and `bcc` just like
457 with regular mail options. You can also use the regular address format.
458
459 mailOptions = {
460 ...,
461 from: "mailer@node.ee",
462 to: "daemon@node.ee",
463 envelope: {
464 from: "Daemon <deamon@node.ee>",
465 to: "mailer@node.ee, Mailer <mailer2@node.ee>"
466 }
467 }
468
3c3cca5 updated readme
Andris Reinman authored
469 ### Using Embedded Images
470
471 Attachments can be used as embedded images in the HTML body. To use this
472 feature, you need to set additional property of the attachment - `cid` (unique
473 identifier of the file) which is a reference to the attachment file. The same
474 `cid` value must be used as the image URL in HTML (using `cid:` as the URL
475 protocol, see example below).
476
477 **NB!** the cid value should be as unique as possible!
478
4a35e99 Readme update
Andris Reinman authored
479 var mailOptions = {
480 ...
481 html: "Embedded image: <img src='cid:unique@node.ee' />",
482 attachments: [{
483 filename: "image.png",
484 filePath: "/path/to/file",
485 cid: "unique@node.ee" //same cid value as in the html img src
486 }]
487 }
3c3cca5 updated readme
Andris Reinman authored
488
489 ## Return callback
490
491 Return callback gets two parameters
492
493 * **error** - an error object if the message failed
494 * **responseStatus** - an object with some information about the status on success
495
c4cc33b Readme update
Andris Reinman authored
496 Example:
497
4a35e99 Readme update
Andris Reinman authored
498 nodemailer.sendMail(mailOptions, function(error, responseStatus){
499 if(!error){
500 console.log(responseStatus.message); // response from the server
501 }
502 });
503
3c3cca5 updated readme
Andris Reinman authored
504 ## Tests
505
506 Run the tests with npm in Nodemailer's directory
507
508 npm test
509
510 There aren't currently many tests for Nodemailer but there are a lot of tests
511 in the modules that are used to generate the raw e-mail body and to use the
512 SMTP client connection.
513
514 ## Tweaking
515
516 Nodemailer in itself is actually more like a wrapper for my other modules
517 [mailcomposer](https://github.com/andris9/mailcomposer) for composing the raw message stream
518 and [simplesmtp](https://github.com/andris9/simplesmtp) for delivering it, by providing an
519 unified API. If there's some problems with particular parts of the
520 message composing/sending process you should look at the appropriate module.
521
522 ## License
523
524 **Nodemailer** is licensed under [MIT license](https://github.com/andris9/Nodemailer/blob/master/LICENSE). Basically you can do whatever you want to with it.
Something went wrong with that request. Please try again.