How to send mail with sendmail
Sendmail is a popular open-source mail transfer agent (MTA) that allows you to send and receive emails on a Linux or Unix-based system. Here's a step-by-step guide on how to send mail using sendmail:
Prerequisites:
- Sendmail must be installed and configured on your system.
- You need to have a valid email address and a mail server (SMTP) to send the email.
Sending an email using sendmail:
- Open a terminal or command prompt on your system.
- Use the following command to send an email:
sendmail -v -t <recipient_email_address>
Replace
<recipient_email_address>
with the actual email address of the recipient.
The -v
option enables verbose mode, which displays the email headers and body. The -t
option tells sendmail to read the email message from standard input.
- Type the email message, including the subject and body, and press Enter. The message will be sent to the recipient.
Example:
sendmail -v -t [email protected]
To: [email protected]
Subject: Test email from sendmail
This is a test email sent using sendmail.
- Press Enter to send the email.
Sending an email with attachments:
To send an email with attachments, you can use the -i
option to specify the attachment file. For example:
sendmail -v -t -i attachment.txt [email protected]
This will send the email with the attachment file attachment.txt
.
Sending an email with a specific sender:
To send an email with a specific sender, you can use the -f
option to specify the sender's email address. For example:
sendmail -v -t -f [email protected] [email protected]
This will send the email with the sender's email address set to [email protected]
.
Tips and Variations:
- You can use the
-s
option to specify the subject of the email. For example:sendmail -v -t -s "Test email from sendmail" [email protected]
- You can use the
-c
option to specify the content type of the email. For example:sendmail -v -t -c text/plain [email protected]
- You can use the
-a
option to specify additional headers for the email. For example:sendmail -v -t -a "X-Priority: High" [email protected]
- You can use the
mail
command instead ofsendmail
to send an email. Themail
command is a wrapper around sendmail and provides a more user-friendly interface.
Remember to replace <recipient_email_address>
with the actual email address of the recipient, and adjust the options and arguments according to your specific needs.