Permalink
Browse files

Added forceEmbeddedImages option

  • Loading branch information...
1 parent 9968d4f commit 8c8d4d7c41a253c5e57dbb07c8a5cf0579862901 Andris Reinman committed Nov 28, 2012
Showing with 67 additions and 1 deletion.
  1. +19 −0 README.md
  2. +43 −0 examples/example_autoembedding.js
  3. +4 −0 lib/nodemailer.js
  4. +1 −1 package.json
View
@@ -622,6 +622,25 @@ var mailOptions = {
}
```
+**Automatic embedding images**
+
+If you want to convert images in the HTML to embedded images automatically, you can
+set mail option `forceEmbeddedImages` to true. In this case all images in
+the HTML that are either using an absolute URL (http://...) or absolute file path
+(/path/to/file) are replaced with embedded attachments.
+
+For example when using this code
+
+```javascript
+var mailOptions = {
+ forceEmbeddedImages: true
+ html: 'Embedded image: <img src="http://example.com/image.png">'
+};
+```
+
+The image linked is fetched and added automatically as an attachment and the url
+in the HTML is replaced automatically with a proper `cid:` string.
+
## Return callback
Return callback gets two parameters
@@ -0,0 +1,43 @@
+var nodemailer = require('../lib/nodemailer');
+
+// Create a SMTP transport object
+var transport = nodemailer.createTransport("SMTP", {
+ service: 'Gmail', // use well known service
+ auth: {
+ user: "test.nodemailer@gmail.com",
+ pass: "Nodemailer123"
+ }
+ });
+
+console.log('SMTP Configured');
+
+// Message object
+var message = {
+
+ // sender info
+ from: 'Sender Name <sender@example.com>',
+
+ // Comma separated list of recipients
+ to: '"Receiver Name" <receiver@example.com>',
+
+ // Subject of the message
+ subject: 'Automatically embedded image', //
+
+ // HTML body with image that will be converted to embedded attachment
+ html:'<p>Embedded image: <img src="'+__dirname+'/nyan.gif"/></p>',
+
+ forceEmbeddedImages: true
+};
+
+console.log('Sending Mail');
+transport.sendMail(message, function(error){
+ if(error){
+ console.log('Error occured');
+ console.log(error.message);
+ return;
+ }
+ console.log('Message sent successfully!');
+
+ // if you don't want to use this transport object anymore, uncomment following line
+ //transport.close(); // close the connection pool
+});
View
@@ -96,6 +96,10 @@ function Nodemailer(options){
mailcomposerOptions.charset = this.options.charset;
}
+ if(!!this.options.forceEmbeddedImages){
+ mailcomposerOptions.forceEmbeddedImages = true;
+ }
+
this.mailcomposer = new MailComposer(mailcomposerOptions);
if(!this.transport){
View
@@ -25,7 +25,7 @@
}
],
"dependencies": {
- "mailcomposer": ">= 0.1.23",
+ "mailcomposer": ">= 0.1.25",
"simplesmtp": ">= 0.1.22",
"optimist": "*"
},

0 comments on commit 8c8d4d7

Please sign in to comment.