Category: Mail

  • Install Mail-in-a-Box

    Mail-In-A-Box is a complete mail server, that included webmail, smtp, imap, pop3.

    https://mailinabox.email

    Installation

    You need Ubuntu 14.04 to install Mail-In-A-Box.

    Before you start installation, make sure you have server hostname set properly.

    To start installation, run

    curl -s https://mailinabox.email/setup.sh | sudo bash
    

    During installation, it ask you to set password for admin email account – me@your-host-name

    Once installation finished, you will be able to login at

    https://YOUR-SERVER-IP/admin

    mail-in-a-box

  • Dovecot

    Dovecot is a IMAP/POP3 server.

    To install on Debian/Ubuntu, run

    apt install dovecot-core -y
    

    To see dovecot config, run

    root@ok:~# doveconf -n
    # 2.2.22 (fe789d2): /etc/dovecot/dovecot.conf
    # Pigeonhole version 0.4.13 (7b14904)
    # OS: Linux 4.4.0-62-generic x86_64 Ubuntu 16.04.3 LTS 
    mail_location = mbox:~/mail:INBOX=/var/mail/%u
    namespace inbox {
      inbox = yes
      location = 
      mailbox Drafts {
        special_use = \Drafts
      }
      mailbox Junk {
        special_use = \Junk
      }
      mailbox Sent {
        special_use = \Sent
      }
      mailbox "Sent Messages" {
        special_use = \Sent
      }
      mailbox Trash {
        special_use = \Trash
      }
      prefix = 
    }
    passdb {
      driver = pam
    }
    ssl = no
    userdb {
      driver = passwd
    }
    root@ok:~# 
    
  • 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

  • Setting up Mail Forwarding in Postfix

    To setup mail forward in postfix,

    Edit postfix config file

    vi /etc/postfix/main.cf
    

    Add

    virtual_alias_domains = /etc/postfix/virtual_alias_domains
    virtual_alias_maps = hash:/etc/postfix/virtual_alias_maps
    

    Create file /etc/postfix/virtual_alias_domains

    vi /etc/postfix/virtual_alias_domains
    

    Add your domains on this file. 1 Per line.

    Example

    [root@s125359 ~]# cat /etc/postfix/virtual_alias_domains
    webhostingneeds.com
    netfreehost.com
    [root@s125359 ~]# 
    

    Here i have 2 domains added, postfix will service as incoming email server for these 2 domains.

    Now create /etc/postfix/virtual_alias_maps, this file will list all email accounts you need and where the email needed to be forwarded to.

    vi /etc/postfix/virtual_alias_maps
    

    Add

    [email protected] [email protected] 
    [email protected] [email protected]  
    

    here email coming to [email protected] and [email protected] get forwarded to [email protected]

    If you need catch all email account, just use

    @yourdomain.com [email protected]
    

    If you want email forwarded to more than one recipient, add them one after other like

    [email protected] [email protected] [email protected]
    

    Now run

    postmap /etc/postfix/virtual_alias_maps
    

    Restart postfix

    systemctl restart postfix
    

    You need to set MX record of your domain to point to server running the postfix mail server to receive mails.

  • 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]
    
  • Check Mail Server Support SSL/TLS

    To check if a mail server support SSL/TLS, run

    openssl s_client -connect MAIL_SERVER_IP:PORT -starttls smtp
    

    Example

    openssl s_client -connect smtp.elasticemail.com:25 -starttls smtp
    

    mail

    openssl

  • spf

    http://www.openspf.org/SPF_Record_Syntax

    Here is some SPF examples

    v=spf1 include:_spf.google.com a a:server10.hosthat.com ip4:147.243.1.48 -all

    DMARC record

    _dmarc.yourdomain.com TXT  "v=DMARC1; p=none"

    If you need to reject email, add

    v=DMARC1; p=reject; pct=100; rua=mailto:[email protected]

    p=quarantine If DMARC failed, remore mail server will accept the mail, but mark it as spam.

    If you just need the report, add

    v=DMARC1; p=none; rua=mailto:[email protected]; ruf=mailto:[email protected];

    [email protected] – This can be any email address to which you need DMARC reports sent. Mail providers sent you report on this, that you can review to make sure no one sending spam mails.

    SPF Tools

    http://www.kitterman.com/spf/validate.html
    http://spf.myisp.ch

    Cpanel Server Block Incoming SPF Failed Mails

  • eximrm

    Here is a bash script to delete mails in exim mail queue. Helpful when you have lot of spam mails in mail queue.

    Create file

    vi /usr/local/bin/eximrm
    

    Add

    #!/bin/bash
     
    exim -bpu | awk '{print $3}' | xargs exim -Mrm
    

    Make it executable

    chmod 755 /usr/local/bin/eximrm
    

    Monitor Server Mail Queue

    Run following script every 1 hour to monitor/alert email queue

    #!/bin/bash
    
    [email protected]
    _limit=250
    
    _result="/tmp/serverok-exim-mailq.txt"
    _queue="`/usr/sbin/exim -bpc`"
    
    if [ "$_queue" -ge "$_limit" ]; then
        echo "Current queue is: $_queue" > $_result
        echo "Summary of Mail queue" >> $_result
        echo "`/usr/sbin/exim -bp | /usr/sbin/exiqsumm`" >> $_result
        mail -s "Number of mails on `hostname` : $_queue" $_mail_user < $_result
        cat $_result
    fi
    
    rm -f $_result 
    
  • 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
    
  • Best Transactional Email Providers

    Many cloud hosting providers, including Google Cloud, AWS, Microsoft Azure, and DigitalOcean, do not support sending emails directly from their servers. They often recommend using a third-party SMTP service for sending emails. Third-party SMTP servers enhance email deliverability and eliminate the need to manage your own email server. When hosting on a shared server, email deliverability can be compromised if another user sends spam, resulting in your IP address being blacklisted. Using a third-party SMTP service ensures consistent email delivery without these risks.

    Below is a comprehensive list of top third-party SMTP service providers ideal for sending emails from your website.

    Smtp2Go

    SMTP2GO is a reliable and scalable email delivery service that provides a robust SMTP server infrastructure for sending emails from anywhere in the world. They offer a free plan for up to 1,000 emails per month, as well as paid plans starting at $25 per month for 50,000 emails.

    https://www.smtp2go.com

    MailJet

    Free account allows you to send 6,000/- emails per month with 200 mails per day limit. Paid plan starts at $9.65 per month for 30k emails.

    https://www.mailjet.com

    Amazon Simple Email Service

    $0.10 per 1,000 emails sent. 65K free emails per month if you are hosted on EC2.

    Disadvantage: You can only send from @your-domain.extn, if you have a SAS application and need to send it from some other email address, you need the domain added to SES and verified.

    To get your Amazon SES service activated, you need to contact Amazon support. Verification is a manual process, can take up to 24 hours. You need to give them information about your use case, how you prevent spam, and how you handle email bounces.

    https://aws.amazon.com/ses/pricing

    SendInBlue

    Up to 300 emails per day for FREE.

    https://www.sendinblue.com/pricing

    ElasticEmail

    No more free plan. Price starts at $0.5 per day + $0.1 per every 1000 emails.

    How much do you have to pay per month if you sent 1000 emails per month?

    Answer: Based on the information you shared, you will be paying $15.10 for 1 month. The amount is broken down to $0.10 for 1000 emails and $0.50 x 30 days = $15.00. This is why the total is $15.10. The daily $0.50 is charged to your account regardless of whether or not you will be sending emails.

    https://elasticemail.com

    SparkPost

    50K Emails for $9 per month. If you are on AWS, you can get it cheaper from marketplace.

    https://www.sparkpost.com

    SendGrid

    Free Plan offers 100 emails per day. Paid Plan starts at 40K email per month for $9.95 per month.

    https://sendgrid.com

    AlibabaCloud DirectMail

    AlibabaCloud DirectMail