How to get exim running as your MTA with a smarthost

If you need to configure exim 4 as your default MTA (mail transport agent) with an external smart host (SMTP) server then these instructions might help. This setup expect that the SMTP server requires no authentication. I've also tagged on some useful commands for clearing your mail.

Installing

After installing exim with yum install exim you will need to setup your smarthost (smtp relay) server in the /etc/exim/exim.conf file.

Setup

Simply comment out the dnslookup section and add these lines below that section :-

divertnonlocal:
driver = manualroute
domains = ! +local_domains
transport = remote_smtp
route_list = * 
ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
no_more

Thats it, however depending on how your server has been setup you may need to set some rewrite option to mask some of your email addresses so that they are accepted by your local SMTP smart host, you can set these in the configuration files rewrite section, for example :-

Show Plain Text
Text code
  1. begin rewrite

This example matches all the address in your local field (*@*) and replaces the From envelope and From: fields with [email protected]. For more in-depth options check out the Exim Address rewriting section .

Setting your MTA

From your bash shell you can also set exim as your default MTA by running the following command and selecting exim from the menu :-

Show Plain Text
Text code
  1. alternatives --config mta

For those running Debian or Ubuntu life has been made easy with the utility dpkg-reconfigure, just run the following command and follow the menu's :-

Show Plain Text
Text code
  1. dpkg-reconfigure exim4-config

Testing Exim

To manually test that your exim has been installed correctly you can use the following command :-

Show Plain Text
Text code
  1. Subject: Testing
  2. This a exim test message.
  3. ^D

With the -v option you will get allot of debug information that may assist in any local or SMTP server mail delivery problems.

Errors

If your getting an error similar to the following :

Show Plain Text
Text code
  1. R=send_to_relay T=remote_smtp defer (-42): authentication required but server did not advertise AUTH support

With the above error its possible that your server does not require or has not got authentication installed. Just remove the hosts_require_auth=* lines from the remote_smtp section.

Some useful mail commands

List all messages in the mail queue:

Show Plain Text
Text code
  1. exim -bp
  2. // or
  3. mailq

Remove a particular message from the queue:

Show Plain Text
Text code
  1. exim -Mrm {message-id}

Remove all messages from the mail queue:

Show Plain Text
Text code
  1. exim -bp | exiqgrep -i | xargs exim -Mrm
Filed under: Linux  Tags: Redhat, Debian, Ubuntu

1 Responses to “How to get exim running as your MTA with a smarthost”

Thanks, useful article.

Sorry, comments have been closed for this post.
(default) 11 queries took 5 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`220
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`220
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'how-to-get-exim-running-as-your-mta-with-a-smarthost' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (75) 111
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 75 AND `PostsTag`.`tag_id` = `Tag`.`id`) 330
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 75 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 7510