How to send mail using smtp in linux

To send mail using SMTP in Linux, you can use the sendmail command or a mail client like mutt or msmtp. Here are the steps:

Using sendmail

  1. Install the sendmail package if it's not already installed: sudo apt-get install sendmail (on Ubuntu-based systems) or sudo yum install sendmail (on RHEL-based systems).
  2. Open a terminal and type: sendmail -v -f your_email_address recipient_email_address
    • -v enables verbose mode, which shows the SMTP conversation.
    • -f specifies the sender's email address.
    • your_email_address is the email address you want to use as the sender.
    • recipient_email_address is the email address you want to send the mail to.
  3. You will be prompted to enter the subject and body of the email. Type them in and press Enter.

Using mutt

  1. Install the mutt package if it's not already installed: sudo apt-get install mutt (on Ubuntu-based systems) or sudo yum install mutt (on RHEL-based systems).
  2. Open a terminal and type: mutt -s "Subject" recipient_email_address
    • -s specifies the subject of the email.
    • Subject is the subject you want to use.
    • recipient_email_address is the email address you want to send the mail to.
  3. You will be prompted to enter the body of the email. Type it in and press Enter.

Using msmtp

  1. Install the msmtp package if it's not already installed: sudo apt-get install msmtp (on Ubuntu-based systems) or sudo yum install msmtp (on RHEL-based systems).
  2. Configure msmtp by creating a configuration file in your home directory: nano ~/.msmtprc
  3. Add the following lines to the file:
    defaults
    auth on
    tls on
    from your_email_address
    • defaults specifies the default settings.
    • auth on enables authentication.
    • tls on enables TLS encryption.
    • from your_email_address specifies the sender's email address.
  4. Save and close the file.
  5. Open a terminal and type: msmtp -v recipient_email_address
    • -v enables verbose mode, which shows the SMTP conversation.
    • recipient_email_address is the email address you want to send the mail to.
  6. You will be prompted to enter the subject and body of the email. Type them in and press Enter.

Using a mail client like Thunderbird

  1. Install Thunderbird if it's not already installed: sudo apt-get install thunderbird (on Ubuntu-based systems) or sudo yum install thunderbird (on RHEL-based systems).
  2. Open Thunderbird and create a new email.
  3. Enter the recipient's email address, subject, and body.
  4. Click the "Send" button to send the email.

Note: Make sure you have a working SMTP server and that your email account is configured correctly.