Tag: postfix

  • Configure ElasticEmail with Postfix

    To configure ElasticEmail with postfix, first install sasl support

    On Debian/Ubuntu

    apt-get install libsasl2-modules
    

    On RHEL/CentOS

    yum install cyrus-sasl-plain
    

    Edit postfix config

    vi /etc/postfix/main.cf
    

    On Ubuntu/Debian, you need to comment the line starting with “relayhost”.

    Add following

    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_sasl_tls_security_options = noanonymous
    smtp_tls_security_level = encrypt
    header_size_limit = 4096000
    relayhost = [smtp.elasticemail.com]:587
    

    Now create file

    /etc/postfix/sasl_passwd
    

    Add following content

    [smtp.elasticemail.com]:587 YOUR_SMTP_USER:YOUR_SMTP_PASSWORD
    

    You can find your SMTP user name and password from

    https://elasticemail.com/account/#/settings/apiconfiguration

    elasticemail postfix

    Now run

    chmod 600 /etc/postfix/sasl_passwd
    postmap /etc/postfix/sasl_passwd
    

    Restart postfix with

    systemctl restart postfix
    

    Postfix will relay mails using postfix now.

    See postfix

  • Configure Postfix to sent emails using MailGun

    First install requirements

    apt-get update && apt-get install postfix libsasl2-modules -y
    

    Run

    sed -i "s/default_transport = error/# default_transport = error/g" /etc/postfix/main.cf
    sed -i "s/relay_transport = error/# relay_transport = error/g" /etc/postfix/main.cf
    sed -i "s/relayhost =/# relayhost =/g" /etc/postfix/main.cf
    

    Edit /etc/postfix/main.cf

    vi /etc/postfix/main.cf
    

    Add

    relayhost = [smtp.mailgun.org]:2525
    smtp_tls_security_level = encrypt
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    

    Create file /etc/postfix/sasl_passwd

    echo "[smtp.mailgun.org]:2525 SMTP_LOGIN:SMTP_PASSWORD" > /etc/postfix/sasl_passwd
    

    Replace SMTP_LOGIN and SMTP_PASSWORD with your user and password you get from mailgun.

    Run

    postmap /etc/postfix/sasl_passwd
    

    Restart postfix

    service postfix restart
    

    You can test email with

    echo "test" | mail -s "test" [email protected]
    
  • SASL authentication no mechanism available

    When sending email from postfix mail sever that use mailgun for relaying mails, i get error

    Jan 4 03:16:06 serverok-vm postfix/qmgr[22652]: 795731A8D: from=, size=820, nrcpt=1 (queue active)
    Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found
    Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: 795731A8D: SASL authentication failed; cannot authenticate to server smtp.mailgun.org[34.237.7.101]: no mechanism available
    Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found
    Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: 795731A8D: SASL authentication failed; cannot authenticate to server smtp.mailgun.org[34.232.180.42]: no mechanism available
    Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found

    On checking postfix mail queue, the mail is stuck in queue

    root@serverok-vm:~# postqueue -p
    -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
    795731A8D       820 Wed Jan  3 21:38:20  [email protected]
    (SASL authentication failed; cannot authenticate to server smtp.mailgun.org[54.164.235.211]: no mechanism available)
                                             [email protected]
    
    -- 1 Kbytes in 1 Request.
    root@serverok-vm:~# 
    

    The problem is fixed by installing libsasl2-modules.

    On Debian/Ubuntu

    apt-get install libsasl2-modules
    

    On RHEL/CentOS

    yum install cyrus-sasl-plain
    

    Now restart postfix.

    service postfix restart
    
  • postfix no local interface found

    When starting postfix it failed with following error

    [root@cloud1 etc]# service postfix start
    Redirecting to /bin/systemctl start postfix.service
    Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
    [root@cloud1 etc]# service postfix status
    Redirecting to /bin/systemctl status postfix.service
    ● postfix.service - Postfix Mail Transport Agent
       Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since Mon 2017-12-04 09:13:07 UTC; 4s ago
      Process: 21324 ExecStart=/usr/sbin/postfix start (code=exited, status=1/FAILURE)
      Process: 21322 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
      Process: 21319 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=75)
    
    Dec 04 09:13:05 cloud1.serverok.in systemd[1]: Starting Postfix Mail Transport Agent...
    Dec 04 09:13:05 cloud1.serverok.in aliasesdb[21319]: /usr/sbin/postconf: fatal: parameter inet_interfaces: no local interface found for ::1
    Dec 04 09:13:06 cloud1.serverok.in aliasesdb[21319]: newaliases: fatal: parameter inet_interfaces: no local interface found for ::1
    Dec 04 09:13:06 cloud1.serverok.in postfix[21324]: fatal: parameter inet_interfaces: no local interface found for ::1
    Dec 04 09:13:07 cloud1.serverok.in systemd[1]: postfix.service: control process exited, code=exited status=1
    Dec 04 09:13:07 cloud1.serverok.in systemd[1]: Failed to start Postfix Mail Transport Agent.
    Dec 04 09:13:07 cloud1.serverok.in systemd[1]: Unit postfix.service entered failed state.
    Dec 04 09:13:07 cloud1.serverok.in systemd[1]: postfix.service failed.
    [root@cloud1 etc]#
    

    To fix, edit /etc/postfix/main.cf

    Find

    #inet_interfaces = all
    #inet_interfaces = $myhostname
    #inet_interfaces = $myhostname, localhost
    inet_interfaces = localhost
    

    Replace with

    inet_interfaces = all
    

    See postfix

  • install postfix from source code

    Requirements

    yum -y install db4 db4-devel
    

    Create user

    groupadd postfix -g 1000
    useradd postfix -u 1000 -g 1000
    groupadd postdrop 
    

    Download and Install

    Go to

    http://www.postfix.org/download.html

    and download latest version of postfix.

    cd /usr/local/src
    wget http://mirrors.rootservices.net/postfix/official/postfix-2.6.2.tar.gz
    tar -zxvf postfix-2.6.2.tar.gz
    cd postfix-2.6.2
    

    COMPILING

    make tidy
    make -f Makefile.init makefiles
    make
    make install
    

    COMPILING WITH MYSQL SUPPORT

    make tidy
    make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm'
    make
    make install
    

    Now it ask many questions, just enter for every questions. See [[postfix make install questions]]

        Warning: you still need to edit myorigin/mydestination/mynetworks
        parameter settings in 
        
    /etc/postfix/main.cf
    
        See also http://www.postfix.org/faq.html for information about dialup
        sites or about sites inside a firewalled network.
    
        BTW: Check your /etc/aliases file and be sure to set up aliases
        that send mail for root and postmaster to a real person, then run
        /usr/bin/newaliases.
    

    PRESS ENTER FOR ALL

    error while loading shared libraries: libmysqlclient.so.16

    [root@linux postfix-2.5.5]# find / -name 'mysql_version.h'
    /usr/include/mysql/mysql_version.h
    [root@linux postfix-2.5.5]#
    
    [root@linux postfix-2.5.5]#  find / -name 'libmysqlclient.so'
    /usr/lib/mysql/libmysqlclient.so
    [root@linux postfix-2.5.5]#
    

    Show mails in queue

    postqueue -p
    

    VERYFY MYSQL SUPPORT

    [root@linux postfix-2.5.5]# postconf -m
    btree
    cidr
    environ
    hash
    mysql
    nis
    proxy
    regexp
    static
    unix
    [root@linux postfix-2.5.5]#
    

    START POSTFIX ON BOOT

    echo /usr/sbin/postfix start >> /etc/rc.local
    

    Commands listed on /etc/rc.local will run on boot.

    See postfix