Jump to content

[Solved] Email Script Source Only when Compiled?


GoogleDude
 Share

Recommended Posts

I searched for a few different terms to see what I came up with but nothing really came back that was relevent.

I am trying to find a way that when I compile a script it emails a copy of the uncompiled script to me. I found that gmail smtp UDF and it works and allow me to attach a file but since its a UDF I am not sure how to make it dynamic to the orignal source I am coding up? If that comes out right?

I see that AutoIt has a way to run a DOS cmd before and or after the script is compiled but since the script source will always be different I am not sure how that will work? I was thinking of adding a RUN before Or after the script is compiled to use the gmail smtp script as a command line swtich. something like C:\gmail_smtp.exe /@ScripFullPath as the attachment but that didnt work. So I am not sure how to achieve such function?

Bottom line is I want to include the uncompiled script @ compile time only. Not everytime the compiled script is run. Is there a UDF or way to do this? That way I can use it in future scipts I write and have indefenit access to the script (incase I loose my copy of the source).

Thanks,

GoogleDude

Edited by GoogleDude
Link to comment
Share on other sites

As an example I have made a script to automate AutoITwrapper with WinWaits and ControlClicks. I have made a registry entry to make this Script (I call AutoITGUIAuto.exe) as my default compiler. You could do the same only your script would email the script with the Gmail UDF and then call the compiler. Here is my Script as an example

#include <Array.au3>
#include <Misc.au3>
_Singleton(@ScriptName, 0)

Opt('TrayIconDebug', 1)
Opt('WinTitleMatchMode', 4)
Opt('WinWaitDelay', 10)

Local $List
If $Cmdline[0] = 0 Then
    $List = _GetFiles('AutoIT Scripts (*.au3)', @DesktopDir)
Else
    $List = $Cmdline
EndIf

For $i = 1 To $List[0]
    _CompileAu3Script($List[$i])
Next

