Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated engine selection

  • Loading branch information...
commit 9c29ca939e7055508861d0440796a0b977a4e2b8 1 parent 0510f4c
Andris Reinman authored
Showing with 28 additions and 4 deletions.
  1. +28 −4 lib/mail.js
View
32 lib/mail.js
@@ -329,7 +329,7 @@ EmailMessage.prototype.generateBody = function(){
this.attachments[i].contents:
new Buffer(this.attachments[i].contents, "utf-8"),
disposition: "attachment",
- content_id: this.attachments[i].cid || ((++gencounter)+"."+Date.now()+"@"+(this.SERVER.hostname || "localhost"))
+ content_id: this.attachments[i].cid || ((++gencounter)+"."+Date.now()+"@"+(this.SERVER && this.SERVER.hostname || "localhost"))
};
@@ -435,14 +435,38 @@ EmailMessage.prototype.send = function(callback){
console.log(Array(str.length+1).join("=")+"\n");
}
+ if(this.SERVER && !exports.SMTP){
+ return this.send_using_engine(this.SERVER, "SMTP", instanceId, callback);
+ }
+
//Use the engine configured by the user
for(var engine in engines) {
if(exports[engine]) {
- exports[engine].instanceId = instanceId;
- engines[engine].send(this, exports[engine], callback);
- return;
+ return this.send_using_engine(exports[engine], engine, instanceId, callback);
}
}
+
+ callback(new Error("Transfer method not defined"));
+}
+
+/**
+ * mail.EmailMessage#send_using_engine(engine, engineId, instanceId, callback) -> undefined
+ * - engine (Object): transfer engine to be used
+ * - engineId (String): engine name
+ * - instanceId (Number): number of the message
+ * - callback (Function): function to be called if sending succeedes or fails
+ *
+ * Initiates a message sending using defined engine
+ **/
+EmailMessage.prototype.send_using_engine = function(engine, engineId, instanceId, callback){
+
+ engine.instanceId = instanceId;
+ engines[engineId].send(this, engine, callback);
+
+ if(this.debug){
+ console.log("Used transfer method: " + engineId + "\n");
+ }
+
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.