Permalink
Browse files

Changed new Transport to createTransport

  • Loading branch information...
1 parent 2cf9e47 commit d7688134397d43302c4a605717bc822f1cc0e96e Andris Reinman committed Feb 10, 2012
Showing with 28 additions and 20 deletions.
  1. +10 −10 README.md
  2. +1 −1 examples/example_sendmail.js
  3. +1 −1 examples/example_ses.js
  4. +1 −1 examples/example_smtp.js
  5. +10 −6 lib/nodemailer.js
  6. +4 −0 lib/transport.js
  7. +1 −1 package.json
View
@@ -41,7 +41,7 @@ This is a complete example to send an e-mail with plaintext and HTML body
var nodemailer = require("nodemailer");
- var transport = new nodemailer.Transport("SMTP",{
+ var transport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "gmail.user@gmail.com",
@@ -94,17 +94,17 @@ Where
## Setting up a transport method
Before you can send any e-mails you need to set up a transport method. This can
-be done with `new nodemailer.Transport(type, options)` where `type` indicates
+be done with `nodemailer.createTransport(type, options)` where `type` indicates
the transport protocol and `options` defines how it used.
- var transport = new nodemailer.Transport("SMTP", {smtp_options});
+ var transport = nodemailer.createTransport("SMTP", {smtp_options});
The same transport object can and should be reused several times.
When the transport method is defined, it should be attached to the message
object as `transport`
- var transport = new nodemailer.Transport("SMTP", {smtp_options});
+ var transport = nodemailer.createTransport("SMTP", {smtp_options});
var mailOptions = {
transport: transport,
@@ -143,7 +143,7 @@ Possible SMTP options are the following:
Example:
- var transport = new nodemailer.Transport("SMTP", {
+ var transport = nodemailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "gmail.user@gmail.com",
@@ -153,7 +153,7 @@ Example:
or the same without `service` parameter
- var transport = new nodemailer.Transport("SMTP", {
+ var transport = nodemailer.createTransport("SMTP", {
host: "smtp.gmail.com", // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
@@ -166,7 +166,7 @@ or the same without `service` parameter
**NB!** if you want to close the pool (cancel all open connections) you can use
`transport.close()`
- var transport = new nodemailer.Transport("SMTP",{});
+ var transport = nodemailer.createTransport("SMTP",{});
...
transport.close(); // close the pool
@@ -183,7 +183,7 @@ Possible SES options are the following:
Example:
- var transport = new nodemailer.Transport("SES", {
+ var transport = nodemailer.createTransport("SES", {
AWSAccessKeyID: "AWSACCESSKEY",
AWSSecretKey: "AWS/Secret/key"
});
@@ -196,7 +196,7 @@ command.
Configuration is really easy, the options parameter is optional but you can
use it to define the path to the *sendmail* command
- var transport = new nodemailer.Transport("Sendmail", "/usr/bin/sendmail");
+ var transport = nodemailer.createTransport("Sendmail", "/usr/bin/sendmail");
### Well known services for SMTP
@@ -239,7 +239,7 @@ Attachments are streamed as binary.
Example:
- var transport = new nodemailer.Transport("Sendmail");
+ var transport = nodemailer.createTransport("Sendmail");
var mailOptions = {
transport: transport,
@@ -1,7 +1,7 @@
var nodemailer = require('../lib/mail');
// Create a Sendmail transport object
-var transport = new nodemailer.Transport("Sendmail", "/usr/sbin/sendmail");
+var transport = nodemailer.createTransport("Sendmail", "/usr/sbin/sendmail");
console.log('Sendmail Configured');
View
@@ -1,7 +1,7 @@
var nodemailer = require('../lib/mail');
// Create an Amazon SES transport object
-var transport = new nodemailer.Transport("SES", {
+var transport = nodemailer.createTransport("SES", {
AWSAccessKeyID: "AWSACCESSKEY",
AWSSecretKey: "/AWS/SECRET",
ServiceUrl: "https://email.us-east-1.amazonaws.com" // optional
View
@@ -1,7 +1,7 @@
var nodemailer = require('../lib/mail');
// Create a SMTP transport object
-var transport = new nodemailer.Transport("SMTP", {
+var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail', // use well known service
auth: {
user: "test.nodemailer@gmail.com",
View
@@ -1,4 +1,5 @@
var Transport = require("./transport").Transport,
+ createTransport = require("./transport").createTransport,
MailComposer = require("mailcomposer").MailComposer;
/*
@@ -8,6 +9,9 @@ var X_MAILER_NAME = "Nodemailer",
X_MAILER_VERSION = "0.3.0; +http://www.nodemailer.org";
+// Export createTransport method
+module.exports.createTransport = createTransport;
+
// Export Transport constructor
module.exports.Transport = Transport;
@@ -61,23 +65,23 @@ Nodemailer.prototype.getGlobalTransport = function(){
if(this.options.SMTP){
// cache the transport for SMTP as it is actually a connection pool
if(!this.options.SMTP._smtp_transport){
- this.options.SMTP._smtp_transport = new Transport("SMTP", this.options.SMTP);
+ this.options.SMTP._smtp_transport = createTransport("SMTP", this.options.SMTP);
}
return this.options.SMTP._smtp_transport;
}else if(this.options.sendmail){
- return new Transport("sendmail", this.options.sendmail);
+ return createTransport("sendmail", this.options.sendmail);
}else if(this.options.SES){
- return new Transport("SES", this.options.SES);
+ return createTransport("SES", this.options.SES);
}else if(module.exports.SMTP){
// cache the transport for SMTP as it is actually a connection pool
if(!module.exports._smtp_transport){
- module.exports._smtp_transport = new Transport("SMTP", module.exports.SMTP);
+ module.exports._smtp_transport = createTransport("SMTP", module.exports.SMTP);
}
return module.exports._smtp_transport;
}else if(module.exports.sendmail){
- return new Transport("sendmail", module.exports.sendmail);
+ return createTransport("sendmail", module.exports.sendmail);
}else if(module.exports.SES){
- return new Transport("SES", module.exports.SES);
+ return createTransport("SES", module.exports.SES);
}
return false;
};
View
@@ -4,6 +4,10 @@ var SendmailTransport = require("./engines/sendmail"),
// Expose to the world
+module.exports.createTransport = function(type, options){
+ return new Transport(type, options); // this way the "new" is optional
+}
+
module.exports.Transport = Transport;
/**
View
@@ -1,7 +1,7 @@
{
"name": "nodemailer",
"description": "Easy to use module to send e-mails, supports unicode and SSL/TLS",
- "version": "0.3.0",
+ "version": "0.3.1",
"author" : "Andris Reinman",
"maintainers":[
{

0 comments on commit d768813

Please sign in to comment.