Send an email via a batch file.

Elcaprio Posted messages 73 Status Membre -  
X.A.N.A. Posted messages 216 Status Membre -
Hello,
Here is my issue, I need to design a small software (specifically I chose a batch file) to monitor remote connections in my company (1 main domain controller and 3 secondary domain controllers for the uninitiated).
In case of connection loss, my batch should send an email to my mailbox (we use Lotus Notes in the company).
Here is where I am:

@echo off
:loop

set /a count=count+1
if %count%==1000 goto :loop
ping 192.xxx.xxx.xxx
ping 192.xxx.xxx.xxx

rem as many pings as there are secondary domain controllers

for /f %%a in (ping 192.xxx.xxx.xxx) do set response=%%
for /f %%a in (ping 192.xxx.xxx.xxx) do set response2=%%

rem as many for as there are pings

if %response%=="request timed out"

At this point, I should put my email sending command, but I can't find the command... I will finish with a goto :loop
I have not tested the command lines above (since I put variables, I have to use them with the if before testing).
Thank you to those who respond!
Just to clarify, I am an intern and I don't have much programming experience (I started in September)
Configuration: Windows XP Internet Explorer 6.0

9 réponses

toto11
 
tout simplement avec:
start mailto:adresse@zzzz.com?subject=subject^&body=MessageBody
37
Iamthenerevar
 
Hello, I have a problem with Blat; when I try to send an email, it says (in quotes lol):
Error: Can't resolve the hostname

I think it can't find the SMTP server, yet I'm using Hotmail for both sender and receiver, and when I installed Blat, I set the server as: smtp.live.fr

Could someone please enlighten me?
2
movie68
 
Good evening,

I think declaring smtp.live.com will work better than smtp.live.fr...

Have a nice evening.
0
Elcaprio Posted messages 73 Status Membre 4
 
Thank you, Toto, I'm going to test it!
I had started off with something much more complicated! lol
I'll keep you updated.

edit: 15/01/2008 4:50 PM
well, after testing, it doesn't work! That said, I might have miswritten the command. I put it like this in my batch:

start mailto: XXX@XXX.fr ?subject="XXX" ^&body= "XXXXXX"

maybe a syntax error?
1
Elcaprio Posted messages 73 Status Membre 4
 
Okay, thanks.
It's complex to set it up as a command...
1
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
Well yes, but an email is a series of parameters:

- from whom?
- to whom?
- who is in CC?
- who is in BCC?
- subject?
- body of the message?
- attachments?
- name of the SMTP sending server

--

See you, Blux
 "Fools dare to do anything. It's even how we recognize them" 
-1
boby
 
Hello Elcaprio, I need an example please ;)

thank you
0
Elcaprio Posted messages 73 Status Membre 4
 
Well, here we are, blat is installed.
Here is a piece of my script:

ping -n 3 254.254.254.254
if %ERRORLEVEL% GEQ 3 goto Mail
:mail
blat message.txt -to xxx-xxx@xxx.fr -s "network error at the router in Caen"
blat message.txt -to xxx-xxx@xxx.fr -s "network error at the router in Caen"

At this point, there's a problem... it sends an email even if the ping responds when it should only send it in case of no response. (hence the IF)

Then I need to tell it to run another script to go down the chain (I ping the router first, if no response the antivirus, if no response the switch, etc...) But I can't remember the command to run the second script :-(
1
movie68
 
Hello,

I know this topic is dated, but a batch is linear, meaning it will check your IF statement, and if the condition is false, it will move to the next line, so it will enter your label :mail.

If the condition is true, it will do what you asked, namely go to the label :mail.
I advise you to do this:


ping -n 3 254.254.254.254
if not %ERRORLEVEL% GEQ 3 goto ok
blat message.txt -to xxx-xxx@xxx.fr -s "network error at the Caen router"
blat message.txt -to xxx-xxx@xxx.fr -s "network error at the Caen router"
:ok
rest of the code

So, if the condition is true, it will go to the label ok and execute the rest of the code. If the condition is false, it will go to the next line and send the emails. Then it will go to the label ok and execute the rest of the code...
0
X.A.N.A. Posted messages 216 Status Membre 19
 
Well, I'm using it, I've set up my ports, etc... and it returns me:

Error: can't resolve service.


Yet I've typed:

blat essais.txt -to xxxxx@xxxx.fr


essais.txt is indeed in the same directory as blat.exe =s

help me please
1
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
What SMTP server name do you have?
0
X.A.N.A. Posted messages 216 Status Membre 19
 
Well, I use my Hotmail messaging, otherwise I'm with Darty.
0
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
I am not asking what you use but what you have configured in blat, with blat -install.
0
X.A.N.A. Posted messages 216 Status Membre 19
 
blat -install xxxxx@hotmail.fr
0
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
What you provided is an email address, but it has no 'legal' existence as data for sending a message.
You need to configure the SMTP server to which you will send your message so that it forwards it to the domain indicated in the destination email address field.
It can be smtp.hotmail.fr..
See the list here:
https://www.commentcamarche.net/faq/893-parametres-de-serveurs-pop-imap-et-smtp-des-principaux-fai
0
Elcaprio Posted messages 73 Status Membre 4
 
I used the mailto command in a second batch to test it separately, it works but it opens Outlook and then waits for me to type the email to send it. My goal is to automate the sending of emails and therefore not to go through any software that requires human intervention...
I thought about netsend but my supervisor really wants it to be an email and not a message...
Please help me...
If it can't be done in batch, could you tell me which language would be the best suited and give me some tips to achieve my goal (besides DOS, I don't know anything)
Thank you for your responses.
0
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
Hi,

You can use blat from the command line. Just install it on your machine...

http://www.blat.net/

--

See you, Blux
 "Fools dare everything. It's even how we recognize them"
0
Elcaprio Posted messages 73 Status Membre 4
 
Thank you, I will test it!
Does it work on all NT?
0
blux Posted messages 2016 Registration date   Status Modérateur Last intervention   3 452
 
It works on win32: win 95, 98, me, nt, 2000, xp, 2003...

--

See you, Blux
 "Fools dare to do anything. That's even how you recognize them"
0
bebeflood
 
I tested it and I still can't find it or I'm mistaken because right now I'm lost
blat message.txt -to m********@hotmail.fr -Install smtp.live.com
0