haraka / Haraka

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

Bug: recursion receive mail from self->self #134

Closed suquant closed 12 years ago

suquant commented 12 years ago

Example: We have 1 smtp server (mxs.example.com) Situation: We send mail from mxs.example.com to -> mxs.example.com

This situation Haraka recursion send self this message indefinitely!!! What i do wrong?

My config:

# default list of plugins
max_unrecognized_commands

# block mails from known bad hosts (see config/dnsbl.zones for the DNS zones queried)
#dnsbl

# allow bad mail signatures from the config/data.signatures file.
#data.signatures

# block mail from some known bad HELOs - see config/helo.checks.ini for configuration
#helo.checks

mail_from.nobounces

# Only accept mail where the MAIL FROM domain is resolvable to an MX record
mail_from.is_resolvable

# Only accept mail for your personal list of hosts
#rcpt_to.in_host_list

relay

test_queue

connection.relaying = 1

root@mxs:~# node -v v0.6.5

root@mxs:~# haraka -v Haraka.js — Version: 1.0.2

smfreegard commented 12 years ago

Hi,

The problem is that Haraka will look up the MX records for your domain and deliver the mail there, thereby creating a loop as Haraka won't know that it's talking to itself.

What you need to do is to create a plugin that overrides the MX record for your domain and routes the message to the desired internal host.

Create a file called override_mx.js in your plugin directory and add the following:

exports.hook_get_mx = function (next, hmail, domain) { if (domain.toLowerCase() === 'my.domain.com') { return next(OK, 'internal.hostname.com'); } return next(); }

Change 'my.domain.com' to your domain name and 'internal.hostname.com' to a hostname that resolves to the IP address of your server (it MUST be a hostname that is resolvable in DNS due to the way this function works currently).

Then add 'override_mx' into config/plugins, restart Haraka and send yourself a test mail - it should work correctly now.

Hope that helps.

suquant commented 12 years ago

Thank you Steve Freegard :-)

I try this in the near future and will answer here after the experiment.

baudehlo commented 12 years ago

We have also added in a check on maximum number of Received headers to Haraka to prevent this from being an infinite loop.