haraka / Haraka

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

Loop when using queue/lmtp and get_mx hook #693

Closed klonodo closed 9 years ago

klonodo commented 10 years ago

I have a problem with haraka running in loop when using queue/lmtp and using dovecot. I have for example 2 IPs on the SMTP server : 1.1.1.1 and 1.1.1.2 , normally Haraka will use always 1.1.1.1 to connect to outbound SMTP servers for delivering, that's why i am using this plugin:

exports.hook_get_mx = function (next, hmail, domain) {
outbound.lookup_mx(domain, function (err, mxs) {
    if (err) return next(DENY, err);
    mxs.forEach(function (mx) {
      mx.bind = '1.1.1.2';
       });
   return next(OK, mxs);
   });

}

I am using it because i need to set outgoing IP as 1.1.1.2, becuase i have this IP in domain MX records. If i send mail everything is ok, but when i receive email then i see loop hell.

In my lmtp.ini i have :

[mydomain.com]
host=localhost
port=2500

If i turn off that custom get_mx plugin then Haraka uses 1.1.1.1 IP and there is no loops. Anyone can help ?

klonodo commented 10 years ago

Ok, i have figured it out. I did a check if connection.relaying == true in data_post hook if it is then i've did connection.transaction.notes.isrelay = true;. After that i've added check inside get_mx to see if (connection.transaction.notes.isrelay == true) and if it is then i am doing outbound.lookup_mx... if not then i just return next();