Apr 28, 2008

Some Exim4 hacks

Exim is the stock MTA in Debian, and rightly so, since its pretty much the most flexible MTA around (note: I did say "most flexible," not "most secure.") It is also very easy to set up, thanks to its debconf integration and sane configuration interface; however, there may be some bits that still needs that extra tweaking that a dialog or menu interface can't reach:

Setting the Right mailserver hostname

Most mailservers typically go by a hostname of "mail" or "mx," for various reasons. Of course, this requires setting the right DNS entry for your domain, but Exim may miss this and use the internal hostname of your mailserver instead. There are quite a lot of ways to set the "right" mailserver name in Exim, but in Debian, it is recommended that one DOESN'T set it via the primary_hostname variable, as this can mess up other places in the Exim configuration and complicate matters. Instead, one can use smtp_active_hostname in the global options:

smtp_active_hostname = mail.foobar.net

Changing Received: header

If one changes the mailserver hostname like above, then it also probably needs to change some headers as well, like the "Received:" header. Again, this is a global options setting, controlled by received_header_text:

received_header_text = Received: \
${if def:sender_rcvhost {from $sender_rcvhost\n\t}\
{${if def:sender_ident {from $sender_ident}}\
${if def:sender_helo_name {(helo=$sender_helo_name)\n\t}} }}\
by $smtp_active_hostname \
${if def:received_protocol {with $received_protocol}} \
${if def:tls_cipher {($tls_cipher)\n\t}}\
(Exim $version_number)\n\t\
${if def:sender_address {(envelope-from <$sender_address>)\n\t}}\
id $message_id\
${if def:received_for {\n\tfor $received_for}}

Note that this changes the header when your Exim receives mail; when your Exim sends mail to another mailserver, you'll have to ensure that the header made by the destination mailserver has its hostname matching your own. Thus, you need to fix the "remote_smtp" transport a bit:

remote_smtp:
  debug_print = "T: remote_smtp for $local_part@$domain"
  driver = smtp
  # to disable TLS on outgoing connections, uncomment this
  # hosts_avoid_tls = *
  helo_data = $smtp_active_hostname    # use the variable we set earlier
  # use the interface our Exim is running on and where the mailserver name points to
  interface = 1.2.3.4

Changing Message-Id

Finally, one can change the "Message-Id" header to match the new hostname above, via another global options variable, message_id_header_domain:

message_id_header_domain = $smtp_active_hostname

Tags: , , , . | Posted at: 15:03 | 0 Comments/Trackbacks.

Comments are closed for this story.

Trackbacks are closed for this story.