1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

send text file In a batch file

Discussion in 'DOS/Other' started by Billd59, Jul 24, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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?
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    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
     
  3. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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.
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    What are you apologizing for. I am just pointing you in the right direction to get you the help you need.
     
  5. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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?
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    Post the exact code you used.
     
  7. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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=[email protected]
    set Subj="email test %date% %time%"
    set Body="did it work? %date% %time%"
    set Serv=smtp.gmail.com:465
    set Auth=[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"
     
  8. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    You are not using the correct code. Look at the link I provided and read it carefully.
     
  9. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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.
     
  10. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    Look at the last set of code in that thread on page 2.
     
  11. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    Is this right one:

    @echo off
    setlocal

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

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    Did you test it?
     
  13. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    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.
     
  14. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,730
    Code:
    set From=[email protected]
    set To=[email protected]
    set Auth=[email protected]
    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.
     
  15. Billd59

    Billd59 Thread Starter

    Joined:
    Feb 7, 2010
    Messages:
    37
    @echo off
    setlocal

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

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1062472