diff --git a/History.md b/History.md index c7ea3d5808..bcb2f238c3 100644 --- a/History.md +++ b/History.md @@ -14,6 +14,8 @@ * Upgrade CoffeeScript from 1.5.0 to 1.6.2. #972 +* `Email.send` has a new `headers` option to set arbitrary headers. #963 + * The `localstorage-polyfill` smart package has been replaced by a `localstorage` package, which defines a `Meteor._localStorage` API instead of trying to replace the DOM `window.localStorage` facility. (Now, apps can use @@ -22,7 +24,7 @@ * Support `appcache` on Chromium. #958 -Patches contributed by GitHub user awwx. +Patches contributed by GitHub users awwx and spang. ## v0.6.2.1 diff --git a/docs/client/api.js b/docs/client/api.js index cc0b3266f2..7f6bea72c2 100644 --- a/docs/client/api.js +++ b/docs/client/api.js @@ -1804,6 +1804,10 @@ Template.api.email_send = { {name: "html", type: "String", descr: rfc('mail body (HTML)') + }, + {name: "headers", + type: "Object", + descr: rfc('custom headers (dictionary)') } ] }; diff --git a/packages/email/email.js b/packages/email/email.js index d092305e68..497ba51701 100644 --- a/packages/email/email.js +++ b/packages/email/email.js @@ -85,12 +85,12 @@ var smtpSend = function (mc) { * @param options.subject {String} RFC5322 "Subject:" line * @param options.text {String} RFC5322 mail body (plain text) * @param options.html {String} RFC5322 mail body (HTML) + * @param options.headers {Object} custom RFC5322 headers (dictionary) */ Email.send = function (options) { var mc = new MailComposer(); // setup message data - // XXX support arbitrary headers // XXX support attachments (once we have a client/server-compatible binary // Buffer class) mc.setMessageOption({ @@ -104,6 +104,10 @@ Email.send = function (options) { html: options.html }); + _.each(options.headers, function (value, name) { + mc.addHeader(name, value); + }); + maybeMakePool(); if (smtpPool) { diff --git a/packages/email/email_tests.js b/packages/email/email_tests.js index 8327ce8aa8..b6fcf3026f 100644 --- a/packages/email/email_tests.js +++ b/packages/email/email_tests.js @@ -14,7 +14,8 @@ Tinytest.add("email - dev mode smoke test", function (test) { to: "bar@example.com", cc: ["friends@example.com", "enemies@example.com"], subject: "This is the subject", - text: "This is the body\nof the message\nFrom us." + text: "This is the body\nof the message\nFrom us.", + headers: {'X-Meteor-Test': 'a custom header'} }); // Note that we use the local "stream" here rather than Email._output_stream // in case a concurrent test run mutates Email._output_stream too. @@ -22,6 +23,7 @@ Tinytest.add("email - dev mode smoke test", function (test) { test.equal(stream.getContentsAsString("utf8"), "====== BEGIN MAIL #0 ======\n" + "MIME-Version: 1.0\r\n" + + "X-Meteor-Test: a custom header\r\n" + "From: foo@example.com\r\n" + "To: bar@example.com\r\n" + "Cc: friends@example.com, enemies@example.com\r\n" +