Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

DOS/Other DOS/Other
Search Search
Search for:
Tech Support Guy > > >

send text file In a batch file


(!)

Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
24-Jul-2012, 07:06 PM #1
send text file In a batch file
I have a batch File that gets my external IPAdress. I have It output to a file. I want It to send that file to a email address?
Here Is the code:
@echo off
>"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")
>>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
>>"%temp%\ip.vbs" echo objHTTP.Send()
>>"%temp%\ip.vbs" echo strHTML = objHTTP.ResponseText
>>"%temp%\ip.vbs" echo wscript.echo strHTML
for /f "tokens=7 delims=:<" %%a in ('cscript /nologo "%temp%\ip.vbs"') do set ip=%%a
echo %ip:~1% > IP.txt
pause

I want IP.txt to a email address?
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
24-Jul-2012, 09:12 PM #2
Bill, we just had a discussion on the dostips forums that you belong to on how to send email from a script. Not sure how you missed it. It was at the top of the forum list for a few days and is still there on the first page.

Emailing with batch.
http://www.dostips.com/forum/viewtopic.php?f=3&t=3566

Last edited by Squashman; 24-Jul-2012 at 09:23 PM..
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
25-Jul-2012, 04:57 PM #3
I thought you can ask question on how to do batch files. I got this In a reply on this website. Sorry so much I will not ask anymore of these question. I just wanted help with batch files. You said don't ask VBScript questions so I thought this was a batch file. I will keep all questions to batch files. I can't help when there reply there told me to do It with VBScript. Like I said I am very sorry and will not do It again.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
25-Jul-2012, 05:36 PM #4
Quote:
Originally Posted by Billd59 View Post
I thought you can ask question on how to do batch files. I got this In a reply on this website. Sorry so much I will not ask anymore of these question. I just wanted help with batch files. You said don't ask VBScript questions so I thought this was a batch file. I will keep all questions to batch files. I can't help when there reply there told me to do It with VBScript. Like I said I am very sorry and will not do It again.
What are you apologizing for. I am just pointing you in the right direction to get you the help you need.
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
25-Jul-2012, 08:13 PM #5
For some reason I got banned from dostips forum. So If you can help me I would be greatful. I tried that code and It didn't send any email to me. I put my hole email address and where It said auth I put my whole email address In.

Sorry about the other email I thought you was from dostip answering my email to ask why I was banned.
That program worked to get my external IP. I just want It to save It to a file (I think I got that) and email It back to my email address?
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
25-Jul-2012, 08:16 PM #6
Post the exact code you used.
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
25-Jul-2012, 09:03 PM #7
Someone else wrote It not me. I am not that good yet.The code I am using Is :

@echo off
>"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")
>>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
>>"%temp%\ip.vbs" echo objHTTP.Send()
>>"%temp%\ip.vbs" echo strHTML = objHTTP.ResponseText
>>"%temp%\ip.vbs" echo wscript.echo strHTML

for /f "tokens=7 delims=:<" %%a in ('cscript /nologo "%temp%\ip.vbs"') do set ip=%%a
echo %ip:~1% > IP.txt

The Email code I found IS:

@echo off
setlocal

:: defaults
set From=
set To=billd59@gmail.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com:465
set Auth=billd59@gmail.com
set Pass=
set fileattach=

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

Last edited by Billd59; 25-Jul-2012 at 09:09 PM..
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
25-Jul-2012, 09:34 PM #8
You are not using the correct code. Look at the link I provided and read it carefully.
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
25-Jul-2012, 10:03 PM #9
I will look at the other codes on dostips. I am not sure what code to use but I will read. Like I said I am not good at Batch files yet but I am learning. I will try to read and understand them.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
25-Jul-2012, 10:07 PM #10
Look at the last set of code in that thread on page 2.
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
25-Jul-2012, 10:17 PM #11
Is this right one:

@echo off
setlocal

:: defaults
set From=billyd59@gmail.com
set To=billd59@gmail.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=billd59@gmail.com
set Pass=
set fileattach=IP.txt

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
pause
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
goto :EOF

:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = objArgs(0)
echo >>"%vbsfile%" objEmail.To = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 465
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
rem


If It Is did I fill It out right?
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
26-Jul-2012, 07:46 AM #12
Quote:
Originally Posted by Billd59 View Post
If It Is did I fill It out right?
Did you test it?
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
26-Jul-2012, 08:06 AM #13
It didn't send the email to me. It opened and I got press a key the Bat opened but know email was sent. Am I doing something wrong? I put my email and password In.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
26-Jul-2012, 08:10 AM #14
Code:
set From=billyd59@gmail.com
set To=billd59@gmail.com
set Auth=billd59@gmail.com
Do you really have two different email addresses with Gmail?
The From and Auth have to be the same. And you have to use the password for that account.
Billd59's Avatar
Billd59 Billd59 is offline
Member with 37 posts.
THREAD STARTER
 
Join Date: Feb 2010
Experience: Beginner
26-Jul-2012, 08:25 AM #15
@echo off
setlocal

:: defaults
set From=billd59@gmail.com
set To=billd59@gmail.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=billd59@gmail.com
set Pass=I put my email address In but don't want to show It
set fileattach=IP.txt

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
pause
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
goto :EOF

:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = objArgs(0)
echo >>"%vbsfile%" objEmail.To = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 465
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
rem

It still doesn't send a email. What am I doning wrong. Is It something stupid I am doing.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