Sendmail - How to test sending email, verbosely using Sendmail

Mail Server :


Purpose :

To verbosely test sending of email using sendmail

Here how :

Prepare a file with name "mail.txt". This will be the email header & contents that we wanna include when test sending this email. The contents of the file should look like below :
To: put_your_email_here@example.com
Subject: Put a subject here
From: to_whoever@example.org

Of cause, here's the place to put the body

The actual command to test sending email :
sendmail -vt < [email file above]

Example of the output :

$ sendmail -vt < ./mail.txt 
put_your_email_here@example.com... Connecting to [] via relay...
220 example.org ESMTP Sendmail 8.14.4/8.14.4; Sat, 26 Mar 2011 20:47:21 +0800 (MYT)
>>> EHLO example.org
250-example.org Hello localhost [], pleased to meet you
250 HELP
>>> MAIL From: SIZE=144
250 2.1.0 ... Sender ok
>>> RCPT To:
>>> DATA
250 2.1.5 ... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 p1QClLLW073679 Message accepted for delivery
put_your_email_here@example.com... Sent (p1QClLLW073679 Message accepted for delivery)
Closing connection to []
>>> QUIT
221 2.0.0 example.org closing connection

Here's another way of test sending of email through sendmail :

printf "Subject: Put a subject here" | sendmail -vf put_your_email_here@example.com to_whoever@example.org

Adios !!!


peppoj said...

Thank you!

I totally missed that "<" redirect before :)

Toby Osbourn said...

Thanks for posting this — Email (especially sendmail) isn't something I need to deal with a lot of the time and your quick post saved me some time today!

shagrat said...

thanks this worked for me.

Anonymous said...

This is a wonderful example. How can I test that the recipient email server would accept the email without actually sending it? My problem with our Linux servers is our email server often goes down, and the linux servers hang, because sendmail keeps trying to re-queue the messages.