Linux sendmail smtp server

Sendmail

Sendmail implements a general purpose internetwork mail routing facility. This document explain how to install sendmail and run an email server which will send and receive mail using the SMTP protocol.

An IMAP or POP3 server is required to retrieve mail using Eudora or MS Outlook. Sendmail does not offer POP3 or IMAP services.

Installation

Prerequisites

You should have a basic knowledge of UNIX and DNS.

The server should allow incoming connections to the SMTP service which will be listening on TCP port 25.

The server should have a fully qualified hostname (FQDN) such as mail.example.net.

The hostname should resolve to an A record. It should not be a CNAME.

The MX record for the domain for which you wish to receive mail should point to the hostname of your server.

There should a PTR record for the IP address of your server. Mail from your server may be rejected if there is no reverse DNS.

Installing sendmail

Download the sendmail source code from the sendmail website.

  • Extract the files from the downloaded file.
  • Change the current directory to where the sendmail source code was extracted.
  • Enter the following command:
  • Verify whether you have a user smmsp. Create the user if it does not exist. The user should not be assigned a login shell.
  • Verify whether you have a group called smmsp.

The sendmail binary is now installed. The next step is to configure sendmail.

Configuring sendmail

The main configuration file for sendmail is the /etc/mail/sendmail.cf file. Starting with version 8.12, sendmail uses the /etc/mail/submit.cf configuration file for mail submission. The .cf files are complex to understand. It is recommended that you create a .mc configuration file and use the M4 (macro processor) to generate the .cf file.

There are some sample .mc configuration files in the cf/cf/ directory of the sendmail source code. Alternatively, you can use one of the sample configuration files available from this website. You should edit the .mc file with a UNIX text editor such as vi.

  • Change the current directory to cf/cf directory.
  • Copy your .mc configuration file to the current directory as sendmail.mc.
  • To generate the sendmail.cf, enter the following command:

The following sample configuration files are available for download. If you are using a smarthost, you will find a sample configuration here.

If you already have sendmail installed and configured, you can generate a new sendmail.cf file by using the following command:

m4 directory/m4/cf.m4 config.mc > sendmail.cf

The directory for the sendmail m4/cf.m4 file depends on the operating system you are using:

  • Debian /usr/share/sendmail.cf
  • FreeBSD /usr/share/sendmail/cf
  • MacOS X /usr/share/sendmail/conf
  • OpenBSD /usr/share/sendmail
  • NetBSD /usr/share/sendmail/cf
  • RedHat /usr/share/sendmail-cf or /usr/lib/sendmail-cf
  • Slackware 8.0 /usr/src/sendmail/
  • Slackware 8.1 /usr/share/sendmail/cf
  • Solaris /usr/lib/mail

On Solaris, for example, type:

m4 /usr/lib/mail/m4/cf.m4 config.mc > sendmail.cf

Verify whether you have the following files in /etc/mail

The local-host-names file should contain the domain name for which your mail server should accept mail. It is recommended that you also add localhost to this file. Each entry should be on a new line.

If there is no relay-domains file, create one with the following command:

The aliases file should contain the following entries at least:

postmaster: root
abuse: root
security: root

In the above example, postmaster is an alias for the root mailbox. The following command will generate the aliases table:

You can create a new access file by typing

The default database map type for Linux, FreeBSD, NetBSD or OpenBSD is hash. Type the following to generate the data bases:

If you are using the smarthost.mc or smarthost-dialup.mc, create a genericstable file and type:

You can now start sendmail.

Sendmail administration

Starting sendmail

The sendmail MTA can be started with the following command:

/usr/sbin/sendmail -L sm-mta -bd -q30m
or
/usr/sbin/sendmail -bd -q30m (versions 8.9.x, 8.10.x, 8.11.x)

The Mail Submission Agent listens for incoming connections on TCP port 587.

If you are using sendmail 8.12, 8.13 or 8.14, enter the following command to start the Mail Submission Program:

/usr/sbin/sendmail -L sm-msp-queue -Ac -q30m

Shutting down sendmail

You can shutdown sendmail by entering the following command:

Viewing the mail queue

You can display the contents of the mail queue with the following command:

Process messages saved in the mail queue

You can process messages saved in the mail queue with the following command:

Troubleshooting

Verifying whether sendmail is running

You can verify whether sendmail is running by running the following command:

You will see the sendmail banner which shows the version of sendmail you are using. Type quit and press Enter to exit to the shell.

Testing SMTP

A SMTP test can be done to verify email delivery. Type:

Type the text in bold when you see the following and press Enter

