How does the mail command send an email from the command line?

The mail command is a simple command-line utility used to send and receive emails. To send an email using the mail command, you can follow these steps:

Basic Syntax

The basic syntax for sending an email is as follows:

mail -s "Subject" recipient@example.com

Steps to Send an Email

  1. Open the Terminal: Launch your terminal application.

  2. Use the mail Command:

    • To send an email, type the command with the subject and recipient's email address:
      mail -s "Your Subject Here" recipient@example.com
  3. Compose the Email:

    • After entering the command, press Enter. You will be prompted to enter the body of the email. Type your message.
  4. End the Email:

    • To finish composing the email, press Ctrl + D (EOF - End of File) on a new line. This will send the email.

Example

Here’s an example of sending an email:

mail -s "Meeting Reminder" john.doe@example.com

After pressing Enter, type your message, and then press Ctrl + D to send it.

Additional Options

  • CC/BCC: You can add CC or BCC recipients by using the -c or -b options, respectively:

    mail -s "Subject" -c cc@example.com -b bcc@example.com recipient@example.com
  • Attachments: To send an email with an attachment, you can use the -a option:

    mail -s "Subject" -a /path/to/file recipient@example.com

Note

Make sure that your system is configured to send emails (e.g., with a mail transfer agent like Postfix or Sendmail) for the mail command to work properly.

0 Comments

no data
Be the first to share your comment!