How to send mail with sendmail command line
The classic sendmail
command!
To send an email using the sendmail
command line, you'll need to follow these steps:
Step 1: Prepare your email
Create a text file containing the email message you want to send. The file should have the following format:
To: [email protected]
From: [email protected]
Subject: Your email subject
Your email body
Replace [email protected]
, [email protected]
, and Your email subject
with the actual values.
Step 2: Use the sendmail
command
Open a terminal or command prompt and navigate to the directory where your email file is located. Then, use the following command:
sendmail [email protected] < your_email.txt
Replace [email protected]
with the email address of the recipient, and your_email.txt
with the name of your email file.
Options and flags
You can customize the sendmail
command by adding options and flags. Here are some common ones:
-t
or--input-file
: Specify the input file containing the email message. (Default is-
)-f
or--from
: Set the sender's email address.-s
or--subject
: Set the email subject.-a
or--attach
: Attach a file to the email.-v
or--verbose
: Enable verbose mode, which shows more detailed output.
For example:
sendmail -t -f [email protected] -s "Your email subject" [email protected] < your_email.txt
Tips and variations
- If you want to send an email with a specific SMTP server, you can use the
-S
or--smtp-server
option followed by the server's hostname or IP address. For example:sendmail -t -S smtp.example.com -f [email protected] -s "Your email subject" [email protected] < your_email.txt
- To send an email with a specific port number, use the
-P
or--port
option followed by the port number. For example:sendmail -t -S smtp.example.com -P 587 -f [email protected] -s "Your email subject" [email protected] < your_email.txt
- If you want to send an email with a specific authentication mechanism (e.g., username and password), you can use the
-u
or--username
and-p
or--password
options. For example:sendmail -t -S smtp.example.com -P 587 -u your_username -p your_password -f [email protected] -s "Your email subject" [email protected] < your_email.txt
Remember to replace the placeholders with your actual values and adjust the options and flags according to your needs.