Results 1 to 2 of 2

Thread: Email script that imports data from .txt files

  1. #1

    Thread Starter
    Junior Member Ragnoth's Avatar
    Join Date
    Feb 2012
    Posts
    28

    Email script that imports data from .txt files

    Basically...this script is tied to a program I created that generates the text files...I am trying to make it grab the text from the Subject.txt and put into the subject line and same thing with the body of the e-mail just using the body.txt

    It does not seem to be working...

    Code:
    Set myNetwork = WScript.CreateObject("WScript.Network")
    
    
    Dim myUserName
    Dim myComputerName
    
    Dim ol, ns, newMail
    
    myUserName = myNetwork.UserName
    myComputerName = myNetwork.Computername
    
    
    
    Set ol = WScript.CreateObject("Outlook.Application")
    Set ns = ol.getNamespace("MAPI")
    ns.logon myUserName,"password" ',true, false
    Set newMail = ol.CreateItem(olMailItem)
    
    newMail.To = "myemail@gmail.com"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\users\public\documents\body.txt", 1)
    Set objFile2 = objFSO.OpenTextFile("C:\users\public\documents\Subject.txt", 1)
    
    Do Until objFile.AtEndOfStream
        strCharacters = objFile.Read(1)
    
    
    newMail.Subject =  myUserName & Wscript.Echo strCharacters
    
    Do Until objFile2.AtEndOfStream
        strCharacters = objFile2.Read(1)
    
    
    newMail.Body = Wscript.Echo strCharacters & FormatDateTime(Now(), vbGeneralDate)
    
    newMail.Send

  2. #2

    Thread Starter
    Junior Member Ragnoth's Avatar
    Join Date
    Feb 2012
    Posts
    28

    Re: Email script that imports data from .txt files

    I think I may have figured it out myself...will marked resolved in a min if I did....and Fail though my code is slightly different now

    here it is now
    Code:
    Set myNetwork = WScript.CreateObject("WScript.Network")
    
    
    Dim myUserName
    Dim myComputerName
    
    Dim ol, ns, newMail
    
    myUserName = myNetwork.UserName
    myComputerName = myNetwork.Computername
    
    
    
    Set ol = WScript.CreateObject("Outlook.Application")
    Set ns = ol.getNamespace("MAPI")
    ns.logon myUserName,"password" ',true, false
    Set newMail = ol.CreateItem(olMailItem)
    
    newMail.To = "myemailaddress"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\users\public\documents\body.txt", 1)
    Set objFile2 = objFSO.OpenTextFile("C:\users\public\documents\Subject.txt", 1)
    
    Do Until objFile.AtEndOfStream
        strCharacters = objFile.Read(1)
    
    Dim Subject
    Set Subject = WScript.StdOut.Write(strCharacters)
    
    newMail.Subject =  myUserName & " " & Subject
    loop
    
    
    Do Until objFile2.AtEndOfStream
        strCharacters2 = objFile2.Read(1)
    
    Dim body
    Set body = WScript.StdOut.Write(strCharacters2)
    
    newMail.Body = body & " " & FormatDateTime(Now(), vbGeneralDate)
    loop
    newMail.Send
    Last edited by Ragnoth; Apr 6th, 2012 at 05:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width