Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction.notes not passing to Hmail.todo.notes #1293

Closed
ricardopolo opened this issue Jan 10, 2016 · 7 comments
Closed

Transaction.notes not passing to Hmail.todo.notes #1293

ricardopolo opened this issue Jan 10, 2016 · 7 comments

Comments

@ricardopolo
Copy link
Contributor

We are creating a plugin that changes the SMTP server based in some info from an API. So we plan to get the info in the queue event, and store the SMTP server in the transaction.notes and then use it in the get_mex hook.

Look up this plugin code

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

exports.register = function() {
  this.register_hook('queue', 'send_email');
  this.register_hook('get_mx', 'change_smtp_server');
};


exports.send_email = function (next, connection) {

  var contents = [
    "From: " + "ricardo.polo@tulpep.com",
    "To: " + "ricardo.polo@tulpep.com",
    "MIME-Version: 1.0",
    "Content-type: text/plain; charset=us-ascii",
    "Subject: Some subject here",
    "",
    "Some email body here",
    ""].join("\n");

  outbound.send_email(connection.transaction.mail_from, connection.transaction.rcpt_to, contents, function (code, msg) {
    connection.transaction.notes.send_server = "server.com";
    connection.transaction.notes.send_server_port = 25;
    switch (code) {
      case OK:    return next(OK, msg);
      case DENY:  return next(DENY, msg);
      default:    return next(DENYSOFT, msg);
    }
  });

};

exports.change_smtp_server =  function (next, hmail, domain) {
  var mx = {
      priority: 0,
      exchange: hmail.todo.notes.send_server,
      port: hmail.todo.notes.send_server_port
  };
  return next(OK, mx);
};

It is supposed acording to docs that everything in transaction.notes will be in hmail.todo.notes, but in this case todo.notes.send_server is empty. Why could this be happening?

Any idea, maybe @baudehlo @smfreegard @msimerson ?
Thank you so much for you help!!

@smfreegard
Copy link
Collaborator

It is supposed acording to docs that everything in transaction.notes will be in hmail.todo.notes, but in this case todo.notes.send_server is empty. Why could this be happening?

Because you're setting the notes in the callback which is run after the outbound.send_email returns....

@ricardopolo
Copy link
Contributor Author

Thanks @smfreegard. If I set the notes in an event previous to the them, inside a callback, when it arrives to the queue event, the value is there. But when comes to get_mx the value is not there.

Look up the code

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

exports.register = function() {
  this.register_hook('data', 'query_the_api');
  this.register_hook('queue', 'send_email');
  this.register_hook('get_mx', 'change_smtp_server');
};


exports.query_the_api = function(next, connection)
{
  request("http://google.com", function(){
    connection.transaction.notes.send_server = 'tulpep-com.mail.protection.outlook.com';
    connection.transaction.notes.send_server_port = 25;
    return next();
  });

};

exports.send_email = function (next, connection) {

  connection.loginfo("There is info" + connection.transaction.notes.send_server);

  var contents = [
    "From: " + "ricardo.polo@tulpep.com",
    "To: " + "ricardo.polo@tulpep.com",
    "MIME-Version: 1.0",
    "Content-type: text/plain; charset=us-ascii",
    "Subject: Some subject here",
    "",
    "Some email body here",
    ""].join("\n");

  outbound.send_email(connection.transaction.mail_from, connection.transaction.rcpt_to, contents, function (code, msg) {
    switch (code) {
      case OK:    return next(OK, msg);
      case DENY:  return next(DENY, msg);
      default:    return next(DENYSOFT, msg);
    }
  });

};

exports.change_smtp_server =  function (next, hmail, domain) {
  var mx = {
      priority: 0,
      exchange: hmail.todo.notes.send_server,
      port: hmail.todo.notes.send_server_port
  };
  return next(OK, mx);
};

Why values are past from data to queue but not from queue to get_mx.
Where should I do the request in order to the get_mx contains the data?

@ricardopolo
Copy link
Contributor Author

I was thinking about it and found this is not about a wrong callback use. Looking at the code I see that when you use outbound.send_email a new transaction is created, so are not notes in the new transaction. Any workarraound?

cc @smfreegard @baudehlo @msimerson

@baudehlo
Copy link
Collaborator

Put them in a header?

On Jan 10, 2016, at 11:04 AM, Ricardo Polo notifications@github.com wrote:

I was thinking about it and think that a valid posibility is that this maybe not related to wrong callbac use. Looking at the code a see that when you use outbound.send_email a new transaction is created, so are not notes are here. Any workarraound?

cc @smfreegard @baudehlo @msimerson


Reply to this email directly or view it on GitHub.

@ricardopolo
Copy link
Contributor Author

@baudehlo that is not possible in our requirements, we cannot have the values in headers. I created a PR that fixes this.

@baudehlo
Copy link
Collaborator

You could use send_trans_email then.

On Jan 10, 2016, at 12:24 PM, Ricardo Polo notifications@github.com wrote:

@baudehlo that is not possible in our requirements, we absolutely need the values from and external API. I created a PR that fixes this.


Reply to this email directly or view it on GitHub.

@ricardopolo
Copy link
Contributor Author

@baudehlo yes I know but we need a bran new email, not keeping anything of the original one. We just want to use some notes to be used in the get_mx plugin later.
I could create a new transaction and replicated all the logic that is inside send_email to use send_trans_email but don't think is a good idea have the same code in two places.

So.. this is why I we created the PR #1295. To can use send_email but still can have notes that can be processed in later hooks. send_emal already receives an options object, this is just a new option. Please check the PR and thanks! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants