The /usr/sbin/sendmail -t command allows you to send emails directly from the command line on Unix-like systems. It reads the recipients from the email headers (e.g., To, Cc, Bcc) within the email content. This method is commonly used for automation in scripts or cron jobs.
Steps to Send an Email with /usr/sbin/sendmail -t
Create the Email Content
The email content must include the headers (e.g., To, Subject) followed by the message body.
Example file (email.txt):
Use the sendmail Command
Run the following command to send the email:
- -t: Instructs sendmail to read the recipient addresses (To, Cc, Bcc) from the email headers.
- < email.txt: Feeds the email content to the command.
Example: Combining with echo and heredoc
Using echo:
Using a Heredoc:
Use Cases
Automation
Ideal for sending system alerts or logs in scripts.
Example:
Cron Jobs
Send output or error notifications from scheduled tasks.
Example cron entry:
Testing Email Server Configuration
Useful for verifying if sendmail is properly configured.
Troubleshooting Common Issues
| Issue | Solution |
|---|---|
| Command Not Found |
|
| Emails Not Delivered |
|
| Emails Marked as Spam |
Ensure the sender domain has correct DNS records:
|
| Debugging the Sendmail Command |
Use verbose mode to see detailed output:
echo -e "To: recipient@example.com\nSubject: Test Email\n\nBody content" | /usr/sbin/sendmail -t -v
|
Enhancements and Alternatives
- Use a Lightweight Mail Client:
Instead of sendmail, consider using
mailxormsmtpfor simpler email sending:echo "This is a test email" | mail -s "Subject" recipient@example.com - Send Emails via SMTP:
Use tools like Python’s
smtplibor a service like SendGrid for more control and security.


