TecGuy Posted April 12, 2010 Posted April 12, 2010 I am stuck trying to use a text file as the body of my Email. This is what i am trying to do: $File = FileOpen("test.txt", 0) While 1 $Raw_err = FileRead($File, 1) If @error = -1 Then ExitLoop WEnd FileClose($File) Sleep(2000) $s_Subject = "Backup Log" $as_Body = $Raw_err Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then ;MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf When I do this my email is blank. Any help would be appreciated.
Negative1 Posted April 12, 2010 Posted April 12, 2010 $Raw_err = FileRead($File, 1) Just a guess but this looks like your problem. You are telling autoit to read the first character to $raw_err. FileRead -------------------------------------------------------------------------------- Read in a number of characters from a previously opened text file. FileRead ( filehandle or "filename" [, count] ) Parameters filehandle The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter. count [optional] The number of characters to read. Default read the entire file. Not optional for file in raw reading mode What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.
Valuater Posted April 12, 2010 Posted April 12, 2010 Note the "Default read the entire file" So, there is no need for the loop. more like.... $File = "C\MyFile.txt" $s_Subject = "Backup Log" $as_Body = FileRead($File) Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then ;MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf not tested 8)
TecGuy Posted April 12, 2010 Author Posted April 12, 2010 Thank you Negative1 you placed me on the right track and thank you Valuater you are correct.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now