Ubuntu: how to install and configure SMTP server with Exim – part 3: setup SSL/TLS


Part 01: Ubuntu: install and configure SMTP server with Exim
Part 02: Ubuntu: how to install and configure SMTP server with Exim – part 2: set a password for a SMTP user

Step 1: Create exim certificate :

For testing you can use this command:
sudo /usr/share/doc/exim4-base/examples/exim-gencert

result:

root@tutorialspots ~ # sudo /usr/share/doc/exim4-base/examples/exim-gencert
[*] Creating a self signed SSL certificate for Exim!
    This may be sufficient to establish encrypted connections but for
    secure identification you need to buy a real certificate!

    Please enter the hostname of your MTA at the Common Name (CN) prompt!

Can't load /root/.rnd into RNG
405723A82B7F0000:error:12000079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:106:Filename=/root/.rnd
........+.+......+.....+.......+..+......+....+...+......+..+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.......+..+.........+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*......+...+........+......+....+..+.......+.....+.............+............+...+...+..+....+.....+.............+...............+..+....+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.......+....+......+...+.....+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+..+...+....+........+....+......+...+.....+..........+..+.............+..+.......+......+............+.........+.....+.+.........+......+..+...+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Code (2 letters) [US]:
State or Province Name (full name) []:New York
Locality Name (eg, city) []:New York
Organization Name (eg, company; recommended) []:tutorialspots
Organizational Unit Name (eg, section) []:
Server name (eg. ssl.domain.tld; required!!!) []:tutorialspots.com
Email Address []:tutorialspots@gmail.com
[*] Done generating self signed certificates for exim!
    Refer to the documentation and example configuration files
    over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS
    support in your mail transfer agent.

Now we have 2 files exim.crt exim.key in directory /etc/exim4

In this case, you maybe send email in some cases:
Example 1: with symfony , edit file .env

MAILER_DSN=smtp://user:pass@server_name:25?verify_peer=false&verify_peer_name=false&allow_self_signed=true

Example 2: with Laravel , edit file config/mail.php add line 'verify_peer' => false,

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.gmail.com'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode'  => null,
            'verify_peer' => false,
        ],
        ...

or edit file .env

MAIL_ENCRYPTION=""

But in real work you should use certificate like Let’s encrypt or paid certificate.

Step 2:

sudo systemctl restart exim4.service

Leave a Reply