Difference between revisions of "Sendmail"

From ArchWiki
Jump to navigation Jump to search
m (fix link error)
(→‎Configuration: Added POODLE/FREAK?Logjam prevention warning.)
Line 21: Line 21:
=== Create SSL certs ===
=== Create SSL certs ===
{{Warning|Some variations and implementations of SSL/TLS are that are [https://weakdh.org/#affected still implemented] are [http://en.wikipedia.org/wiki/Transport_Layer_Security#Attacks_against_TLS.2FSSL vulnerable to attack]. For details on these current vulnerabilities within SSL/TLS and how they apply to Sendmail and other services (such as email) visit http://disablessl3.com/ and https://weakdh.org/sysadmin.html}}
* Generate a key and sign it. Read [[OpenSSL#Generating_keys|OpenSSL]] for more information.
* Generate a key and sign it. Read [[OpenSSL#Generating_keys|OpenSSL]] for more information.

Revision as of 17:33, 26 June 2015

zh-CN:Sendmail Sendmail is the classical SMTP server from the unix world. It was originally coded long time ago, when the internet was a safer place, and back then, security didn't matter as much as does today. Therefore it used to have several security bugs and it got some bad reputation for that. But those bugs are long fixed and a recent sendmail version is as safe as any other SMTP server. However, if your top priority is security, you should probably use netqmail.

The goal of this article is to setup Sendmail for local users accounts, without using mysql or other database, and allowing also the creation of mail-only accounts.

This article only explains the required steps configuring Sendmail; after that, you probably want to add IMAP and POP3 access, so you could follow the Dovecot article.


Install the package sendmailAUR from the AUR, and the packages procmail and m4 from the official repositories.

DNS Records

You should have a domain, and edit your MX records to point your server. Remember some servers have problems with MX records pointing to CNAMEs, so your MX should point to an A record instead.

Adding users

  • By default, all the local users can have an email address like username@your-domain.com. But if you want to add mail-only accounts, that is, users who can get email, but can't have shell access or login on X, you can add them like this:
useradd -m -s /sbin/nologin joenobody
  • Assign a password:
passwd joenobody


Create SSL certs

Warning: Some variations and implementations of SSL/TLS are that are still implemented are vulnerable to attack. For details on these current vulnerabilities within SSL/TLS and how they apply to Sendmail and other services (such as email) visit http://disablessl3.com/ and https://weakdh.org/sysadmin.html
  • Generate a key and sign it. Read OpenSSL for more information.


  • Create the file /etc/mail/sendmail.mc.

You can read all the options for configuring sendmail on the file /usr/share/sendmail-cf/README.

Warning: If you create your own sendmail.mc file, remember that plaintext auth over non-TLS is very risky. Using the following example forces TLS and is therefore more safe unless you know what are you doing

Here is an example using auth over TLS. The example has comments explaing how it works. The comments start with dnl .

define(`confDOMAIN_NAME', `your-domain.com')dnl
dnl  The following allows relaying if the user authenticates,
dnl  and disallows plaintext authentication (PLAIN/LOGIN) on
dnl  non-TLS links:
define(`confAUTH_OPTIONS', `A p y')dnl
dnl  Accept PLAIN and LOGIN authentications:
dnl Make sure this paths correctly point to your SSL cert files:
FEATURE(`virtusertable', `hash /etc/mail/virtusertable.db')dnl
  • Then process it with
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


  • Put your domains on the local-host-names file:
  • Make sure the domains are also resolved by your /etc/hosts file.


  • Create the file /etc/mail/access and put there the base addresses where you want to be able to relay mail. Lets suppose you have a vpn on, and you want to relay mails from any ip in that range:
10.5.0 RELAY
127.0.0 RELAY
  • Then process it with
# makemap hash /etc/mail/access.db < /etc/mail/access


  • Edit the file /etc/mail/aliases and uncomment the line #root: human being here and change it to be like this:
root:         your-username
  • You can add aliases for your usernames there, like:
coolguy:      your-username
somedude:     your-username
  • Then process it with
# newaliases


  • Create your virtusertable file and put there aliases that includes domains (useful if your server is hosting several domains)
your-username@your-domain.com         your-username
joe@my-other.tk                       joenobody
  • Then process it with
# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable

Start on boot

Enable and start the following services. Read Daemons for more datails.

  • saslauthd.service
  • sendmail.service
  • sm-client.service

SASL authentication

  • Add a user to the SASL database for SMTP authentication.
# saslpasswd2 -c your-username

Tips and tricks

Forward all the mail of one domain to certain user

To forward all mail addressed to any user in the my-other.tk domain to your-username@your-domain.com, add to the /etc/mail/virtusertable file:

@my-other.tk        your-username@your-domain.com

Do not forget to process it again with

# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable