Spacetrucker Posted May 7, 2007 Posted May 7, 2007 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
DonDamm Posted May 7, 2007 Posted May 7, 2007 (edited) 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 OFFREM send email from command line via IISREM change this path to point to IIS's pickup directorySET root=c:\InetPub\MailRoot\PickupREM set up temp and eml filenamesIF NOT EXIST %root%\temp MKDIR %root%\temp:setTempFileNameSET tmp=%RANDOM%IF EXIST %root%\temp\%tmp%.tmp GOTO setTempFileNameSET eml=%root%\%tmp%.emlSET tmp=%root%\temp\%tmp%.tmpREM build the email. ^ is the escape characterECHO 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 deliveryRENAME %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 May 7, 2007 by DonDamm
Spacetrucker Posted May 8, 2007 Author Posted May 8, 2007 Don, many thanks for the code and the suggestion. I'll try this today.
nmX.Memnoch Posted May 8, 2007 Posted May 8, 2007 I use a CMD utility called BLAT for sending emails. There's no install required...it's just drag-n-drop.
DonDamm Posted May 8, 2007 Posted May 8, 2007 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 25Depending 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.comand it should come back that the address is ok.Then type the recipient:RCPT TO: somenumbnuts@ID10T.comNext you need to tell it your are going to send data so,DATAand 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 hereand 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.
Spacetrucker Posted May 9, 2007 Author Posted May 9, 2007 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.
nmX.Memnoch Posted May 9, 2007 Posted May 9, 2007 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 ).
DonDamm Posted May 9, 2007 Posted May 9, 2007 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.
nmX.Memnoch Posted May 9, 2007 Posted May 9, 2007 Where I work we can relay from any internal source to any internal destination address. To relay externally, the source has to be setup as an allowed relayer.
Spacetrucker Posted May 9, 2007 Author Posted May 9, 2007 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
DennisT Posted May 17, 2007 Posted May 17, 2007 I've used blat quite a bit. It's now one of those "included in a server build" applications. The price is right too.
nmX.Memnoch Posted May 17, 2007 Posted May 17, 2007 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.
Spacetrucker Posted May 31, 2007 Author Posted May 31, 2007 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 ServerobjMessage.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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now