Jump to content

Sending email from the command line for performance alerts.


Recommended Posts

Windows 2003 SP2.

I want to setup a Performance Alert and email myself a message when the Alert is triggered. I'm asking for help with the command syntax. I know you can send an email from the command prompt, I haven't found out how it's done through googling so I'm posting up here.

TIA

Link to comment
Share on other sites


If you have IIS installed, then you could just use a batch file that would execute on the alert. You can set that through the Management Console.

This is an example:

@ECHO OFF
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
:setTempFileName
SET tmp=%RANDOM%
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%

Just insert the appropriate addys and Bob's your uncle! :^)

You could also use telnet. Just open a telnet session, set Local_echo, then connect to your mail server and enter the user and pass ansd go from there. It has been a long time since I did that so I'm unsure of the commands, but I'm sure you could find it in Google. Try telnet+email.

Edited by DonDamm
Link to comment
Share on other sites

I just got back in and thought I'd try try a test email to myself with telnet. Well, it worked.

Just start calling telnet from the command line with the address of an outgoing mailserver followed by the port number (normally 25).

telnet smtp.yourmailserver.name 25

Depending on your mail server you may have to declare your local.domain.name or not with a HELO command. I didn't have to do this with mine, nor did I have to enter a username and password.

the next part is pretty staight forward. Just type your email address:

MAIL FROM: you@youremailaddress.com

and it should come back that the address is ok.

Then type the recipient:

RCPT TO: somenumbnuts@ID10T.com

Next you need to tell it your are going to send data so,

DATA

and it should return a 354 ok to send data response. Here you can put in a subject if you wish like so,

Subject: put subject here

and now type any old text you wish to send...
but when you are finished end by hitting Enter and then putting a period on its own line followed by another Enter
.

At this point you should get a 250 code, Message received (or accepted) with a string of numbers which is the message identifier.

that's it. So, you see it's pretty easy and I'm sure you could batch file it.

If you have any questions about it check RFC822 I think it is.

Link to comment
Share on other sites

I use a CMD utility called BLAT for sending emails. There's no install required...it's just drag-n-drop.

I tried using Blat, I get the message "Error: Server refused connection". I have another issue to work at the moment that's been given a higher priority. So it may be a day or two before I get back to this one. Thanks to both of you for the suggestions. I appreciate the help.

Link to comment
Share on other sites

BLAT definitely works. The error message indicates that your SMTP server isn't going to alloy you to relay email from just any source (this is Good ThingTM, unless of course you want to relay email :)).

Link to comment
Share on other sites

BLAT sounds like an easier way to do it. And nmX.Memnoch is right. If the mail server doesn't allow relaying, then you won't be able to do it this way. Relaying is an important function, but it has also been wildly abused by spammers, so many mail administrators do not allow it.

Link to comment
Share on other sites

BLAT definitely works. The error message indicates that your SMTP server isn't going to alloy you to relay email from just any source (this is Good ThingTM, unless of course you want to relay email :)).

I'm not saying that Blat don't work. :) I'm just saying I get the error message. I'll ask the email admin to look into relaying from the inside. Thanks for cluing me in on the meaning of the error msg.

Don - the code you were gracious enough to send me. I tried it, and it creates a tmp file in c:\inetpub\mailroot\pickup\temp, but I don't receive it via email. Is there something else I need to do to have it emailed to me?

And, on the telnet, I think I need to add a CR\LF at the end of the commands. It works as long as I can hit the <Enter Key> at the end of each command. But in the batch file I need to emulate hitting that <Enter Key>.

Thanks

Link to comment
Share on other sites

Yes, the price is just right. :)

I also like the ability to send HTML formatted messages. I use it in my logon script for generating things like AV defs out of date, etc, etc. Using an HTML formatted email allows me to change the background color of the message depending on the severity of the alert email.

Link to comment
Share on other sites

  • 2 weeks later...

I found this VB script code on Paul Sadowski's scripting page and it works for me. I put the file in the \Windows\System32 subdir and wrote a little batch file to start it with "cscript". I put the batch file in the "Run this Program" field under the Actions tab.

Set objMessage = CreateObject("CDO.Message")

objMessage.Subject = "Diskspace low on server"

objMessage.From = "notifyadmin@domain.org"

objMessage.To = "someone@domain.org"

objMessage.TextBody = "Check disk space"

'==This section provides the configuration information for the remote SMTP server.

'==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server

objMessage.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "emailserver.domain.org"

'Server port (typically 25)

objMessage.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...