haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

foreverlooping 2x then died #213

Closed adamramadhan closed 12 years ago

adamramadhan commented 12 years ago
[INFO] [9E2036F2-BB09-4A44-B0C7-A7032C39CBC6] [outbound] Looking up A records fo
r: aspmx.l.google.com
[INFO] [9E2036F2-BB09-4A44-B0C7-A7032C39CBC6] [outbound] Attempting to deliver t
o: 173.194.79.26 (1)
[INFO] [9E2036F2-BB09-4A44-B0C7-A7032C39CBC6] [outbound] Successfully delivered
mail: 1340271655724_0_19199_5008.ip-10-128-75-153 (2.0.0 OK 1340271657 gk6si4079
806pbc.344)
[ERROR] [9E2036F2-BB09-4A44-B0C7-A7032C39CBC6] [outbound] Ongoing connection clo
sed

then loops again, i got two emails then die. what is going on here?

in plugins i only have this test.js and a rcpt_to.in_host_list

var fs = require('fs');

exports.hook_data = function (next, connection) {

  // enable mail body parsing
  connection.transaction.parse_body = 1;
  // connection.relaying = true;

  // attachment start
  connection.transaction.attachment_hooks(function (ctype, filename, body) {

      // stop all the email that have attachment
      if (filename) 
      {
        haraka.loginfo("there is an attachment!");
        return next(DENY);
      }
  });

  return next();
}

exports.hook_data_post = function (next, connection) {

  var outbound = require('./outbound');

  var email_body_text = connection.transaction.body.body_text_encoded;
  var email_from = connection.transaction.mail_from;
  var email_to = connection.transaction.body.header.headers_decoded.to;
  var rcpt = connection.transaction.rcpt_to;

  var contents = [
    "From: Nadia <t@dev.test.com>",
    "To: " + email_from,
    "MIME-Version: 1.0",
    "Content-type: text/plain; charset=utf8",
    "Subject: Some subject here",
    "",
    "Some email body here",
    ""].join("\n");

  // rcpt.forEach(function (r) { outbound.send_email(r, email_from, contents) });
  outbound.send_email(rcpt[0].original, email_from, contents);

  return next();
}
smfreegard commented 12 years ago

in config/loglevel change the entry to LOGPROTOCOL and re-run your test; then post the full log output; it will be obvious where this is failing then.

I can see why you're getting two messages (you're sending a message in hook_data_post whilst the message that is coming in will be sent by hook_queue_outbound) but not why you're getting the error message.

If it's dieing - then there should be a stack trace in the log as well.

adamramadhan commented 12 years ago

where should i put the message.send() ?

smfreegard commented 12 years ago

I'm not really sure what you are trying to achieve here to be honest. You don't need to generate a message at all if you simply just want to reject messages that contain attachments.

If you send a message into Haraka via SMTP - you don't have to manually create a message and send it; it does all of that for you if properly configured.

Maybe if you are a bit more clear about what you are trying to do - we can tell you how to achieve it.

adamramadhan commented 12 years ago

ok what im trying to do is make a simple reply, when i email at test@harakaserver.com it will reply the message we send back to the sender. but when there is an attachment, i need something like die(); in php, or maybe stop. ive read the docs about DENY an i think its the best thing that we need to do it so.

smfreegard commented 12 years ago

I'm still not 100% sure exactly what you mean. How about this:

var outbound = require('./outbound');

exports.hook_data = function (next, connection) {

// enable mail body parsing connection.transaction.parse_body = 1; // connection.relaying = true;

// attachment start connection.transaction.attachment_hooks(function (ctype, filename, body) {

  // stop all the email that have attachment
  if (filename) 
  {
    connection.loginfo('found attachment: ' + filename);
    connection.transaction.notes.has_attachment = true;
  }

});

return next(); }

exports.hook_data_post = function (next, connection) { if (connection.transaction.notes.has_attachment) { return next(DENY, 'attachments not allowed'); }

var email_body_text = connection.transaction.body.body_text_encoded; var email_from = connection.transaction.mail_from; var email_to = connection.transaction.body.header.headers_decoded.to; var rcpt = connection.transaction.rcpt_to;

var contents = [ "From: Nadia t@dev.test.com", "To: " + email_from, "MIME-Version: 1.0", "Content-type: text/plain; charset=utf8", "Subject: Some subject here", "", "Some email body here", ""].join("\n");

// rcpt.forEach(function (r) { outbound.send_email(r, email_from, contents) }); outbound.send_email(rcpt[0].address, email_from, contents);

return next(); }