fake sendmail for windows

fake sendmail
© byron jones
bsd license

unfortunately i no longer have the time or resources to provide any support or updates to sendmail.


sendmail.exe is a simple windows console application that emulates sendmail's "-t" option to deliver emails piped via stdin.

it is intended to ease running unix code that has /usr/lib/sendmail hardcoded as an email delivery means.

it doesn't support deferred delivery, and requires an smtp server to perform the actual delivery of the messages.


using fake sendmail

generally all you need to do is install sendmail.exe in \usr\lib, and existing code that calls /usr/lib/sendmail will work.

if you're coding new applications, all you need to do is construct your email message with complete headers, then pipe it to /usr/lib/sendmail -t

for example, to use fake sendmail from the command line:

REM send email from command line via SMTP with sendmail

ECHO From: byron@example.com > %TEMP%\temp.mail
ECHO To: someone-else@example.com >> %TEMP%\temp.mail
ECHO Subject: this is a test >> %TEMP%\temp.mail
ECHO.>> %TEMP%\temp.mail
ECHO testing. >> %TEMP%\temp.mail
ECHO blah blah.. >> %TEMP%\temp.mail
ECHO. >> %TEMP%\temp.mail
ECHO blah. >> %TEMP%\temp.mail

sendmail -t < %TEMP%\temp.mail

DEL %TEMP%\temp.mail

note ECHO. puts a blank line in the file, not a line with a single period on it.

note: if you have IIS installed, you can send emails without any third party programs (you do NOT need my sendmail wrapper).

REM send email from command line via IIS

REM change this path to point to IIS's pickup directory
SET root=c:\InetPub\MailRoot\Pickup

REM set up temp and eml filenames
IF NOT EXIST %root%\temp MKDIR %root%\temp
IF EXIST %root%\temp\%tmp%.tmp GOTO setTempFileName
SET eml=%root%\%tmp%.eml
SET tmp=%root%\temp\%tmp%.tmp

REM build the email.  ^ is the escape character
ECHO From: bob.smith@example.com> %tmp%
ECHO To: sally.jones@example.com>> %tmp%
ECHO Subject: Example>> %tmp%
ECHO Content-Type: text/html>> %tmp%
ECHO.>> %tmp%
ECHO ^<b^>This is a test^</b^>>> %tmp%

REM move the temp file into the pickup directory for delivery
RENAME %tmp% %eml%


msmtp is an excellent open-source sendmail replacement.

while it's possile to send email from the command line or a batch file using fake sendmail, blat is a fantastic open-source utility which will allow you to easily send emails with attachments.


range check error

i've had a few reports of sendmail returning a "range check error". i have tracked this to a bug in the indy sockets library and it has been fixed in version 18.

socket error # 10053 software caused connection abort

some anti-virus products limit what applications are allowed to send mail via port 25 (SMTP). ensure that sendmail.exe is in your list of approved applications.

socket error # 11004 valid dns name - no data record of requested type

socket error 11004 means that the dns server which sendmail is talking to does not have a record of the appropriate type for the com puter name which it was looking up.

this can happen if the dns server is currently incorrectly configured (check with your isp, or whoever is running the dns server you are using) or because you should be using a different computer name which would have an a record defined.

in some cases it can also happen because you are using the incorrect dns server addresses (eg using the dns servers of one isp when you are dialing into a second isp).

550 relaying denied, 572 relay not authorized, 554 relay access denied

it means that you have been denied access to that smtp server by its administrator. administrators prevent abuses of their smtp relay servers by requiring that you send e-mail only from a computer connected to their network, or that you use some type of authentication.

talk to the server's administrator and ask what are the requirements for connecting to the server. sometimes, the server may need to be reconfigured.

issues running on windows 8+

http://stackoverflow.com/q/21337859 details a workaround for this which involves running sendmail.exe in "windows xp sp 3" compatibility mode as administrator.


sendmail sets the ERRORLEVEL to 0 when successful.

versions prior to version 28 set the ERRORLEVEL to 1 if the email was unable to be delivered.
version 28 and high set the ERRORLEVEL to -1 if the email was unable to be delivered.

the value was changed to provide better compatibility with PHP, which expects the ERRORLEVEL to be -1 on failure. should you require an updated version which sets the ERRORLEVEL to 1, don't hesitate to let me know.

debug logging

uncomment the debug_logfile entry in sendmail.ini resend a failed message. this should create debug.log in the same directory as sendmail.exe showing the complete SMTP transcript.

license and source

this program is released under the bsd license.

the license details and full source (delphi 2007) are included in the zip.