SERVER:220 local ESMTP Sendmail 8.13.5/8.13.5; Wed, 15 Mar 2006 01:51:21 -0800 (PST)
USER:HELO host.example.com
SERVER:250 mail.example.net Hello host.example.com [192.0.2.1], pleased to meet you
USER:MAIL FROM:
SERVER:250 2.1.0 . Sender ok
USER:RCPT TO:
SERVER:250 2.1.5 . Recipient ok
USER:DATA
SERVER:354 Enter mail, end with «.» on a line by itself
USER:This is a test message
USER:.
SERVER:250 2.0.0 k2FApLlB020139 Message accepted for delivery
USER:QUIT
SERVER:221 2.0.0 mail.example.net closing connection

Mail log

Sendmail uses the mail facility of syslog for logging. The mail log is usually written to /var/log/maillog

Sendmail configuration files

Add the domains (one per line) for which you want mail to be delivered locally to this file.

If the system is acting as a secondary MX server, add the domains (one per line) to this file.

Add your aliases to this file, then run newaliases to update the data base.

This file is used to allow or disallow relaying. The configuration section explains howto run makemap to update the data base.

File and directory permissions

The following permissions are generally required for sendmail related files and directories:

-r-xr-sr-x root smmsp /usr/sbin/sendmail
drwxrwx— smmsp smmsp /var/spool/clientmqueue
drwx—— root wheel /var/spool/mqueue
-r—r—r— root wheel /etc/mail/sendmail.cf
-r—r—r— root wheel /etc/mail/submit.cf

Mail relaying

Mail relaying occurs when mail is forwarded from someone else through your mail server. Forwarding mail through a mail server is perfectly natural as long as either the originator of the message or the receiver is a authorized user. If neither the sender nor the recipient of the message is a local user, it is called third-party mail relaying.

Mail servers should be configured not to accept third-party mail relay. If a mail server allows third-party mail relaying from everyone, it is known as an open relay. Such a mail server attracts spammers as it can be used to send large amounts of junk mail under false identity.

If the client computer from which you are connecting from has a static IP address, you can add the following entry, for example, to allowing relaying (send mail):

192.168.0.5 RELAY (allows 192.168.0.5 to relay)

192.168.1 RELAY (allows 192.168.1/24 to relay)

You should run the makemap command after modifying the access file.

If you are connecting from a dynamic IP address, you should use SMTP AUTH to allow relaying.

Mail submission

Sendmail has been split into two parts, with one part handling mail submission. This allows sendmail to run without being SUID root.

The Mail Submission Program (MSP) uses the /var/spool/clientmqueue directory by default. It will use the /etc/mail/submit.cf configuration file. That configuration file can be generated from the submit.mc using m4.

The MSP will send outgoing mail by passing it to localhost on port 25 using the SMTP protocol. As of sendmail version 8.12.x, you should have sendmail running as a daemon and listening on localhost at least.

Submitting mail from the command line with sendmail

Type the following command where user@example.com is the address of the recipient:

Type in your message, then press Enter and type in a dot and press Enter again.

Piping to sendmail

You can pipe in a message to sendmail with the following command where filename is name of the file containing the message:

Sending file attachments

Sendmail does not send mail attachments. You should encode your file using a MIME encoding utility before piping it to sendmail.

The future

Sendmail X was slated as the next version after sendmail 8. It is not longer being developed. Its successor is MeTA1.

Acronyms

Feedback

If you have any comments, send us an email or contact us through our feedback form.

If you have problems sending or receiving emails; or require technical support for sendmail, we can help you.

Источник

How to Install and Configure Sendmail on Ubuntu 22.04 / 20.04 /18.04

Sendmail is a widely used Mail Transfer Agent (MTA) that allows users to send and receive email on Linux systems. It is a powerful and flexible mail server solution that can be configured to work with various email clients and services. In this article, we will provide you with a comprehensive guide to understanding, installing, and configuring Sendmail on Ubuntu. We will also cover some tips and tricks for mail server administrators to ensure efficient and secure operation.

Prerequisites

Before you begin, ensure that you have the following:

  1. An Ubuntu system (we will use Ubuntu 20.04 LTS in this guide, but the process should be similar for other versions)
  2. A stable internet connection
  3. Root or sudo privileges

Step 1: Update your system

Before installing Sendmail, update your Ubuntu system to ensure that you have the latest packages and security patches. Open a terminal and run the following command:

sudo apt update && sudo apt upgrade -y 

To install Sendmail along with related packages, such as mailutils and sendmail-cf, run the following command:

sudo apt install -y sendmail sendmail-cf mailutils 

Step 3: Configure Sendmail

The main configuration file for Sendmail is /etc/mail/sendmail.cf. However, it is recommended to make changes to the .mc file (e.g., /etc/mail/sendmail.mc) and then generate the .cf file. This makes the configuration process easier and less error-prone.

To configure Sendmail, open the /etc/mail/sendmail.mc file using your preferred text editor:

sudo nano /etc/mail/sendmail.mc 

Ensure the following lines are present and uncommented in the file:

Источник

Читайте также:  Acer aspire es1 linux
Оцените статью
Adblock
detector