Note: Prefer Exim4
over Sendmail
Append the following directives into /etc/mail/sendmail.mc
.
These lines should come before mailer definitions.
define(`SMART_HOST',`mail.example.com')
define(`RELAY_MAILER_ARGS', `TCP $h 587')
define(`ESMTP_MAILER_ARGS', `TCP $h 587')
FEATURE(`authinfo',`Hash -o /etc/mail/authinfo.db')
TRUST_AUTH_MECH(`PLAIN LOGIN')
define(`confAUTH_MECHANISMS', `PLAIN LOGIN')
define(`confAUTH_OPTIONS', `A')
MASQUERADE_AS(`example.com')
MASQUERADE_DOMAIN(`localdomain')
MASQUERADE_DOMAIN(`other-example.com')
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')
FEATURE(masquerade_envelope)
FEATURE(masquerade_entire_domain)
Edit (create if not exists) credentials file at /etc/mail/authinfo
and supply authentication settings (a line for each SMTP host):
AuthInfo:mail.example.com "U:username" "P:password"
Protect the file from other users
chmod 0600 /etc/mail/authinfo
Create authentication database from plaintext file:
makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo
Create a /etc/mail/generics-domains
file that is just a list of all the domains that
should be inspected. Make sure the file includes your server's canonical domain name, which
you can obtain using the command:
sendmail -bt -d0.1 </dev/null
An example /etc/mail/generics-domains
could be:
foo.example.com
baz.example.com
Create your /etc/mail/genericstable file
. First sendmail searches the /etc/mail/generics-domains
file for a list of domains to reverse map. It then looks at the /etc/mail/genericstable
file
for an individual email address from a matching domain. An example is:
www-data no-reply@example.com
root admin@example.com
See also https://sites.google.com/site/syscookbook/miscellaneous/sendmail
Finally, create the database for genericstable:
makemap -r hash genericstable.db < genericstable
Since sendmail's configuration has changed, we need to rebuild it (inside /etc/mail
). Afterwards (if everything went ok) restart the daemon:
make
invoke-rc.d sendmail restart
Test your configuration, use sendmail in verbose mode to contact someone:
echo -e "Subject: Hello\r\n\r\nI say hello"| sendmail -v -F 'Contact' someone@foo.com