Func _CompileAu3Script($pScript)
    Local $Title = '[TITLE:AutoIt3Wrapper GUI to Compile AutotIt3 Script (ver 1.10.1.14); CLASS:AutoIt v3 GUI]'
    Local $Button = '[CLASS:Button; INSTANCE:28]'
    Local $Split, $String, $Result = 0, $File
    If StringInStr(FileRead($pScript), '/bdir=') Then
        $String = FileRead($pScript)
        $String = StringRegExpReplace($String, '(?m)(?i)(.*)(/bdir=)(.*)$', '$1$2' & StringReplace(@TempDir, '\', '\\') & '\\')
        Do
            FileOpen($pScript, 2)
        Until Not @error = -1
        $File = FileWrite($pScript, $String)
        Do
            $Result = FileClose($File)
        Until $Result = 1
    EndIf
    $Split = _PathSplitByRegExp($pScript)
    If $Split[7] <> 'au3' Then Return SetError(1, 0, 0)
    $Outfile = $Split[3] & '.exe'
    $Obfuscated = $Split[3] & '_Obfuscated.' & $Split[7]
    If Not FileExists($pScript) Then Return SetError(1, 0, 0)
    $bCompiler = @ProgramFilesDir & '\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper_Gui.exe'
    $aSplitString = StringSplit($pScript, "\")
    $Compile = Run($bCompiler & ' /in "' & $pScript & '" /out "' & $Outfile & '"')
    ProcessWait('AutoIt3Wrapper_Gui.exe')
    WinSetState($Title, '', @SW_HIDE)
    Do
        Sleep(10)
    Until WinExists($Title, 'Autoit3 version to use:')
    WinSetState($Title, '', @SW_HIDE)
    If Not ControlClick($Title, '', $Button) Then
        WinWait($Title, '', 2)
        ControlClick($Title, 'Autoit3 version to use:', '[CLASS:Button; INSTANCE:30]')
        Return SetError(1, 0, 0)
    EndIf
    ProcessWaitClose($Compile)
    Do
        Sleep(10)
    Until Not FileExists($Split[3] & '.upx')
    If FileExists($Obfuscated) Then FileRecycle($Obfuscated)
    Return _Refresh($Split[2])
EndFunc   ;==>_CompileAu3Script

Func _GetFiles($Type = 'All Files (*.*)', $InitDir = '')
    Local $String, $ConversionList, $Flag, $oFile
    If $Cmdline[0] = 0 Then
        $Message = 'Choose the File(s) to Open.'
        $SourceFile = FileOpenDialog($Message, $InitDir, $Type, _GetIEVersion())
        If @error Then Exit
        If StringInStr($SourceFile, '|') Then
            $ConversionList = StringSplit($SourceFile, '|', @CRLF)
            For $i = 2 To $ConversionList[0]
                $ConversionList[$i] = $ConversionList[1] & '\' & $ConversionList[$i]
            Next
            _ArrayDelete($ConversionList, 1)
            $ConversionList[0] = UBound($ConversionList) - 1
        Else
            Local $ConversionList[2] = [1, $SourceFile]
        EndIf
    ElseIf $Cmdline[0] > 1 Then
        $CmdLineRaw = StringReplace(StringReplace($CmdLineRaw, '" "', '","'), '"', '')
        $ConversionList = StringSplit($CmdLineRaw, ',')
    Else
        $ConversionList = $Cmdline
    EndIf
    ;If IsArray($ConversionList) Then _ArrayDisplayEx($ConversionList, 'Array of Files')
    Return $ConversionList
EndFunc   ;==>_GetFiles

Func _GetIEVersion()
    $iE_Version = FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')
    Switch Int(FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe'))
        Case 0 To 4
            Global $Flag = 4
        Case 5
            Global $Flag = 2 + 4
        Case Else
            Global $Flag = 1 + 2 + 4
    EndSwitch
    Return $Flag
EndFunc   ;==>_GetIEVersion

Func _PathSplitByRegExp($sPath)
    #cs
        Function Name:  _PathSplitByRegExp()
        $RetArray[0] = Full path ($sPath)
        $RetArray[1] = Drive letter
        $RetArray[2] = Path without FileName and extension
        $RetArray[3] = Full path without File Extension
        $RetArray[4] = Full path without drive letter
        $RetArray[5] = FileName and extension
        $RetArray[6] = Just Filename
        $RetArray[7] = Just Extension of a file
        On failure - If $sPath not include correct path (the path is not splitable),
        then $sPath returned.
        If $sPath not include needed delimiters, or it's emty,
        then @Error set to 1, and returned -1.
    #ce
    If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1)
    Local $RetArray[8], $pDelim = ""
    If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
    If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"
    If $pDelim = "" Then $pDelim = "/"
    If Not StringInStr($sPath, $pDelim) Then Return $sPath
    If $pDelim = "\" Then $pDelim &= "\"
    $RetArray[0] = $sPath
    $RetArray[1] = StringReplace($sPath, StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*|\\w*\\)', ''), "")
    $RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '')
    $RetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '')
    $RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*\\|\\w*\\)', '')
    $RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '')
    $RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]*$', '')
    $RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '')
    Return $RetArray
EndFunc   ;==>_PathSplitByRegExp

Func _Refresh($iDirectory)
    If $iDirectory = @DesktopDir Or $iDirectory = @DesktopCommonDir Then
        $hWnd = WinGetHandle('classname=Progman')
    Else
        $hWnd = WinGetHandle($iDirectory, '')
    EndIf
    ControlSend($hWnd, '', '', '{F5}')
    DllCall('user32.dll', 'long', 'SendMessage', 'hwnd', $hWnd, 'int', 0x111, 'int', 28931, 'int', 0)
    If WinExists('[REGEXPTITLE:xplorer²]', '') Then WinMenuSelectItem('[REGEXPTITLE:xplorer²]', '', '&View', '&Refresh')
EndFunc   ;==>_Refresh

Link to comment
Share on other sites

As an example I have made a script to automate AutoITwrapper with WinWaits and ControlClicks. I have made a registry entry to make this Script (I call AutoITGUIAuto.exe) as my default compiler. You could do the same only your script would email the script with the Gmail UDF and then call the compiler. Here is my Script as an example

#include <Array.au3>
#include <Misc.au3>
_Singleton(@ScriptName, 0)

Opt('TrayIconDebug', 1)
Opt('WinTitleMatchMode', 4)
Opt('WinWaitDelay', 10)

Local $List
If $Cmdline[0] = 0 Then
    $List = _GetFiles('AutoIT Scripts (*.au3)', @DesktopDir)
Else
    $List = $Cmdline
EndIf

For $i = 1 To $List[0]
    _CompileAu3Script($List[$i])
Next

