Configure email delivery

Topics

Configure email delivery for sending PDF reports in Scheduler

The default e-mail client that installs with the Linux CentOS system, which is used by Energylogserver to send reports (Reports chapter), is postfix.

Configuration file for postfix mail client

The postfix configuration directory for CentOS is /etc/postfix. It contains files:

main.cf - the main configuration file for the program specifying the basic parameters

Some of its directives:

Postfix Configuration Directives

Directive

Description

queue_directory

The postfix queue location.

command_directory

The location of Postfix commands.

daemon_directory

Location of Postfix daemons.

mail_owner

The owner of Postfix domain name of the server

myhostname

The fully qualified domain name of the server.

mydomain

Server domain

myorigin

Host or domain to be displayed as origin on email leaving the server.

inet_interfaces

Network interface to be used for incoming email.

mydestination

Domains from which the server accepts mail.

mynetworks

The IP address of trusted networks.

relayhost

Host or other mail server through which mail will be sent. This server will act as an outbound gateway.

alias_maps

Database of aliases used by the local delivery agent.

alias_database

Alias database generated by the new aliases command.

mail_spool_directory

The location where user boxes will be stored.

master.cf - defines the configuration settings for the master daemon and the way it should work with other agents to deliver mail. For each service installed in the master.cf file seven columns define how the service should be used.

Master.cf Column Definitions

Column

Description

service

The name of the service

type

The transport mechanism to be used.

private

Is the service only for user by Postfix.

unpriv

Can the service be run by ordinary users

chroot

Whether the service is to change the main directory (chroot) for the mail. Queue.

wakeup

Wake up interval for the service.

maxproc

The maximum number of processes on which the service can be forked (to divide into branches)

command + args

A command associated with the service plus any argument

access - can be used to control access based on an e-mail address, host address, domain, or network address.

Examples of entries in the file

Access File Examples

Description

Example

To allow access for specific IP address:

192.168.122.20 OK

To allow access for a specific domain:

example.com OK

To deny access from the 192.168.3.0/24 network:

192.168.3 REJECT

After making changes to the access file, you must convert its contents to the access.db database with the postmap command:

postmap /etc/postfix/access
ll /etc/postfix/access*

  -rw-r--r--. 1 root root 20876 Jan 26 2014 /etc/postfix/access
  -rw-r--r--. 1 root root 12288 Feb 12 07:47 /etc/postfix/access.db

canonical - mapping incoming e-mails to local users.

Examples of entries in the file:

To forward emails to user1 to the [user1@yahoo.com] mailbox:

user1 user1@yahoo.com

To forward all emails for example.org to another example.com domain:

@example.org @example.com

After making changes to the canonical file, you must convert its contents to the canonical.db database with the postmap command:

postmap /etc/postfix/canonical
ll /etc/postfix/canonical*

  -rw-r--r--. 1 root root 11681 2014-06-10 /etc/postfix/canonical
  -rw-r--r--. 1 root root 12288 07-31 20:56 /etc/postfix/canonical.db

generic - mapping of outgoing e-mails to local users. The syntax is the same as a canonical file. After you make a change to this file, you must also run the postmap command.

postmap /etc/postfix/generic
ll /etc/postfix/generic*

  -rw-r--r--. 1 root root 9904 2014-06-10 /etc/postfix/generic
  -rw-r--r--. 1 root root 12288 07-31 21:15 /etc/postfix/generic.db

relocated – information about users who have been transferred. The syntax of the file is the same as canonical and generic files.

Assuming the user1 was moved from example.com to example.net, you can forward all emails received at the old address to the new address:

Example of an entry in the file:

<user1@example.com> <user1@example.net>

After you make a change to this file, you must also run the postmap command.

postmap /etc/postfix/relocated
ll /etc/postfix/relocated*

  -rw-r--r--. 1 root root 6816 2014-06-10 /etc/postfix/relocated
  -rw-r--r--. 1 root root 12288 07-31 21:26 /etc/postfix/relocated.d

transport – mapping between e-mail addresses and the server through which these e-mails are to be sent (next hops) in the transport format: nexthop.

Example of an entry in the file:

<user1@example.com> smtp:host1.example.com

After you make changes to this file, you must also run the postmap command.

postmap /etc/postfix/transport
ll /etc/postfix/transport*

  -rw-r--r--. 1 root root 12549 2014-06-10 /etc/postfix/transport
  -rw-r--r--. 1 root root 12288 07-31 21:32 /etc/postfix/transport.db

virtual - user to redirect e-mails intended for a certain user to the account of another user or multiple users. It can also be used to implement the domain alias mechanism.

Examples of the entries in the file:

Redirecting email for user1, to root users and user3:

user1 root,user3

Redirecting email for user 1 in the example.com domain to the root user:

<user1@example.com> root

After you make a change to this file, you must also run the postmap command:

postmap /etc/postfix/virtual
ll /etc/postfix/virtual

 -rw-r--r--. 1 root root 12494 2014-06-10 /etc/postfix/virtual
 -rw-r--r--. 1 root root 12288 07-31 21:58 /etc/postfix/virtual.db

Basic postfix configuration

Base configuration of postfix application you can make in /etc/postfix/main.cf configuration file, which must be completed with the following entry:

  • section # RECEIVING MAIL

    inet_interfaces = all
    inet_protocols = ipv4
    
  • section # INTERNET OR INTRANET

    relayhost = [IP mail server]:25 (port number)
    

In the next step, you must complete the canonical file of the postfix

At the end, you should restart the postfix:

 systemctl restart postfix

Example of postfix configuration with SSL encryption enabled

To configure email delivery with SSL encryption you need to make the following changes in the postfix configuration files:

  • /etc/postfix/main.cf - file should contain the following entries in addition to standard (unchecked entries):

    mydestination = $myhostname, localhost.$mydomain, localhost
    myhostname = example.com
    relayhost = [smtp.example.com]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_tls_CAfile = /root/certs/cacert.cer
    smtp_use_tls = yes
    smtp_sasl_mechanism_filter = plain, login
    smtp_sasl_tls_security_options = noanonymous
    canonical_maps = hash:/etc/postfix/canonical
    smtp_generic_maps = hash:/etc/postfix/generic
    smtpd_recipient_restrictions = permit_sasl_authenticated
    
  • /etc/postfix/sasl_passwd - file should define the data for authorized

    [smtp.example.com]:587 [USER@example.com:PASS]
    [smtp.example.com]:587 username:password
    

You need to give appropriate permissions:

chmod 400 /etc/postfix/sasl_passwd

and map configuration to the database:

postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/canonical
postmap /etc/postfix/generic

next, you need to generate a CA cert file:

cat /etc/ssl/certs/Example_Server_CA.pem | tee -a etc/postfix/cacert.pem

Finally, you need to restart the postfix

systemctl restart postfix

Custom notification on the workstation

The mechanism of personalization of notification at the workstation will be implemented by combining alerting mechanisms, triggering integrated commands, and triggering interaction scripts allowing for the transfer of a personalized notification to the workstation. The notifications will use a specific script, which can inform all logged-in users or the selected one about the detection of individual incidents.

Configuration steps

  1. Create a new alert rule or edit an existing one according to the instruction: Creating Alerts,

  2. In the Alert Method field select the Command method,

  3. Add the following script name to Path to script/command field:

    notifyworkstation.py