Permalink
Browse files

MAIL and RCPT commands.

- Added error 503 for bad command sequence.
- Added code for MAIL and RCPT commands.
  • Loading branch information...
1 parent c4aaa22 commit d3f1c7366cc5a2a91a1a6faef878fbf963f4c453 @miksago miksago committed Jan 15, 2010
Showing with 36 additions and 4 deletions.
  1. +2 −1 examples/config.example
  2. +5 −1 examples/example-client.js
  3. +28 −2 lib/smtp/client.js
  4. +1 −0 lib/smtp/errors.js
View
@@ -10,4 +10,5 @@ var config = exports;
config.port = 25;
config.host = "smtp.server.com";
-config.from = "test@server.com";
+config.from = "test@server.com";
+config.to = "test@server2.com";
@@ -17,5 +17,9 @@ client.addOnce("idle", function(){
});
client.addOnce("idle", function(){
+ client.rcpt(config.to);
+});
+
+/*client.addOnce("idle", function(){
client.quit();
-});
+});*/
View
@@ -169,11 +169,37 @@ Client.prototype.auth = function(){};
Sending mail
-----------------------------------------------*/
Client.prototype.mail = function(from_addr){
+ var client = this;
+
this.get("MAIL FROM:<"+from_addr+">", function(packet){
- sys.puts(packet.data.join(" "));
+ switch(packet.status){
+ case "250":
+ client.mail_from = true;
+ break;
+ default:
+ throw SMTPError["unhandled"];
+ break;
+ }
+ });
+};
+Client.prototype.rcpt = function(to_addr){
+ var client = this;
+
+ if( ! client.mail_from){
+ throw SMTPError["503"];
+ return;
+ }
+
+ this.get("RCPT TO:<"+to_addr+">", function(packet){
+ switch(packet.status){
+ case "250":
+ break;
+ default:
+ throw SMTPError["unhandled"];
+ break;
+ }
});
};
-Client.prototype.rcpt = function(){};
Client.prototype.data = function(){};
/*-----------------------------------------------
View
@@ -13,6 +13,7 @@ var SMTPErrors = exports;
SMTPErrors.client = {
"unhandled": new Error("Received an unhandled status code"),
// numeric:
+ "503": new Error("Bad sequence of commands"),
"504": new Error("Command parameter not implemented"),
"550": new Error("Requested action not taken: mailbox unavailable"),
"554": new Error("Transaction failed (Or, in the case of a connection-opening response, \"No SMTP service here\")")

0 comments on commit d3f1c73

Please sign in to comment.