Jump to content

Recommended Posts

Posted

making a gui that allows me to send mail based on Jos's script from here

Case $Send
            _INetSmtpMailCom(GUICtrlRead($SmtpServer), GUICtrlRead($FromName), GUICtrlRead($FromAddress), GUICtrlRead($ToAddress), GUICtrlRead($Subject), GUICtrlRead($Body), GUICtrlRead($AttachFiles), GUICtrlRead($CcAddress), GUICtrlRead($BccAddress), GUICtrlRead($Username), GUICtrlRead($Password))

        case $Hotmail
            GUICtrlSetData ( $SmtpServer, "smtp.live.com")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "@hotmail.com")
            GUICtrlSetData ( $Username, "@hotmail.com")
            GUICtrlSetData ( $Password, "***********")
            GUICtrlSetData ( $ssl, 1)
        case $Gmail
            GUICtrlSetData ( $SmtpServer, "smtp.gmail.com")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "@gmail.com")
            GUICtrlSetData ( $Username, "@gmail.com")
            GUICtrlSetData ( $Password, "*********")

        Case $Exit
            Exit
    EndSwitch
WEnd

If @error then
    msgbox(0,"Error sending message","Error code: " & @error & "  Description: " & $Send)
EndIf

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)

so, it works fine, but i want to be able to change ssl from 0 to 1.

ive tried setting , GUICtrlRead($ssl)

and then adding GUICtrlSetData ( $ssl, "1") or ( $ssl, "0")

but it doesnt seem to work...

any help?

Posted

You need to add the $IPPort argument and the SSL argument. Since I cannot see the code for your GUI, just try this

_INetSmtpMailCom(GUICtrlRead($SmtpServer), GUICtrlRead($FromName), GUICtrlRead($FromAddress), GUICtrlRead($ToAddress), GUICtrlRead($Subject), GUICtrlRead($Body), GUICtrlRead($AttachFiles), GUICtrlRead($CcAddress), GUICtrlRead($BccAddress), GUICtrlRead($Username), GUICtrlRead($Password), 25, GUICtrlRead($ssl))

Posted (edited)

You need to add the $IPPort argument and the SSL argument. Since I cannot see the code for your GUI, just try this

_INetSmtpMailCom(GUICtrlRead($SmtpServer), GUICtrlRead($FromName), GUICtrlRead($FromAddress), GUICtrlRead($ToAddress), GUICtrlRead($Subject), GUICtrlRead($Body), GUICtrlRead($AttachFiles), GUICtrlRead($CcAddress), GUICtrlRead($BccAddress), GUICtrlRead($Username), GUICtrlRead($Password), 25, GUICtrlRead($ssl))

sorry, didnt think to post the entire code.

#include <GUIConstants.au3>
#Include<file.au3>
#include<EditConstants.au3>

Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$MyEmail = GUICreate("Email Sender 1.0", 461, 560, 192, 125)
GUICtrlCreateLabel("From", 16, 16, 31, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Address", 16, 40, 49, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("To", 16, 64, 19, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Subject", 16, 136, 47, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Body", 16, 200, 32, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Attachments", 16, 160, 74, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("CC", 16, 88, 20, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("BCC", 16, 112, 28, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$FromName = GUICtrlCreateInput("", 96, 16, 185, 21)
$FromAddress = GUICtrlCreateInput("", 96, 40, 185, 21)
$ToAddress = GUICtrlCreateInput("", 96, 64, 185, 21)
$CcAddress = GUICtrlCreateInput("", 96, 88, 185, 21)
$BccAddress = GUICtrlCreateInput("", 96, 112, 185, 21)
$Subject = GUICtrlCreateInput("", 96, 136, 185, 21)
$Body = GUICtrlCreateEdit("", 64, 192, 329, 193)
GUICtrlSetData(-1, "")
$AttachFiles = GUICtrlCreateInput("", 96, 160, 185, 21)
$Send = GUICtrlCreateButton("Send", 64, 496, 75, 25)
$Reset = GUICtrlCreateButton("Reset", 144, 496, 75, 25)
$Exit = GUICtrlCreateButton("Exit", 224, 496, 75, 25)
GUICtrlCreateGroup("", 64, 384, 273, 105)
GUICtrlCreateLabel("SMTP Server", 75, 408, 68, 17)
GUICtrlCreateLabel("User ID", 75, 432, 40, 17)
GUICtrlCreateLabel("Password", 75, 456, 50, 17)
$SmtpServer = GUICtrlCreateInput("", 146, 405, 180, 21)
$Username = GUICtrlCreateInput("", 146, 429, 180, 21)
$Password = GUICtrlCreateInput("", 146, 453, 180, 21, $ES_PASSWORD)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$*** = GUICtrlCreateButton("****", 344, 392, 107, 41)
$Hotmail = GUICtrlCreateButton("Hotmail", 344, 440, 107, 41)
$Gmail = GUICtrlCreateButton("Gmail", 344, 488, 107, 41)
$MailCheck = GUICtrlCreateButton("Check Mail", 304, 16, 131, 33)
$status = GUICtrlCreateEdit("", 307, 63, 210, 126)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)

TCPStartup()

$ip = TCPNameToIP('')
$user = ''
$pass = ''

$socket = TCPConnect($ip, 110)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Send
            _INetSmtpMailCom(GUICtrlRead($SmtpServer), GUICtrlRead($FromName), GUICtrlRead($FromAddress), GUICtrlRead($ToAddress), GUICtrlRead($Subject), GUICtrlRead($Body), GUICtrlRead($AttachFiles), GUICtrlRead($CcAddress), GUICtrlRead($BccAddress), GUICtrlRead($Username), GUICtrlRead($Password))
        Case $Reset
            GUICtrlSetData ( $SmtpServer, "")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "")
            GUICtrlSetData ( $ToAddress, "")
            GUICtrlSetData ( $Subject, "")
            GUICtrlSetData ( $Body, "")
            GUICtrlSetData ( $AttachFiles, "")
            GUICtrlSetData ( $CcAddress, "")
            GUICtrlSetData ( $BccAddress, "")
            GUICtrlSetData ( $Username, "")
            GUICtrlSetData ( $Password, "")

        case $****
            GUICtrlSetData ( $SmtpServer, "")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "")
            GUICtrlSetData ( $Username, "")
            GUICtrlSetData ( $Password, "")

        case $Hotmail
            GUICtrlSetData ( $SmtpServer, "smtp.live.com")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "@hotmail.com")
            GUICtrlSetData ( $Username, "@hotmail.com")
            GUICtrlSetData ( $Password, "")

        case $Gmail
            GUICtrlSetData ( $SmtpServer, "smtp.gmail.com")
            GUICtrlSetData ( $FromName, "")
            GUICtrlSetData ( $FromAddress, "@gmail.com")
            GUICtrlSetData ( $Username, "@gmail.com")
            GUICtrlSetData ( $Password, "")

        case $MailCheck