Func _CompileAu3Script($pScript)
    Local $Title = '[TITLE:AutoIt3Wrapper GUI to Compile AutotIt3 Script (ver 1.10.1.14); CLASS:AutoIt v3 GUI]'
    Local $Button = '[CLASS:Button; INSTANCE:28]'
    Local $Split, $String, $Result = 0, $File
    If StringInStr(FileRead($pScript), '/bdir=') Then
        $String = FileRead($pScript)
        $String = StringRegExpReplace($String, '(?m)(?i)(.*)(/bdir=)(.*) , '$1$2' & StringReplace(@TempDir, '\', '\\') & '\\')
        Do
            FileOpen($pScript, 2)
        Until Not @error = -1
        $File = FileWrite($pScript, $String)
        Do
            $Result = FileClose($File)
        Until $Result = 1
    EndIf
    $Split = _PathSplitByRegExp($pScript)
    If $Split[7] <> 'au3' Then Return SetError(1, 0, 0)
    $Outfile = $Split[3] & '.exe'
    $Obfuscated = $Split[3] & '_Obfuscated.' & $Split[7]
    If Not FileExists($pScript) Then Return SetError(1, 0, 0)
    $bCompiler = @ProgramFilesDir & '\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper_Gui.exe'
    $aSplitString = StringSplit($pScript, "\")
    $Compile = Run($bCompiler & ' /in "' & $pScript & '" /out "' & $Outfile & '"')
    ProcessWait('AutoIt3Wrapper_Gui.exe')
    WinSetState($Title, '', @SW_HIDE)
    Do
        Sleep(10)
    Until WinExists($Title, 'Autoit3 version to use:')
    WinSetState($Title, '', @SW_HIDE)
    If Not ControlClick($Title, '', $Button) Then
        WinWait($Title, '', 2)
        ControlClick($Title, 'Autoit3 version to use:', '[CLASS:Button; INSTANCE:30]')
        Return SetError(1, 0, 0)
    EndIf
    ProcessWaitClose($Compile)
    Do
        Sleep(10)
    Until Not FileExists($Split[3] & '.upx')
    If FileExists($Obfuscated) Then FileRecycle($Obfuscated)
    Return _Refresh($Split[2])
EndFunc ;==>_CompileAu3Script

Func _GetFiles($Type = 'All Files (*.*)', $InitDir = '')
    Local $String, $ConversionList, $Flag, $oFile
    If $Cmdline[0] = 0 Then
        $Message = 'Choose the File(s) to Open.'
        $SourceFile = FileOpenDialog($Message, $InitDir, $Type, _GetIEVersion())
        If @error Then Exit
        If StringInStr($SourceFile, '|') Then
            $ConversionList = StringSplit($SourceFile, '|', @CRLF)
            For $i = 2 To $ConversionList[0]
                $ConversionList[$i] = $ConversionList[1] & '\' & $ConversionList[$i]
            Next
            _ArrayDelete($ConversionList, 1)
            $ConversionList[0] = UBound($ConversionList) - 1
        Else
            Local $ConversionList[2] = [1, $SourceFile]
        EndIf
    ElseIf $Cmdline[0] > 1 Then
        $CmdLineRaw = StringReplace(StringReplace($CmdLineRaw, '" "', '","'), '"', '')
        $ConversionList = StringSplit($CmdLineRaw, ',')
    Else
        $ConversionList = $Cmdline
    EndIf
    ;If IsArray($ConversionList) Then _ArrayDisplayEx($ConversionList, 'Array of Files')
    Return $ConversionList
EndFunc ;==>_GetFiles

Func _GetIEVersion()
    $iE_Version = FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')
    Switch Int(FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe'))
        Case 0 To 4
            Global $Flag = 4
        Case 5
            Global $Flag = 2 + 4
        Case Else
            Global $Flag = 1 + 2 + 4
    EndSwitch
    Return $Flag
EndFunc ;==>_GetIEVersion

Func _PathSplitByRegExp($sPath)
    #cs
        Function Name:  _PathSplitByRegExp()
        $RetArray[0] = Full path ($sPath)
        $RetArray[1] = Drive letter
        $RetArray[2] = Path without FileName and extension
        $RetArray[3] = Full path without File Extension
        $RetArray[4] = Full path without drive letter
        $RetArray[5] = FileName and extension
        $RetArray[6] = Just Filename
        $RetArray[7] = Just Extension of a file
        On failure - If $sPath not include correct path (the path is not splitable),
        then $sPath returned.
        If $sPath not include needed delimiters, or it's emty,
        then @Error set to 1, and returned -1.
    #ce
    If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1)
    Local $RetArray[8], $pDelim = ""
    If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+ ) Then $pDelim = "\"
    If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+ ) Then $pDelim = "//"
    If $pDelim = "" Then $pDelim = "/"
    If Not StringInStr($sPath, $pDelim) Then Return $sPath
    If $pDelim = "\" Then $pDelim &= "\"
    $RetArray[0] = $sPath
    $RetArray[1] = StringReplace($sPath, StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*|\\w*\\)', ''), "")
    $RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']* , '')
    $RetArray[3] = StringRegExpReplace($sPath, '\.[^.]* , '')
    $RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*\\|\\w*\\)', '')
    $RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '')
    $RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]* , '')
    $RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '')
    Return $RetArray
