Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File; Copying Text to an Email  (Read 9290 times)

0 Members and 1 Guest are viewing this topic.

thenewkid

    Topic Starter


    Starter

    Batch File; Copying Text to an Email
    « on: August 26, 2009, 11:00:24 AM »
    EDIT: Basically, I was to copy text FROM a file, not copy the file (.txt) itself. Thanks again for any help!


    I'm looking to copy text from a file (.txt) and send it inside the body of an email using a batch file.

    Here is the syntax I am using to send the email (which works perfectly via SQL Server Mgt Studio's database mail) from a batch file.

    sqlcmd.exe -E -Q "exec msdb.dbo.sp_send_dbmail @profile_name = 'myname', @recipients = '[email protected]' , @file_attachments = 'attachment.txt', @subject = 'Email' , @body = 'Email text for the file attachment' , @body_format = 'HTML'"

    I would like to take the text OUT OF the file and put it IN THE BODY of the email rather than attaching the text file.

    Any help would be greatly appreciated!
    Thank you

    « Last Edit: August 26, 2009, 03:30:22 PM by thenewkid »

    smeezekitty

    • Guest
    Re: Batch File; Copying Text to an Email
    « Reply #1 on: August 26, 2009, 12:27:55 PM »
    i am sure it has something to do with the type command

    Salmon Trout

    • Guest
    Re: Batch File; Copying Text to an Email
    « Reply #2 on: August 26, 2009, 12:49:27 PM »
    i am sure it has something to do with the type command


    Well that's another problem solved!  ::)


    thenewkid

      Topic Starter


      Starter

      Re: Batch File; Copying Text to an Email
      « Reply #3 on: August 26, 2009, 01:05:22 PM »
      I did find this code, that copies certain parts of a text file and copies it into a new file, but I would ulitmately like to have it output into the body of an email. I'm not sure what/how to change the type command...

      @echo off
      SetLocal EnableDelayedExpansion
      type nul > NewFile.txt
      set StartText=Start Line of Paragraph
      set EndText=End Line which is not Included
      set Flag=0
      for /f "tokens=* delims=" %%a in ('type XCopy.txt') do (
      if /i "%StartText%" EQU "%%a" (set Flag=1)
      if /i "%EndText%" EQU "%%a" (set Flag=0)
      if !Flag! EQU 1 echo %%a >> NewFile.txt)



      Thanks for your response! Any other thoughts on changing the type to output into the email would be extremely helpful!

      macdad-



        Expert

        Thanked: 40
        Re: Batch File; Copying Text to an Email
        « Reply #4 on: August 27, 2009, 04:43:19 PM »
        There have been several topics reguarding this, you'll need a 3rd party program:
        http://www.computerhope.com/forum/index.php/topic,78671.msg518291.html#msg518291
        If you dont know DOS, you dont know Windows...

        Thats why Bill Gates created the Windows NT Family.

        thenewkid

          Topic Starter


          Starter

          Re: Batch File; Copying Text to an Email
          « Reply #5 on: August 31, 2009, 12:36:02 PM »
          Actually, I was able to get the text out of the .txt file by using a query to access the database the report is stored in.

          @query = 'DATABASE NAME.dbo.textfilename'

          Not sure if this will work for all applications, but the email sends out perfectly for me and includes the correct text WITHOUT the attachment.