This is an old revision of the document!


Overview

Postfix

Set Sender

Add the following line to “/etc/postfix/main.cf”:

sender_canonical_maps = hash:/etc/postfix/sender_canonical

Create “/etc/postfix/sender_canonical” with following content:

user user@domain.com
user email.adress@gmx.net
www-data mail@example.com
root email.adress@gmx.net

Note: The “domain” (and the local user on the system) in the adress MUST exist!! If not - depending on the config from the receiver - the mail will be rejected.

Create Postfix database:

postmap /etc/postfix/sender_canonical

Restart Postfix:

/etc/init.d/postfix restart  

generic

If you run a postfix host without a signed domain such as “localdomain.local” you can't send mails. Therefore you need a “generic mapping”:

Content file “/etc/postfix/generic”:

myaccount@myserver mymailadresse@domain.net

Execute:

postmap /etc/postfix/generic

sasl_password

Content “/etc/postfix/sasl_password”:

mail.domain.net myuser@domain.net:my-strong-secret

Execute:

postmap hash:/etc/postfix/sasl_password

main.cf

/etc/postfix/main.cf “satellite” example:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = test.local
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, dev.local, localhost.local, localhost
relayhost = mail.test.net:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128, 10.0.0.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

# required if you want to send mails to a mailprovider
sender_canonical_maps = hash:/etc/postfix/sender_canonical
smtp_generic_maps = hash:/etc/postfix/generic

smtp_tls_security_level = may
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
smtp_sasl_security_options = noanonymous
#smtp_tls_security_level = encrypt

Transport

/etc/postfix/transport                     #The optional transport table specifies a mapping from email addresses to message delivery transports and next-hop destinations
postmap /etc/postfix/transport             #To rebuild an indexed file after changing the corresponding transport table

Commands

Check mail/ mail content by executing “mailq” or “postqueue -p”:

mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
DB3207206C      465 Thu Mar 23 14:37:38  test@testmail.org
                   (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
                                         test_receiver@linux.de

then:

postcat -q DB3207206C

Check postfix-config:

postconf -n

or

cat /etc/postfix/main.cf

Postfix & DNS

To set Postfix (/etc/postfix/main.cf) to resolv DNS set

smtp_host_lookup = DNS

To set Postfix to listen on /etc/hosts set

smtp_host_lookup = native 

Logging

Logfiles are into

/var/log/mail

or

/var/log/mail.log

Errors are in

mail.warn

or

mail.err  

main.cf

mynetworks = 192.168.1.0/24     #Limit access on Networks
mynetworks = 192.168.1.5/32     #Limit access on IP

Usefull commands

Commandline:

mailq | less                             #Read mail-queue 
mailq | egrep '^--'                      #amount mails in queue
postsuper -d ALL                         #delete all mails in queue
postsuper -d ID                          #delete mail by id ("mailq | less" to get the id!)
postsuper -h ALL                         #all mails on "hold"
postsuper -h ID                          #mail by id on hold
postsuper -H ALL                         #release all mails on hold
postsuper -H ID                          #release mail by id on hold
postqueue -f                             #deliver immediately if to many mails on hold (flush)
postsuper -d ALL deferred                #postpone mails to a future time
newaliases                               #to fix the problem "error: open database /etc/aliases.db: No such file or directory" or recreate aliases.db for postfix

Delete mail by mail-name

mailq | tail +2 | awk 'BEGIN { RS = "" } / user@domain-example\.com$/ { print $1 }' | tr -d '*!' | postsuper -d - 

or

for i in `mailq | egrep "^[0-9A-F]" | grep 'MAILER-DAEMON' | cut -c1-12 | sed s/\*//g` ; \
    do 
    echo "delete msg: $i" ; 
    postsuper -d $i ; 
    done

Check:

mailq

or

 postqueue -p
linux/postfix.1572521689.txt.gz · Last modified: 2019/10/31 12:34 by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki