# send text file In a batch file



## Billd59 (Feb 7, 2010)

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 (Apr 4, 2003)

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


----------



## Billd59 (Feb 7, 2010)

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 (Apr 4, 2003)

Billd59 said:


> 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 (Feb 7, 2010)

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 (Apr 4, 2003)

Post the exact code you used.


----------



## Billd59 (Feb 7, 2010)

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 [email protected]
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com:465
set [email protected]
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"


----------



## Squashman (Apr 4, 2003)

You are not using the correct code. Look at the link I provided and read it carefully.


----------



## Billd59 (Feb 7, 2010)

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 (Apr 4, 2003)

Look at the last set of code in that thread on page 2.


----------



## Billd59 (Feb 7, 2010)

Is this right one:

@echo off
setlocal

:: defaults
set [email protected]
set [email protected]
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set [email protected]
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 (Apr 4, 2003)

Billd59 said:


> If It Is did I fill It out right?


Did you test it?


----------



## Billd59 (Feb 7, 2010)

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 (Apr 4, 2003)

```
set [email protected]
set [email protected]
set [email protected]l.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 (Feb 7, 2010)

@echo off
setlocal

:: defaults
set [email protected]
set [email protected]
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set [email protected]
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.


----------



## Billd59 (Feb 7, 2010)

I get a error message:


----------



## Squashman (Apr 4, 2003)

```
set Pass=I put my email address In but don't want to show It
```
You mean you put your password in but don't want to show it.

Why are you trying to post a screen shot? The error message should just be text. Just copy and paste the text.


----------



## Billd59 (Feb 7, 2010)

I get a error message: If I try to open the Bat It sending. It saids line 3 subscript out of range source: Microsoft VBscript runtime error.

I made a screen capture of the error. I tried to send It but It doesn't work.


----------



## Billd59 (Feb 7, 2010)

I just didn't want to post my password. When I run the program before I press a key It make a Bat file called email.bat.vbs and If I open that I get a box with a error message and I can't copy and paste the error


----------



## Squashman (Apr 4, 2003)

Are you using the Manage Attachments button to upload your image or are you just trying to copy and paste into the forums?


----------



## Billd59 (Feb 7, 2010)

I am tring to copy and paste I will do Image now. Here Is the error:







I put It on my desktop.


----------



## Squashman (Apr 4, 2003)

You can't copy and paste images into the forums. You need to use the Manage Attachments feature.
click the Go Advanced Button!!!!!!!


----------



## Billd59 (Feb 7, 2010)

I will try to post again the error:


----------



## Squashman (Apr 4, 2003)

Nothing wrong with line 3 of the Vbscript file that the Batch file creates. It gets that argument passed to it when you execute the Batch file.


----------



## Billd59 (Feb 7, 2010)

why Isn't It sending the email? Did you try It?


----------



## Squashman (Apr 4, 2003)

Billd59 said:


> why Isn't It sending the email? Did you try It?


Used it at home and it works.
Can't do it at work because of Firewall rules setup on our network.


----------



## Billd59 (Feb 7, 2010)

I have eset will that block the email from being sent or my router? I am using It at home. Can It be my computer stopping the email? I have windows XP on my desktop which I been using but I have windows 7 on my laptop. Do you think It could be Windows XP stopping the email?


----------



## Squashman (Apr 4, 2003)

It will work on XP and above.

You are getting that error message when you execute the batch file? You are not trying to double click the VBS file are you. It shouldn't even be there after running the BATCH file. It is suppose to get deleted after the batch file is done executing.


----------



## Billd59 (Feb 7, 2010)

I am double clicking on the bat.vbs file. It opens I get "press any key" but It doesn't send the email. So I think It working but for some reason It not sending the email. It tryied disableing eset Virus and firewall that didn't work It still didn't send the email. I check my spam filter the emails not there eighter. I don't know what else to do? Like I say when I run the Bat It opens I get press any key I press a key It closes but no email Is sent.


----------



## Squashman (Apr 4, 2003)

You shouldn't be double clicking on any file with a .VBS extension. You should only be double clicking on files with a .bat extension.


----------



## Billd59 (Feb 7, 2010)

I did that. I don't think I am doing anything wrong. All I am doing Is double click on the Icon and press a key when It ask me to. After I do that I go to my email and see If there Is a email and there Is none. I don't think I am doing anything.

I hope I am not bothering you with this. If I ever become a pain let me know?


----------



## Squashman (Apr 4, 2003)

You shouldn't be getting a Vbscript error when double clicking the batch file you are running.
Turn the ECHO ON at the top of the batch file and then run the batch file again.
See if there are any errors coming out of the batch file itself.


----------



## Billd59 (Feb 7, 2010)

I just did that and I don't see know errors. I tried to copy what I saw and I was going to send It but you can't copy and paste. I run It throw VBScript and I got this:
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Documents and Settings\Bill\Local Settings\Application Data\Adersoft\VbsEdit\Temp\FBVCVJYK.vbs(1, 2) Microsoft VBScript compilation error: Invalid character


***** script completed - exit code: 1 *****
I usally just use notepad as a editor.


----------



## Squashman (Apr 4, 2003)

I have no idea what the heck you are doing.


----------



## Billd59 (Feb 7, 2010)

I was just trying to let you see what I saw. I didn't really see any error when I use notepad. Is there a way I can have what I see go to a file so I can send It to you?


----------



## Billd59 (Feb 7, 2010)

Did you just send me email. It said " "This is a junk email account I use. Do not reply!"


----------



## Squashman (Apr 4, 2003)

Billd59 said:


> Did you just send me email. It said " "This is a junk email account I use. Do not reply!"


I figured out your problem. If you read the link I posted in the DosTips forums in the Batch email thread you would have noticed that you need to supply the full path to the file attachment.

So your file attach variable needs to look like this.

```
set fileattach=C:\Users\Bill\batch files\email\IP.txt
```
Do not put quotes around that. The script does it further down in the code.

But if I were you I wouldn't even screw around with the file attachment.
Just combine the IP.bat with the Email.bat and use the Variable in IP.bat as the Body of your email.


----------



## Billd59 (Feb 7, 2010)

sorry about that I should of notice that. I tried that thank you very much. one more thing Is It easy just to have It automatically delete the IP.txt file and delete the bat file?


----------



## Squashman (Apr 4, 2003)

Billd59 said:


> one more thing Is It easy just to have It automatically delete the IP.txt file and delete the bat file?


This just tells me that you are not even bothering to learn what the code is doing that you are given. You say you are new to all this but if you are not bothering to go through the code and understand how it works then what is the point. You will never be able to do any of this stuff yourself.

Read the code for both of those batch files and answer your own question!


----------



## Billd59 (Feb 7, 2010)

ok I just wanted to know If It was hard to do? I will do It myself. Sorry to bother you.


----------



## Squashman (Apr 4, 2003)

Billd59 said:


> ok I just wanted to know If It was hard to do? I will do It myself. Sorry to bother you.


No it is not that hard at all. It is the most basic command known to every operating system since the dawn of time. It is already in your batch file for emailing!


----------



## Billd59 (Feb 7, 2010)

I did It all ready. I am helping someone. I throught I could email her the Batch file but gmail will not let you email a batch file. She doesn't know muck about computers. She just got her computer. I have to figure some other way to help her. Thanks for your help. I am tring to learn batch and VBScript. Thanks again


----------



## Squashman (Apr 4, 2003)

Use your brain. What are two easy ways you could get her the code for the batch file.


----------



## Billd59 (Feb 7, 2010)

I know ways to do It. I can rename the or I can make It a RAR file. I just want to think of a way she can undo. I don't know If she can rename file or use winrar. I figure making the Batch a exe but gmail doesn't allow you to send EXE files.


----------



## Billd59 (Feb 7, 2010)

I got one question: you know where we put the path In, Is there a way to make It where you don't have to do that? the computer just finds It. I just want to know If that can be done. 
I have It so It delete the IP.txt file and It delete the batch file.


----------



## Squashman (Apr 4, 2003)

Like I said in my previous posts. Don't bother with attaching the file. Just use the VARIABLE that is created with the IP.bat and use that as the body of your message!


----------



## Squashman (Apr 4, 2003)

Billd59 said:


> I know ways to do It. I can rename the or I can make It a RAR file. I just want to think of a way she can undo. I don't know If she can rename file or use winrar. I figure making the Batch a exe but gmail doesn't allow you to send EXE files.


Why would you make a RAR file when every version of Windows since XP has had Native ZIP capability. Why do you always have to make things harder than they have to be.

If people don't know how to rename a file or create a text file then they shouldn't be using a computer in the first place! Tell them to take a class on basic computer concepts. My mother was proactive and did that many many years ago. I very rarely ever have to help her with anything.

In its purest form, a batch file is a TEXT file. You could email her the file as a TEXT file or she could do what you did. Copy and paste it from a forum or email into NOTEPAD and then save it as a BAT file!


----------



## Squashman (Apr 4, 2003)

Why do you need to know her IP address anyways?


----------



## Billd59 (Feb 7, 2010)

I just need the IP to remote to her computer. I can try to send It as a text file.


----------



## Billd59 (Feb 7, 2010)

I read I don't know If It true but I read Gmail won't allow you to zip a Batch file but something with Rar that will work


----------



## Billd59 (Feb 7, 2010)

I got one question: you know where we put the path In, Is there a way to make It where you don't have to do that? the computer just finds It. I just want to know If that can be done. 
I have It so It delete the IP.txt file and It delete the batch file.


----------



## Squashman (Apr 4, 2003)

You aren't reading any of my posts are you? Or at least not understanding them.
You don't need to know her IP address to do remote assistance for her. Plenty of apps and web based solutions that can provide remote assistance without knowing the IP address of the user you are helping.


----------



## Billd59 (Feb 7, 2010)

ok I was going to use the remote that comes with windows. I thought you need the IP address for that one. I am reading all your post. I just thought you needed IP address for all of the remote? I didn;t want to pay for one because I don't plan to use It all the time just once In a while.


----------



## Squashman (Apr 4, 2003)

Are you kidding!
You said this lady barely understands how to use a computer and now you expect her to enable remote desktop connection on her computer and also do the port forwarding on her router so that you can acces her computer!


----------



## Billd59 (Feb 7, 2010)

I was going to set It up for her. You might be right It might be to hard. Maybe I can use log me In and Hamachi or Team-viewer. I heard you can use that free. What ever I use I have to go set It up for her. She lives on the other side of Staten Island. Or If you have any Ideas let me know?


----------



## Squashman (Apr 4, 2003)

No setup for Team Viewer.


----------



## Squashman (Apr 4, 2003)

Wait a minute. Now you are going to go setup stuff on her computer. Why were you screwing around with trying to email the batch file then?


----------



## Billd59 (Feb 7, 2010)

I was just going to use psexec that uses her IPaddress and than I didn't have to go to her house but I don't know what I really should use anymore. I just wanted to learn how to do the batch anyway. I learned alot from that. even If you don't think I did. Like I said I am handicap so It takes me time to learn. If I don't use that file with her computer I will use It somewhere else. Thanks for all your help with It. She also was having trouble with her profile on the computer she get this thing were windows will not reconize her password. So I thought when she get that If I had the IP I could use psexec with the cmd and reset the passwrd with net user command.

What does ping localhost do? I am tiring to find a video or something about that on the Internet. All the video I watch has that In them but they don't explain It.


----------



## Squashman (Apr 4, 2003)

I am sorry to say Bill but you are really way in over your head. You are not going to be able to use psexec to remote into her computer unless you open up a huge gaping whole in her router and firewall for every hacker in the world to take advantage of. I don't suggest you do that!

You really don't understand the basics of most of the things you are trying to do let alone what problems may occur from what you are trying to do. 

Please find someone in your local area that can help you before you make a mistake that you will regret or even worse you may end up causing a lot of problems with the person you are trying to help.


----------



## Billd59 (Feb 7, 2010)

I was planning to use PSexec with Hamachi so I don't have to open any ports. I am trying my best. If I run Into trouble I will ask someone for help. 
I been trying PSExec on my computer. I know I am not a expert but I think I know alittle about computers. I know you are trying to help and any help I will take. I like trying to learn about this kind of stuff. I will learn It but It takes aliitle longer than normal. That's why I like the videos on batch files and VBScript Its easier to learn. I might not get It the first time but I will after a while.

It people like you I learn alot from.


----------



## Billd59 (Feb 7, 2010)

Billd59 said:


> I was just going to use psexec that uses her IPaddress and than I didn't have to go to her house but I don't know what I really should use anymore. I just wanted to learn how to do the batch anyway. I learned alot from that. even If you don't think I did. Like I said I am handicap so It takes me time to learn. If I don't use that file with her computer I will use It somewhere else. Thanks for all your help with It. She also was having trouble with her profile on the computer she get this thing were windows will not reconize her password. So I thought when she get that If I had the IP I could use psexec with the cmd and reset the passwrd with net user command.
> 
> What does ping localhost do? I am tiring to find a video or something about that on the Internet. All the video I watch has that In them but they don't explain It.





Squashman said:


> I am sorry to say Bill but you are really way in over your head. You are not going to be able to use psexec to remote into her computer unless you open up a huge gaping whole in her router and firewall for every hacker in the world to take advantage of. I don't suggest you do that!
> 
> You really don't understand the basics of most of the things you are trying to do let alone what problems may occur from what you are trying to do.
> 
> Please find someone in your local area that can help you before you make a mistake that you will regret or even worse you may end up causing a lot of problems with the person you are trying to help.


 I hope I didn't scare you off. You might be right. Just everyone tells me I can't do stuff.
I am playing aru=ound with the IP program. I am trying to make It write the file In different places. If I post the code can you tell me what I am doing wrong? I am first going to try to figure It out by myself. I think I am using the right code. Does It matter where I put the > then path?


----------

