Sign in to follow this  
Followers 0
mawaissharif

need Help With Email Sender

2 posts in this topic

1- I have made a script to record the all data of a person 

2- I want backup of these data By sending this data on a email

3- By sending data on email i can easily search the data of specific person 

 - Mail server search fast then My Computer  :ermm:

I want to send the record automatically (Not Manually Like Add person Name ,Address , etc And Then Send it.. )

For This Purpose I have choiced a ini file 

;First Function
Func isdatabasesendingtime()
    Local $IS = IniReadSectionNames($MailingAddress & "\EmailDatabase.INI")
    If @error Then
        Sleep(1000)
    Else
        Return 1
    EndIf
EndFunc

Function reads the section if any section will be available

then it returns 1 

then i have made a next function 

Func geahitisavailable()
    Global $EMAILDATABASEINI = $MailingAddress & "\EmailDatabase.INI"
    Local $THIS = IniReadSectionNames($MailingAddress & "\EmailDatabase.INI")
    For $i = 1 To $THIS[0]
        $rc = 'nOT'
        Global $BSSE = 'Send'
        ToolTip($BSSE,@DesktopHeight - 100,@DesktopWidth - 100,"Before Sending")
        Local $PassportNumber = $THIS[$i]
        Local $LOGISTHAT = FileRead($path&"\"&$PassportNumber&"\Log.bin")
        Local $BodyandLog = ;hereis the Body oF email that records i want to send on mail
        Local $WWWW = $path&"\" &$PassportNumber&"\"
        $AttachFiles = ;here is the files that i want to send
        $rc = _INetSmtpMailCom($SmtpServer, $PassportNumber, $FromAddress, $ToAddress, $PassportNumber, $BodyandLog, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
        IniWrite($MailingAddress& "\Status.ini",@YEAR&@MON&@MDAY,@HOUR&@MIN&@SEC&@MSEC,$rc &"   " & $PassportNumber) ;; this is used so i can find the record when email was sent
        If $rc = 'Sent' Then
                IniDelete($MailingAddress & "\EmailDatabase.INI",$PassportNumber)
                IniWrite($MailingAddress & "\Status.ini",@YEAR&@MON&@MDAY,@HOUR&@MIN&@SEC&@MSEC,$rc)
        EndIf
    Next
EndFunc

this function reads the Records of that person that was found previously 

and after sending it 

this function delete that section that was previously found by first function 

:::::::::::::::::::::::::::::::::::::::::

Problem is that some time it delete the section without sending email

Here is my full function :-)  :alien:

#NoTrayIcon
;
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
Global $MailingAddress = 'E:\Masdar Internatinoal Office Files\MailingTime'
DirCreate($MailingAddress)
$SmtpServer = "smtp.gmail.com"              ; address for the smtp-server to use - REQUIRED
$FromName = "Muhammmad Awais Sharif"                      ; name from who the email was sent
$FromAddress = "mail@example.com" ; address from where the mail should come
$ToAddress = "mail@example.com"   ; destination address of the email - REQUIRED
$Subject = "My Name Is awais"                   ; subject from the email - can be anything you want it to be
$Body = "this is body"                              ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = "mail@example.com"       ; address for cc - leave blank if not needed
$BccAddress = "mail@example.com"     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "mail@example.com"                    ; 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 = 1                                ; 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
Global Const $Path = "E:\Masdar Internatinoal Office Files"
;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("EmailClient.Error", "ErrorHandler")
While 1
    Sleep(100)
    Local $ismailavailable = Mailingtimeis()
    If $ismailavailable = 1 Then
        GOANDMAIL()
    EndIf
    Local $isdatabasemailingtime = isdatabasesendingtime()
    If $isdatabasemailingtime = 1 Then
        geahitisavailable()
    EndIf
    Sleep(5000)
WEnd
Func geahitisavailable()
    Global $EMAILDATABASEINI = $MailingAddress & "\EmailDatabase.INI"
    Local $THIS = IniReadSectionNames($MailingAddress & "\EmailDatabase.INI")
    For $i = 1 To $THIS[0]
        $rc = 'nOT'
        Global $BSSE = 'Send'
        ToolTip($BSSE,@DesktopHeight - 100,@DesktopWidth - 100,"Before Sending")
        Local $PassportNumber = $THIS[$i]
        Local $LOGISTHAT = FileRead($path&"\"&$PassportNumber&"\Log.bin")
        Local $BodyandLog = "Passport Number"&"        "&$PassportNumber&@CRLF&"Full Name"&"         "& ASDFGH("Full Name",$PassportNumber)&@CRLF&"Father Name"&@TAB&@TAB& ASDFGH("Father Name",$PassportNumber)&@CRLF&"Profession"&@TAB&@TAB& ASDFGH("Occupation",$PassportNumber)&@CRLF&"Number Of Passport"&@TAB&@TAB& ASDFGH("Numberofpassport",$PassportNumber)&@CRLF&"Refernce "&@TAB&@TAB& ASDFGH("Referencce",$PassportNumber)&@CRLF&"Medical Issued Day"&@TAB&@TAB& ASDFGH("Day",$PassportNumber)&@CRLF&"Medical Issued Month"&@TAB&@TAB& ASDFGH("Month",$PassportNumber)&@CRLF&"Medical Issued Year"&@TAB&@TAB& ASDFGH("Year",$PassportNumber)&@CRLF&"Visa Processing Step"&@TAB&@TAB& ASDFGH("Visa Processing Step",$PassportNumber)&@CRLF&"Passport Sent To"&@TAB&@TAB& ASDFGH("Passport Sent To",$PassportNumber)&@CRLF&"More Brief Info"&@TAB&@TAB& ASDFGH("MoreBriefiNFO",$PassportNumber)&@CRLF&"Name Of The Phon Reciver"&@TAB&@TAB& ASDFGH("NameOfthecontecter",$PassportNumber)&@CRLF&"Phon Number"&@TAB&@TAB& ASDFGH("Phon Number OF person",$PassportNumber)&@TAB& "Record Update Details"&@TAB&@TAB&@CRLF& @CRLF& $LOGISTHAT
        Local $WWWW = $path&"\" &$PassportNumber&"\"
        $AttachFiles = $WWWW & "Person Copy.Jpeg" & ";" & $WWWW & "Passport Copy.Jpeg" & ";" & $WWWW & "license B Side Copy.Jpeg" & ";" & $WWWW & "license A Side Copy.Jpeg" & ";" & $WWWW & "ID Card B Side Copy.Jpeg" & ";" & $WWWW & "ID Card A Side Copy.Jpeg"
        $rc = _INetSmtpMailCom($SmtpServer, $PassportNumber, $FromAddress, $ToAddress, $PassportNumber, $BodyandLog, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
        IniWrite($MailingAddress& "\Status.ini",@YEAR&@MON&@MDAY,@HOUR&@MIN&@SEC&@MSEC,$rc &"   " & $PassportNumber)
        If $rc = 'Sent' Then
                IniDelete($MailingAddress & "\EmailDatabase.INI",$PassportNumber)
                IniWrite($MailingAddress & "\Status.ini",@YEAR&@MON&@MDAY,@HOUR&@MIN&@SEC&@MSEC,$rc)
        EndIf
    Next
EndFunc
Func ASDFGH($KEY,$SEC)
    Local $rESULTA = IniRead($path &"\"& $SEC &"\Details.Qt",$SEC,$KEY,"")
    Return $rESULTA
EndFunc

Func GOANDMAIL()
    Local $THIS = IniReadSectionNames($MailingAddress & "\Email.INI")
    For $i = 1 To $THIS[0]
            Global $rESULTA = 0
            $FromNamea = IniRead($MailingAddress & "\Email.INI",$THIS[$i],"Name","Null")
            $Subjecta = IniRead($MailingAddress & "\Email.INI",$THIS[$i],"Title","Null")
            $Bodya = IniRead($MailingAddress & "\Email.INI",$THIS[$i],"Body","Null")
            $rc = _INetSmtpMailCom($SmtpServer, $FromNamea, $FromAddress, $ToAddress, $Subjecta, $Bodya, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
            If $rc = 'Sent' Then
                IniDelete($MailingAddress & "\Email.INI",$THIS[$i])
            EndIf
    Next
EndFunc

Func Mailingtimeis()
    Local $IS = IniReadSectionNames($MailingAddress & "\Email.INI")
    If @error Then
        Sleep(1000)
    Else
        Return 1
    EndIf
EndFunc
Func isdatabasesendingtime()
    Local $IS = IniReadSectionNames($MailingAddress & "\EmailDatabase.INI")
    If @error Then
        Sleep(1000)
    Else
        Return 1
    EndIf
EndFunc


; 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 : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                $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]
    Else
        Global $BSSE = 'Send'
        ToolTip($BSSE,@DesktopHeight - 100,@DesktopWidth - 100,"After")
        Return 'Sent'
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func ErrorHandler()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    MsgBox(0,"","### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

Thanks For Help in advance  :guitar:     :gathering:   :cheer:

Share this post


Link to post
Share on other sites



there was file attachment problem 

some attachment :wacko2:  files was not exists .........

Share this post


Link to post
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
Sign in to follow this  
Followers 0