Sign in to follow this  
Followers 0
farhan879

Help needed

3 posts in this topic

#1 ·  Posted (edited)

Hello, i've been using autoit for almost 3 months now and quite like it. I have a problem in my script. I am try to make one SMTP mail (Hotmail). Here are some of the SMTP server i know:

mx1.hotmail.com

mx2.hotmail.com

mx3.hotmail.com

mx4.hotmail.com

But i do not not why i get an error when i try to send an email. Here is my script:

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.12.1
    Author:         myName
    
    Script Function:
    Template AutoIt script.
    
#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>
#include <File.au3>


$Form2 = GUICreate("Email Sender 1.0", 465, 328, 189, 122)
$Label_Username = GUICtrlCreateLabel("Hotmail User", 320, 64, 81, 17)
$HotmailUser = GUICtrlCreateInput("", 320, 80, 121, 21)
$Label_Pasword = GUICtrlCreateLabel("Hotmail Pass", 320, 104, 79, 17)
$HotmailPass = GUICtrlCreateInput("", 320, 120, 121, 21)
$Label_to = GUICtrlCreateLabel("To:", 8, 32, 24, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$HotmailToAdress = GUICtrlCreateInput("", 56, 32, 177, 21)
$Label_Subject = GUICtrlCreateLabel("Subject:", 0, 56, 52, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$HotmailSubject = GUICtrlCreateInput("", 56, 56, 177, 21)
$Label_body = GUICtrlCreateLabel("Body", 16, 88, 28, 17)
$HotmailBody = GUICtrlCreateEdit("", 16, 104, 273, 185)
$Group_account = GUICtrlCreateGroup("Account info", 312, 48, 145, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$HotmailSend = GUICtrlCreateButton("Send", 336, 200, 75, 25, 0)
$Cancel = GUICtrlCreateButton("Cancel", 336, 240, 75, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem_about = GUICtrlCreateMenuItem("About", $MenuItem1)
$MenuItem_exit = GUICtrlCreateMenuItem("Exit", $MenuItem1)

GUISetState(@SW_SHOW)




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit
        Case $MenuItem_about
            MsgBox(64, "Email Sender 1.0", "This Email Sender is made by Farhan as a efficient and convenient application to send emails." & @CRLF & @CRLF & "(c) Copyright 2008. All Rights Reseved.")

        Case $MenuItem_exit
            Exit
        Case $HotmailSend
            $SmtpServer = "mx1.hotmail.com "
            $FromName = "Mail"
            $FromAddress = "STARTTLS"
            $ToAddress = GUICtrlRead($HotmailToAdress)
            $Subject = GUICtrlRead($HotmailSubject)
            $Body = GUICtrlRead($HotmailBody)
            $AttachFiles = ""
            $CcAddress = ""
            $BccAddress = ""
            $Importance = "Normal"
            $Username = GUICtrlRead($HotmailUser)
            $Password = GUICtrlRead($HotmailPass)
            $IPPort = 25 
            $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)
            Else
                MsgBox(64, "Success", "Your email is successfully sent")
            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

Is it the problem with the port or the SMTP server?

Please help me :)

Edited by farhan879

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

Share this post


Link to post
Share on other sites



The first link you gave, i could not really understand. And the second link, that topic was opened by me.


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

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