EndFunc ;==>_PathSplitByRegExp

Func _Refresh($iDirectory)
    If $iDirectory = @DesktopDir Or $iDirectory = @DesktopCommonDir Then
        $hWnd = WinGetHandle('classname=Progman')
    Else
        $hWnd = WinGetHandle($iDirectory, '')
    EndIf
    ControlSend($hWnd, '', '', '{F5}')
    DllCall('user32.dll', 'long', 'SendMessage', 'hwnd', $hWnd, 'int', 0x111, 'int', 28931, 'int', 0)
    If WinExists('[REGEXPTITLE:xplorer²]', '') Then WinMenuSelectItem('[REGEXPTITLE:xplorer²]', '', '&View', '&Refresh')
EndFunc ;==>_Refresh

Interesting. I will take a look at it. Thanks for the idea!

~GoogleDude

Link to comment
Share on other sites

OK GoggleDude, this is what I have..it ain't pretty, but it includes the GMail function so the only includes are the standard Array.au3 and Misc.au3. The only thing that you need to do is verify the location of your AutoIt3Wrapper_Gui.exe file(the $bCompiler variable) and fill in at least these variables: $S_FROMNAME $S_FROMADDRESS $S_TOADDRESS $S_USERNAME $S_PASSWORD. Barring a Window Title difference this should be complete, albeit unpolished

#NoTrayIcon
#include-once
Opt('ExpandEnvStrings', 1)
Opt('TrayAutoPause', 0)

#include <Array.au3>
#include <Misc.au3>
_Singleton(@ScriptName, 0)

Opt('TrayIconDebug', 1)
Opt('WinTitleMatchMode', 4)
Opt('WinWaitDelay', 10)

Global $bCompiler = @ProgramFilesDir & '\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper_Gui.exe'
Global $S_SMTPSERVER = "smtp.gmail.com"
Global $S_FROMNAME = "YourName"
Global $S_FROMADDRESS = "YourFromEmailAddress"
Global $S_TOADDRESS = "YourToEmailAddress"
Global $S_CCADDRESS = ""
Global $S_BCCADDRESS = ""
Global $S_USERNAME = "YourGMailUsername"
Global $S_PASSWORD = "YourGMailPassword"
Global $IPPORT = 465;25;465
Global $SSL = 1

Local $List
If $Cmdline[0] = 0 Then
    $List = _GetFiles('AutoIT Scripts (*.au3)', @DesktopDir)
Else
    $List = $Cmdline
EndIf

For $i = 1 To $List[0]
    _CompileAu3Script($List[$i])
Next

