Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Mail Servers»How to Install Sendmail on Ubuntu 18.04 & 16.04 LTS

    How to Install Sendmail on Ubuntu 18.04 & 16.04 LTS

    By RahulNovember 23, 20203 Mins Read

    Sendmail is a general purpose email routing facility used for email transport over the Internet. It includes SMTP (Simple Mail Transfer Protocol) for the mail-transfer and email delivery. Most of the system administrators preferred to use Sendmail server as MTA than other MTAs. You can also use Sendmail server to send the email via external SMTP servers like Gmail, Amazon SES, MailChimp etc.

    Advertisement

    1. Remove Postfix

    Postfix is the default SMTP service pre-installed on Ubuntu operating systems. And you are willing to use Sendmail server on your system.

    First of all, remove the existing postfix installation on Ubuntu.

    sudo systemctl stop postfix
    sudo apt remove postfix && apt purge postfix
    

    2. Install Sendmail

    If you don’t have installed Sendmail using the following command to install Sendmail with other required packages using yum package manager.

    sudo apt install sendmail
    

    3. Configure Sendmail Server

    The execute the sendmailconfig command to complete the basic configuration.

    sudo sendmailconfig
    

    Select all options to ‘Y’ and press enter. Wait for the command finish.

    Your server is ready for sending emails. You can use the Linux command line or PHP script to send emails.

    4. Receive Incomming Emails

    Edit /etc/mail/sendmail.mc file and comment below line to allow receiving an email from anywhere. To comment a line in sendmail.mc, just put dnl keyword at the start of the line.

    dnl DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
    dnl DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
    

    Then add your domain names to /etc/mail/local-host-names file.

    cat /etc/mail/local-host-names
    
    tecadmin.net
    mail.tecadmin.net
    localhost
    localhost.localdomain
    

    Now use m4 is a macro processor to compile the Sendmail configuration files. m4 is stream-based, that is, it doesn’t understand about lines.

    sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
    

    Restart Sendmail service

    sudo systemctl restart sendmail
    

    Your system is ready for incoming emails.

    5. Configure Domain-based E-mail Routing

    As we read above that virtusertable file used for aliasing, allowing multiple virtual domains to be hosted on one machine.

    • 1. All emails addressed to @example.com domain delivered to [email protected]
      @example.com [email protected]
      
    • 2. All emails addressed to [email protected] will forward to local user jack.
      [email protected]  jack
      
    • 3. All emails addressed to @mydomain.com will forward to domain @otherdomain.com with corresponding usernames.
      @mydomain.com    %[email protected]
      
    • 4. All emails addressed to @otherdomain.com will be rejected my mail server with acknowledging sender with the message
      @otherdomain.com 	 error:nouser User unknown
      

    After making all changes in virtusertable execute following command to create updated virtusertable.db file containing the new configuration.

    sudo makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable
    

    Now restart Sendmail service

    sudo /etc/init.d/sendmail restart
    

    Thanks for reading this article. I hope this article will help you to configure Sendmail on Ubuntu Linux systems.

    References:
    http://www.sendmail.com/
    http://www.sendmail.com/sm/open_source/docs/m4/intro_m4.html

    Postfix sendmail smtp
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Configuring Sendmail through the External SMTP relay

    Postfix: Sending Emails From External SMTP Servers

    Postfix: Sending Emails From External SMTP Servers

    Postfix: Configure SASL Authentication for Remote SMTP

    Postfix: Configure SASL Authentication for Remote SMTP

    View 8 Comments

    8 Comments

    1. Chris on July 21, 2021 8:40 pm

      if you have the problem: “bash: /etc/mail/sendmail.cf: Permission denied”, try this:
      sudo sh -c “sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf”

      Reply
    2. Ax on March 14, 2021 2:22 am

      I have the same problem as Praveen Kumar.

      Reply
    3. Praveen Kumar on February 15, 2021 8:47 am

      sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

      When i run this command i found the following error:
      -bash: /etc/mail/sendmail.cf: Permission denied

      Please suggest me what can i do, i am new bee in ubuntu server. can we skip this step ??

      Reply
      • Tou on April 20, 2021 7:31 pm

        log into root user
        command su –

        Reply
    4. Jordan on November 15, 2019 7:06 am

      Hi, Rahul, I hope all is well. I am having trouble with your directions. I am unsure what the virtusertable is or how to edit it properly. Could you explain these directions a little more for me?

      Reply
    5. Redouane on June 11, 2019 4:42 am

      Useful. Thank you very much

      Reply
    6. Matt on May 22, 2019 10:16 am

      You are my hero

      Reply
    7. Mack patel on February 25, 2019 12:47 pm

      Nice post! Thanks for sharing this.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.