title: VBscript - Body of text file into Email
body: <p>i m using the following script to send a few emails during the day, it takes one or more parameters (there are a few versions) and is called by a .bat file. The script is : </p>
  
  <pre><code>Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
  Const cdoBasic = 2
  Const cdoSendUsingPort = 2
  Dim oMsg, oConf
  Dim sDateTimeStamp
  
  Set args = WScript.Arguments 
  arg1 = args(0)
  
  
  ' E-mail properties
  Set oMsg      = CreateObject("CDO.Message")
  oMsg.From     = "myemail@gmail.com"  ' or "Sender Name &lt;from@gmail.com&gt;"
  oMsg.To       = "otheremail@gmail.com"    ' or "Recipient Name &lt;to@gmail.com&gt;"
  oMsg.Subject  = "System Message"
  oMsg.BodyPart.Charset = "Windows-1253"
  oMsg.Textbody = "Attached files." &amp; vbcrlf &amp; _ 
      "This on a new line" &amp; vbcrlf &amp; _ 
      "This on yet another"
  
  
  Const ForReading = 1
  Const ForWriting = 2
  Const ForAppending = 8
  
  Const FileToBeUsed = "DIRTEST.TXT"
  Dim fso, f, g
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
  
  g = f.ReadAll
  
  f.Close
  
  Set f = Nothing
  Set fso = Nothing
  
  
  
  ' GMail SMTP server configuration and authentication info
  Set oConf = oMsg.Configuration
  oConf.Fields(schema &amp; "smtpserver")       = "gmail.com" 'server address
  oConf.Fields(schema &amp; "smtpserverport")   = 587              'port number
  oConf.Fields(schema &amp; "sendusing")        = cdoSendUsingPort
  oConf.Fields(schema &amp; "smtpauthenticate") = cdoBasic         'authentication type
  oConf.Fields(schema &amp; "smtpusessl")       = False             'use SSL encryption
  oConf.Fields(schema &amp; "sendusername")     = "mymy@gmail.com" 'sender username
  oConf.Fields(schema &amp; "sendpassword")     = "XXXXXX"      'sender password
  oConf.Fields.Update()
  
  'base64
  
  ' send message
  oMsg.Send()
  
  ' Return status message
  If Err Then
      resultMessage = "ERROR " &amp; Err.Number &amp; ": " &amp; Err.Description
      Err.Clear()
  Else
      resultMessage = "Success Notification Message sent succesfully."
  End If
  
  Wscript.echo(resultMessage)
  </code></pre>
  
  <p>Right now the text body is set to :</p>
  
  <pre><code>    Attached Files
      This is a new line
      This is yet another
  </code></pre>
  
  <p>I would like to interject a directory listing between line 1 and 2, either directly or by saving the directory listing in a text file, then putting the contents of said file in the email body, like so :</p>
  
  <pre><code>    Attached Files
      06/10/2016  &lt;TIME&gt;            13.000 Name1.txt
      06/10/2016  &lt;TIME&gt;           300.000 Name2.pdf
      06/10/2016  &lt;TIME&gt;           150.000 Name3.pdf
      06/10/2016  &lt;TIME&gt;         5.000.000 Name4.pdf
      This is a new line
      This is yet another
  </code></pre>
  
  <p>EDIT : The above code succesfully appends the dir list to the mail subject, but also appends a batch of gibberish characters at the top. </p>