Sending email from the command line for performance alerts.
#1
Posted 07 May 2007 - 02:03 PM
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
#2
Posted 07 May 2007 - 05:30 PM
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.
This post has been edited by DonDamm: 07 May 2007 - 05:37 PM
#3
Posted 08 May 2007 - 08:13 AM
#4
Posted 08 May 2007 - 09:46 AM
#5
Posted 08 May 2007 - 05:33 PM
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.
#6
Posted 09 May 2007 - 09:15 AM
nmX.Memnoch, on May 8 2007, 10:46 AM, said:
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.
#7
Posted 09 May 2007 - 09:19 AM
#8
Posted 09 May 2007 - 11:24 AM
#9
Posted 09 May 2007 - 11:59 AM
#10
Posted 09 May 2007 - 03:09 PM
nmX.Memnoch, on May 9 2007, 10:19 AM, said:
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
#11
Posted 17 May 2007 - 10:10 AM
#12
Posted 17 May 2007 - 03:28 PM
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.
#13
Posted 31 May 2007 - 04:06 PM
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



Help
Back to top









