Print
Contents[Show]

1. What? 

To quickly test if the sendmail command is working correctly to then use it for example in shell scripts, via command line or even from PHP scripts (PHP supports sendmail to send emails from PHP scripts - you can set the sendmail path in your php.ini), you can issue the below command on your UNIX or Linux system:

# echo "Subject: sendmail test" | sendmail -v This email address is being protected from spambots. You need JavaScript enabled to view it.

This email address is being protected from spambots. You need JavaScript enabled to view it. is obviously the e-mail address you want the test email to be sent to. This sendmail command line example will send a blank email with the subject "sendmail test" to This email address is being protected from spambots. You need JavaScript enabled to view it. if the test is successful.

 

2. Useful tricks if no mail gets sent

# nano /etc/aliases

postmaster: root
postmaster: root
root: This email address is being protected from spambots. You need JavaScript enabled to view it.

# newaliases
/etc/aliases: 77 aliases, longest 17 bytes, 792 bytes total

# service sendmail restart
Redirecting to /bin/systemctl restart sendmail.service
# mailq -qL
/var/spool/mqueue (1 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
wA9D2Iuf023631? 2252 Fri Nov 9 14:02 MAILER-DAEMON
                                     This email address is being protected from spambots. You need JavaScript enabled to view it.

# sendmail -v -qwA9D2Iuf023631 -d11

 

 

Sources

https://clients.javapipe.com/knowledgebase/132/How-to-Test-Sendmail-From-Command-Line-on-Linux.html

https://tecadmin.net/ways-to-send-email-from-linux-command-line/

https://www.jeffgeerling.com/blogs/jeff-geerling/configure-sendmail-centos

https://serverfault.com/questions/576405/redirect-mail-from-system-user-account-to-real-email-account

https://serverfault.com/questions/239261/sendmail-ignore-local-delivery/241703#241703

 

 

 

 

 

 

 

Hits: 1161