Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Ever since a windows update that took down my IIS6 mail server a few weeks back, I've been really paranoid about my mail server working.

So every time I run a windows update I fire up command prompt and send myself a quick test mail.

Like so:

> telnet localhost 25
> helo domain.com
> mail from: me@mydomain.com
> rcpt to: you@mydomain.com
> data
some random body to mail myself
.

This is a realy great way to test my mail server, but it's a pain in the neck to do quickly. Is there anyway i can run this in a batch script or something as a quick test?

I've tried a bat file but this just waits after i call telnet I've also explored if telnet accepts any input files and it does not seem to.

What's the best way to do this?

share|improve this question

4 Answers 4

up vote 3 down vote accepted

There's a command line utility called blat that can be used to send e-Mail in Windows.

In UNIX, you could use the userland tool to interact with the queue. Most MTAs have /usr/sbin/sendmail equivalents symlinked from the same location. The mail utility is available on most systems as well.

I'm entirely on board with Chris' monitoring recommendation, if you don't already have monitoring. Otherwise, verification of functionality after a change makes plenty of sense.

share|improve this answer
    
I use blat on a regular basis (auto-emails everyday) on a WinServer 2003 and it works well. All commands can be run from batch file. –  Scott Lundberg May 26 '10 at 18:54
    
perfect, exactly what I was looking for! –  WebDude Jun 3 '10 at 19:29

PowerShell is your friend. Check out the send-mailmessage cmdlet.

http://technet.microsoft.com/en-us/library/dd347693.aspx

$date = get-date
send-mailmessage -from "User <Sender@domain.com>" -to "Recipient <recipient@domain.com>" -subject "Test message $date" -smtpserver mailserver.domain.com

Save that into a notepad file named send-testsmtpmessage.ps1 and run it from PowerShell. You can even setup a bat file that invokes PowerShell and the script just by clicking on the file. Done.

The email will read with the subject line of something like this:

Test message 05/27/2010 23:02:04

share|improve this answer
    
That syntax looks like a direct copy of what Blat uses. :) –  John Gardeniers May 28 '10 at 5:05
    
the looked like an ideal solution. unfortunately I only have Powershell 1.0 and this required Powershell 2.0 Getting blat to work was easier than figuring out how to install powershell 2 on Windows Server 2008 R1. I Will try this when i move over to R2 –  WebDude Jun 3 '10 at 19:30

You could have Servers Alive sat running to test the server and any services that you want to monitor - this a couple of add-ons that do mail flow checking which may work for you.

share|improve this answer

I addition to Blat, which Warner mentioned, there are a number of other command line mailers for Windows. You can also do the same through a variety of programming and scripting languages. Perl makes things especially easy. I've even seen Powershell examples in answers to other questions on this site, although that is the most cryptic scripting language I've seen for many years.

share|improve this answer
    
War_ner_ not Warren. –  Ward May 26 '10 at 19:42
    
My apologies. Rectified. –  John Gardeniers May 26 '10 at 21:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.