Send an email via a batch file.
Elcaprio
Posted messages
73
Status
Membre
-
X.A.N.A. Posted messages 216 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)
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
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?
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?
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?
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?
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 :-(
Here is a piece of my script:
ping -n 3 254.254.254.254
if %ERRORLEVEL% GEQ 3 goto 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 :-(
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...
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...
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
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
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
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
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.
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.
Hi,
You can use blat from the command line. Just install it on your machine...
http://www.blat.net/
--
See you, Blux
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"