How to send mail using sendmail in unix
Sendmail is a popular mail transfer agent (MTA) used in Unix-like operating systems to send and receive emails. Here's a step-by-step guide on how to send mail using sendmail in Unix:
Prerequisites:
- Make sure you have sendmail installed on your system. You can check by running the command
sendmail -v
(with the-v
option for verbose mode). - You need to have a valid email address and a mail server configured on your system.
Sending a mail using sendmail:
- Open a terminal and navigate to the directory where you want to send the mail from.
- Use the
sendmail
command followed by the recipient's email address and the subject of the mail. For example:sendmail -v [email protected] "Subject: This is a test mail"
Replace
[email protected]
with the actual email address of the recipient, andSubject: This is a test mail
with the subject of the mail.
Options:
You can use various options with the sendmail
command to customize the mail. Here are some common options:
-v
: Verbose mode, which displays the mail headers and body.-t
: Treat the input as a file, rather than reading from standard input.-f
: Specify the sender's email address.-s
: Specify the subject of the mail.-a
: Specify the attachment file(s).
For example, to send a mail with a attachment, you can use the following command:
sendmail -v -t -f [email protected] -s "Subject: This is a test mail" -a attachment.txt [email protected]
Replace [email protected]
with your email address, attachment.txt
with the name of the attachment file, and [email protected]
with the recipient's email address.
Tips:
- Make sure you have a valid email address and a mail server configured on your system.
- You can use the
mail
command instead ofsendmail
if you have it installed on your system. - You can also use a text editor to create a mail file and then use the
sendmail
command to send the mail. For example:echo "Subject: This is a test mail" > mail.txt echo "This is a test mail" >> mail.txt sendmail -v [email protected] < mail.txt
This will create a file named
mail.txt
with the subject and body of the mail, and then send the mail usingsendmail
.