Func _CompileAu3Script($pScript)
    Local $Title = '[TITLE:AutoIt3Wrapper GUI to Compile AutotIt3 Script (ver 1.10.1.14); CLASS:AutoIt v3 GUI]'
    Local $Button = '[CLASS:Button; INSTANCE:28]'
    Local $Split, $String, $Result = 0, $File
    If StringInStr(FileRead($pScript), '/bdir=') Then
        $String = FileRead($pScript)
        $String = StringRegExpReplace($String, '(?m)(?i)(.*)(/bdir=)(.*)$', '$1$2' & StringReplace(@TempDir, '\', '\\') & '\\')
        Do
            FileOpen($pScript, 2)
        Until Not @error = -1
        $File = FileWrite($pScript, $String)
        Do
            $Result = FileClose($File)
        Until $Result = 1
    EndIf
    $Split = _PathSplitByRegExp($pScript)
    If $Split[7] <> 'au3' Then Return SetError(1, 0, 0)
    Local $S_ATTACHFILES = $pScript
    Local $S_SUBJECT = 'Compiling Script ' & $Split[5] & '  on  ' & @YEAR & '/' & @MON & '/' & @MDAY & '  at  ' & @HOUR & ':' & @MIN & ':' & @SEC
    $Outfile = $Split[3] & '.exe'
    Local $AS_BODY = $S_SUBJECT
    
    _Splash('Emailing ' & $Split[5] & '  to  ' & $S_TOADDRESS)
    ;Send Script via GMail
    _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)
    
    _Splash('Compiling ' & $S_ATTACHFILES)
    $Obfuscated = $Split[3] & '_Obfuscated.' & $Split[7]
    If Not FileExists($pScript) Then Return SetError(1, 0, 0)
    $aSplitString = StringSplit($pScript, "\")
    $Compile = Run($bCompiler & ' /in "' & $pScript & '" /out "' & $Outfile & '"')
    ProcessWait('AutoIt3Wrapper_Gui.exe')
    WinSetState($Title, '', @SW_HIDE)
    Do
        Sleep(10)
    Until WinExists($Title, 'Autoit3 version to use:')
    WinSetState($Title, '', @SW_HIDE)
    If Not ControlClick($Title, '', $Button) Then
        WinWait($Title, '', 2)
        ControlClick($Title, 'Autoit3 version to use:', '[CLASS:Button; INSTANCE:30]')
        Return SetError(1, 0, 0)
    EndIf
    ProcessWaitClose($Compile)
    Do
        Sleep(10)
    Until Not FileExists($Split[3] & '.upx')
    If FileExists($Obfuscated) Then FileRecycle($Obfuscated)
    Return _Refresh($Split[2])
EndFunc   ;==>_CompileAu3Script

Func _GetFiles($Type = 'All Files (*.*)', $InitDir = '')
    Local $String, $ConversionList, $Flag, $oFile
    If $Cmdline[0] = 0 Then
        $Message = 'Choose the File(s) to Open.'
        $SourceFile = FileOpenDialog($Message, $InitDir, $Type, _GetIEVersion())
        If @error Then Exit
        If StringInStr($SourceFile, '|') Then
            $ConversionList = StringSplit($SourceFile, '|', @CRLF)
            For $i = 2 To $ConversionList[0]
                $ConversionList[$i] = $ConversionList[1] & '\' & $ConversionList[$i]
            Next
            _ArrayDelete($ConversionList, 1)
            $ConversionList[0] = UBound($ConversionList) - 1
        Else
            Local $ConversionList[2] = [1, $SourceFile]
        EndIf
    ElseIf $Cmdline[0] > 1 Then
        $CmdLineRaw = StringReplace(StringReplace($CmdLineRaw, '" "', '","'), '"', '')
        $ConversionList = StringSplit($CmdLineRaw, ',')
    Else
        $ConversionList = $Cmdline
    EndIf
    ;If IsArray($ConversionList) Then _ArrayDisplayEx($ConversionList, 'Array of Files')
    Return $ConversionList
EndFunc   ;==>_GetFiles

Func _GetIEVersion()
    $iE_Version = FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')
    Switch Int(FileGetVersion(@ProgramFilesDir & '\Internet Explorer\iexplore.exe'))
        Case 0 To 4
            Global $Flag = 4
        Case 5
            Global $Flag = 2 + 4
        Case Else
            Global $Flag = 1 + 2 + 4
    EndSwitch
    Return $Flag
EndFunc   ;==>_GetIEVersion

Func _INETSMTPMAILCOM($S_SMTPSERVER, $S_FROMNAME, $S_FROMADDRESS, $S_TOADDRESS, $S_SUBJECT = "", $AS_BODY = "", $S_ATTACHFILES = "", $S_CCADDRESS = "", $S_BCCADDRESS = "", $S_USERNAME = "", $S_PASSWORD = "", $IPPORT = 25, $SSL = 0)
    Global $oMYRET
    $oBJEMAIL = ObjCreate("CDO.Message")
    $oBJEMAIL.From = '"' & $S_FROMNAME & '" <' & $S_FROMADDRESS & ">"
    $oBJEMAIL.To= $S_TOADDRESS
    Local $I_ERROR = 0
    Local $I_ERROR_DESCIPTION = ""
    If $S_CCADDRESS <> "" Then $oBJEMAIL.Cc = $S_CCADDRESS
    If $S_BCCADDRESS <> "" Then $oBJEMAIL.Bcc = $S_BCCADDRESS
    $oBJEMAIL.Subject = $S_SUBJECT
    If StringInStr($AS_BODY, "<") And StringInStr($AS_BODY, ">") Then
        $oBJEMAIL.HTMLBody = $AS_BODY
    Else
        $oBJEMAIL.Textbody = $AS_BODY & @CRLF
    EndIf
    If $S_ATTACHFILES <> "" Then
        Local $S_FILES2ATTACH = StringSplit($S_ATTACHFILES, ";")
        For $x = 1 To $S_FILES2ATTACH[0]
            $File = _PathSplitByRegExp($S_FILES2ATTACH[$x])
            $S_FILES2ATTACH[$x] = $File[0]
            If FileExists($S_FILES2ATTACH[$x]) Then
                $oBJEMAIL.AddAttachment($S_FILES2ATTACH[$x])
            Else
                $I_ERROR_DESCIPTION = $I_ERROR_DESCIPTION & @LF & "File not found to attach: " & $S_FILES2ATTACH[$x]
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $S_SMTPSERVER
    $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPORT
    If $S_USERNAME <> "" Then
        $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $S_USERNAME
        $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $S_PASSWORD
    EndIf
    If $SSL Then
        $oBJEMAIL.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    $oBJEMAIL.Configuration.Fields.Update
    $oBJEMAIL.Send
    If @error Then
        SetError(2)
        Return $oMYRET[1]
    EndIf
EndFunc   ;==>_INETSMTPMAILCOM

Func _PathSplitByRegExp($sPath)
    ;Function Name:    _PathSplitByRegExp()
    ;$RetArray[0] = Full path ($sPath)
    ;$RetArray[1] = Drive letter
    ;$RetArray[2] = Path without FileName and extension
    ;$RetArray[3] = Full path without File Extension
    ;$RetArray[4] = Full path without drive letter
    ;$RetArray[5] = FileName and extension
    ;$RetArray[6] = Just Filename
    ;$RetArray[7] = Just Extension of a file
    ;On failure - If $sPath not include correct path (the path is not splitable),
    ;then $sPath returned.
    ;If $sPath not include needed delimiters, or it's emty,
    ;then @Error set to 1, and returned -1.

    If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1)
    Local $RetArray[8], $pDelim = ""
    If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
    If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"
    If $pDelim = "" Then $pDelim = "/"
    If Not StringInStr($sPath, $pDelim) Then Return $sPath
    If $pDelim = "\" Then $pDelim &= "\"
    $RetArray[0] = $sPath
    $RetArray[1] = StringReplace($sPath, StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*|\\w*\\)', ''), "")
    $RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '')
    $RetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '')
    $RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*\\|\\w*\\)', '')
    $RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '')
    $RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]*$', '')
    $RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '')
    Return $RetArray
