2011-03-28

Sendmail - How to test sending email, verbosely using Sendmail




Mail Server :

Sendmail

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 [127.0.0.1] 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 [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
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 [127.0.0.1]
>>> 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 !!!

4 comments:

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.