Jump to content

Using a Text file for the Body of an Emal


Recommended Posts

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...