How to install send mail from smtp server

To install and configure Sendmail to send emails from an SMTP server, you'll need to follow these steps:

Step 1: Install Sendmail

  1. Ubuntu/Debian: sudo apt-get install sendmail
  2. RHEL/CentOS: sudo yum install sendmail
  3. Fedora: sudo dnf install sendmail

Step 2: Configure Sendmail

  1. Edit the Sendmail configuration file: sudo nano /etc/sendmail.cf

  2. Add the following lines at the end of the file:

    define(`SMART_HOST', `your_smtp_server:25')dnl
    define(`RELAY_HOST', `your_smtp_server')dnl

    Replace your_smtp_server with the hostname or IP address of your SMTP server.

  3. Save and exit the file.

Step 3: Restart Sendmail

  1. Restart the Sendmail service: sudo service sendmail restart (on Ubuntu/Debian) or sudo systemctl restart sendmail (on RHEL/CentOS/Fedora)

Step 4: Test Sendmail

  1. Use the sendmail command to test the configuration:
    echo "Subject: Test email" | sendmail -v -f [email protected] [email protected]

    Replace [email protected] with your email address and [email protected] with the recipient's email address.

Step 5: Configure your application to use Sendmail

  1. Update your application's configuration to use Sendmail as the SMTP server. For example, in PHP, you can use the mail() function with the following settings:
    <?php
    mail('[email protected]', 'Test email', 'This is a test email', 'From: [email protected]');
    ?>

    Make sure to replace the placeholders with your actual email address and recipient's email address.

Additional Tips

By following these steps, you should be able to install and configure Sendmail to send emails from an SMTP server.