$socket = TCPConnect($ip, 110)
If $socket = -1 Then
    GUICtrlSetData($status, 'Error: Bad connection' & @CRLF)
Else
    $step = 'login'
    Do
        $recv = TCPRecv($socket, 512)
        If @error Then
            GUICtrlSetData($status, 'Notice: Disconnected!' & @CRLF, 1)
            $socket = -1
        ElseIf StringInStr($recv, '+OK') = 1 Then
            GUICtrlSetData($status, $recv & @CRLF, 1)
            Switch $step
                Case 'login'
                    GUICtrlSetData($status, 'Login: Username...' & @CRLF, 1)
                    _TCPSend($socket, 'user ' & $user & @CRLF)
                    $step = 'pass'
                Case 'pass'
                    GUICtrlSetData($status, 'Login: Password...' & @CRLF, 1)
                    _TCPSend($socket, 'pass ' & $pass & @CRLF)
                    $step = 'stat'
                Case 'stat'
                    GUICtrlSetData($status, 'Logged In: Check for mail...' & @CRLF, 1)
                    _TCPSend($socket, 'stat' & @CRLF)
                    $step = 'check'
                Case 'check'
                    $match = StringRegExp($recv, '\+OK ([0-9]+)', 2)
                    If Not @error Then
                        GUICtrlSetData($status, 'You have ' & $match[1] & ' new email(s)' & @CRLF, 1)
                        If $match[1] > 0 Then
                            _TCPSend($socket, 'Disconnecting' & @CRLF)
                    TCPCloseSocket($socket)
                    $socket = -1
                        Else
                            GUICtrlSetData($status, 'Disconnecting', 1)
                            TCPCloseSocket($socket)
                            $socket = -1
                        EndIf
                    Else
                        GUICtrlSetData($status, 'Error: Improper format:' & $recv & @CRLF, 1)
                        GUICtrlSetData($status, 'Disconnecting', 1)
                        TCPCloseSocket($socket)
                        $socket = -1
                    EndIf
            EndSwitch
        ElseIf StringInStr($recv, '-ERR') = 1 Then
            GUICtrlSetData($status, 'Error: ' & $recv & @CRLF, 1)
            GUICtrlSetData($status, 'Disconnecting', 1)
            TCPCloseSocket($socket)
            $socket = -1
        EndIf
    Until $socket = -1
EndIf

        Case $Exit
            Exit
    EndSwitch
WEnd

If @error then
    msgbox(0,"Error sending message","Error code: " & @error & "  Description: " & $Send)
EndIf

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=1)
    $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])
            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
;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
; Sent the Message
    $objEmail.Send
    if @error then
        SetError(2)
        return $oMyRet[1]
    EndIf
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

; mail check
Func _TCPSend($socket, $data)
    TCPSend($socket, $data)
    GUICtrlSetData($status, '> ' & $data, 1)
EndFunc
Edited by royalmarine
Posted

The GUICtrlRead() and GUICtrlSetData() read and write data in user input boxes, so you would need to have a line starting with "$ssl = GUICtrlCreateInput(" where you have the other GUICtrlCreateInput() lines. That will allow you to change the variable, but I have no idea how you are going to use it. It sounds like Varian knows what he is talking about.

Posted

Did you plan on creating a checkbox or something to select SSL on or off? In your code, you do not have any references to an $SSL control, so from where were you planning on reading the value or state?

Posted

Did you plan on creating a checkbox or something to select SSL on or off? In your code, you do not have any references to an $SSL control, so from where were you planning on reading the value or state?

i dont want to be able to set the ssl myself.

i want to add it to the settings depending on which mail account i choose to send it with.

e.g

if i click hotmail, since hotmail needs ssl to be 1 in this program,

then

case $Hotmail

GUICtrlSetData ( $SmtpServer, "smtp.live.com")

GUICtrlSetData ( $FromName, "")

GUICtrlSetData ( $FromAddress, "@hotmail.com")

GUICtrlSetData ( $Username, "@hotmail.com")

GUICtrlSetData ( $Password, "****")

GuiCtrlSetDate ($ssl=1)

was thinking something along these lines.

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
×
×
  • Create New...