Jump to content

Need Help


farhan879
 Share

Recommended Posts

Basically, i'm trying to make my email sender send the email a few times. Like, you type in how many times you want to send in a inputbox and it'll send that email for that amount of times.

Example:

I type in the number 5 and it'll send the email five times, how do i exactly do that?

Here's my script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Email Sender 1.0", 459, 410, 190, 123)
$Label_to = GUICtrlCreateLabel("To:", 8, 32, 24, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GmailToAdress = GUICtrlCreateInput("", 56, 32, 177, 21)
$Label_Subject = GUICtrlCreateLabel("Subject:", 0, 56, 52, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GmailSubject = GUICtrlCreateInput("", 56, 56, 177, 21)
$Label_body = GUICtrlCreateLabel("Body", 16, 88, 28, 17)
$GmailBody = GUICtrlCreateEdit("", 16, 104, 273, 185)
GUICtrlSetData(-1, "")
$Group_account = GUICtrlCreateGroup("Account info", 312, 48, 145, 129)
$Label_Username = GUICtrlCreateLabel("Gmail Username", 320, 64, 81, 17)
$GmailUser = GUICtrlCreateInput("", 320, 80, 121, 21)
$Label_Pasword = GUICtrlCreateLabel("Gmail Password", 320, 104, 79, 17)
$GmailPass = GUICtrlCreateInput("", 320, 120, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GmailSend = GUICtrlCreateButton("Send", 336, 200, 75, 25)
$Cancel = GUICtrlCreateButton("Cancel", 336, 240, 75, 25)
$Label1 = GUICtrlCreateLabel("How many times?", 64, 304, 87, 17)
$Input1 = GUICtrlCreateInput("", 64, 328, 169, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit        
            
            Case $GmailSend
            GUICtrlSetState($GmailSend, $GUI_DISABLE)
            $SmtpServer = "smtp.gmail.com"
            $FromName = "Mail"
            $FromAddress = "STARTTLS"
            $ToAddress = GUICtrlRead($GmailToAdress)
            $Subject = GUICtrlRead($GmailSubject)
            $Body = GUICtrlRead($GmailBody)
            $AttachFiles = ""
            $CcAddress = ""
            $BccAddress = ""
            $Importance = "Normal"
            $Username = GUICtrlRead($GmailUser)
            $Password = GUICtrlRead($GmailPass)
            $IPPort = 25 ; port used for sending the mail
            $ssl = 0
            $IPPort = 465
            $ssl = 1
            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)
                GUICtrlSetState($GmailSend, $GUI_ENABLE)                
            Else
                MsgBox(64, "Success", "Your email is successfully sent")
                GUICtrlSetState($GmailSend, $GUI_ENABLE)

            EndIf
    EndSwitch
WEnd
;
; 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 ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "H"
        Case ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "N"
        Case ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "L"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail = ""
EndFunc   ;==>_INetSmtpMailCom

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

Please help me with this, i need to now how. I have completely no idea on how to do it.

Thanks.

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser
Link to comment
Share on other sites

Something like this?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Email Sender 1.0", 459, 410, 190, 123)
$Label_to = GUICtrlCreateLabel("To:", 8, 32, 24, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GmailToAdress = GUICtrlCreateInput("", 56, 32, 177, 21)
$Label_Subject = GUICtrlCreateLabel("Subject:", 0, 56, 52, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$GmailSubject = GUICtrlCreateInput("", 56, 56, 177, 21)
$Label_body = GUICtrlCreateLabel("Body", 16, 88, 28, 17)
$GmailBody = GUICtrlCreateEdit("", 16, 104, 273, 185)
GUICtrlSetData(-1, "")
$Group_account = GUICtrlCreateGroup("Account info", 312, 48, 145, 129)
$Label_Username = GUICtrlCreateLabel("Gmail Username", 320, 64, 81, 17)
$GmailUser = GUICtrlCreateInput("", 320, 80, 121, 21)
$Label_Pasword = GUICtrlCreateLabel("Gmail Password", 320, 104, 79, 17)
$GmailPass = GUICtrlCreateInput("", 320, 120, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GmailSend = GUICtrlCreateButton("Send", 336, 200, 75, 25)
$Cancel = GUICtrlCreateButton("Cancel", 336, 240, 75, 25)
$Label1 = GUICtrlCreateLabel("How many times?", 64, 304, 87, 17)
$Input1 = GUICtrlCreateInput("", 64, 328, 169, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit        
            
            Case $GmailSend
            GUICtrlSetState($GmailSend, $GUI_DISABLE)
            $SmtpServer = "smtp.gmail.com"
            $FromName = "Mail"
            $FromAddress = "STARTTLS"
            $ToAddress = GUICtrlRead($GmailToAdress)
            $Subject = GUICtrlRead($GmailSubject)
            $Body = GUICtrlRead($GmailBody)
            $AttachFiles = ""
            $CcAddress = ""
            $BccAddress = ""
            $Importance = "Normal"
            $Username = GUICtrlRead($GmailUser)
            $Password = GUICtrlRead($GmailPass)
            $IPPort = 25 ; port used for sending the mail
            $ssl = 0
            $IPPort = 465
            $ssl = 1
            Global $oMyRet[2]
            Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
            $_Read = GUICtrlRead($Input1)       ; Added
            $_Num = 0                           ; Added
            Do                                  ; Added
                $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
                $_Num += 1                      ; Added
            Until $_Num = $_Read                ; Added
            If @error Then
                MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
                GUICtrlSetState($GmailSend, $GUI_ENABLE)                
            Else
                MsgBox(64, "Success", "Your email is successfully sent")
                GUICtrlSetState($GmailSend, $GUI_ENABLE)

            EndIf
    EndSwitch
WEnd
;
; 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 ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "H"
        Case ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "N"
        Case ""
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "L"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail = ""
EndFunc   ;==>_INetSmtpMailCom

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

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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