Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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