This post was originally published on go2linux.org, a Linux blog I ran from 2007 to 2011. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.
Smarthost for sendmail and/or exim
This will describe you how to set up a smarthost using either sendmail or exim, for the exim, i will only consider Debian.
This is to send emails using your linux server as your smtp server, and it will use your ISP email server to send all your emails through it, to the final users.
The sendmail configuration I have tested on CentOS, and Fedora, but should work on Debian and Ubuntu as well
Sendmail
You need sendmail 8.11 or a later one to do this. Edit with your favorite text editor the file /etc/mail/sendmail.mc and add this line dnl define(SMART_HOST',smtpserver.domain.xxx') [change smtpserver.domain.xxx for your ISP server or any server that is open for you. Now generate the sendmai.cf file, for that use this command
make -C /etc/mail
Here you can check my sendmail.mc file, just change the lines in bold, to fit your needs
divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for Red Hat Linux')dnl
OSTYPE(`linux')dnl
define(`confDEF_USER_ID',``8:12'')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST',true)dnl
define(`confDONT_PROBE_INTERFACES',true)dnl
define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
define(`confTO_IDENT', `0')dnl
FEATURE(`no_default_msa',`dnl')dnl
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail,`',`procmail -t -Y -a $h -d $u')dnl
FEATURE(`access_db',`hash -T -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
FEATURE(`accept_unresolvable_domains')dnl
LOCAL_DOMAIN(`localhost.localdomain')dnl
dnl MASQUERADE_AS('your.domain')dnl
FEATURE(`access_db')dnl
FEATURE(`authinfo', `hash /etc/mail/authinfo')
define(`SMART_HOST',`your.smtp.server')dnl
MASQUERADE_AS(your.domain)dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(genericstable, `hash -o /etc/mail/genericstable')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/genericsdomain')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
Create a file named /etc/mail/genericstable with this inside it
root [email protected]
and the execute this,
makemap hash /etc/mail/genericstable < /etc/mail/genericstable
In this example we are supposing you need to authenticate to the email server of your ISP so be sure to have this line in your /etc/mail/sendmail.mc
FEATURE(`authinfo', `hash /etc/mail/authinfo')
and also create this file:
vi /etc/mail/authinfo
with this inside
AuthInfo:your.smtp.server "U:[email protected]" "I:user" "P:passwd" "M:LOGIN PLAIN"
and run
makemap hash /etc/mail/authinfo < /etc/mail/authinfo
and make authinfo readable only by root
chmod 600 /etc/mail/authinfo
Now you are done, you can start sending emails using your ISP account with your linux server.
Exim
This have only tested with Debian by me, and it is really easy. run
dpkg-reconfigure exim4
and choose smarthost, and provide with the name and port of your ISP server, after that, edit the file /etc/exim4/passwd.client
and insert your user and password info, to authenticate on your ISP server in this format
target.mail.server.example:login:password
You are done!