EndFunc   ;==>_PathSplitByRegExp


Func _Refresh($iDirectory)
    If $iDirectory = @DesktopDir Or $iDirectory = @DesktopCommonDir Then
        $hWnd = WinGetHandle('classname=Progman')
    Else
        $hWnd = WinGetHandle($iDirectory, '')
    EndIf
    ControlSend($hWnd, '', '', '{F5}')
    DllCall('user32.dll', 'long', 'SendMessage', 'hwnd', $hWnd, 'int', 0x111, 'int', 28931, 'int', 0)
    If WinExists('[REGEXPTITLE:xplorer²]', '') Then WinMenuSelectItem('[REGEXPTITLE:xplorer²]', '', '&View', '&Refresh')
EndFunc   ;==>_Refresh

Func _Splash($Text) ;Shows a small borderless splash message.
    SplashTextOn('', $Text, @DesktopWidth, 25, -1, 5, 33, '', 14)
EndFunc   ;==>_Splash
EDIT: Somehow my copy/paste did not include entire script..this is complete

Edited by Varian
Link to comment
Share on other sites

OK After a bunch of trial and error with various different options I found one that works pretty well. However it does use an external command line exe to send the email.

It requires a command line app SendEmail.exe more info on sendemail.exe can be found Here.

Simply put SendEmail.exe in the same directory as your uncompiled .AU3 script and compile your script using SciTE

Include the following line at the top of your uncompiled script

#AutoIt3Wrapper_Run_Before=sendemail.exe -f myfromgmailaddress@gmail.com -xu myfromgmailaddress@gmail.com -xp myfromgmailpassword -s smtp.gmail.com:587 -m AutoIt Source -u AutoIt Script Source for %scriptfile% -t mytoemailaddress@gmail.com -a .\%scriptfile%.au3

I also setup a Filter in gmail to stick all these emails in a folder/label so they dont clutter my inbox.

Hope this helps someone else out besides myself.

~GoogleDude

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