Jump to content

GUI for cmail command line utility


MattHiggs
 Share

Recommended Posts

Hey autoit scripters.  I just finished up a script that provides a GUI interface for cmail, a command line utility which allows email to be sent via command line, is easy to use, and is compatible with almost any mailbox setup.  I wrote the GUI to provide a way to create "template" messages which can be saved for future and will allow the user to send repetitive emails to many people very quickly rather than having to type out the same email over and over again.  Includes drag and drop attachment support.  Note that the command which actually runs the cmail utility may require you to modify it in order to make it work for your particular mail setup (eg configuring a proxy server, disable use of TLS, include more advanced features, etc.), as I utilized the utilities basic parameters that were compatible with my GMail account when writing this script.  BTW, for those of you looking for a way to send email from your gmail account via command line without the need to lower your security settings, cmail is the tool to use.  just create a "custom app password" for the tool to utilize, and it works like a charm.  And a big thank you to "big_daddy" for his Spell checker example that was incorporated into this script to check messages for spelling errors prior to sending the message, found here.  You will also need Zip.au3 udf in autoit "includes" folder.  Now, without further ado:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <ListBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:        William Higgs

 Script Function:
    Provides a graphical user interface for the command line utility "Cmail", which lets one send emails via command line.  I wrote this
    specificially to reduced the ammount of time needed to send messages to potential employers.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <Constants.au3>
#include <Word.au3>
#include <Array.au3>
OnAutoItExitRegister ( "_Exit" )
Global $trans = False
;_WordErrorHandlerRegister()
If Not FileExists ( @MyDocumentsDir & "\settings.ini" ) Then
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Name","What is the name wou want the recipients of your messages to see in regards to the sender? (Should be your name)",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Name", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Email address","What is your email address or the email address of the account sending the mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("SMTP server","What is the address of the SMTP server for your outgoing mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Port","What is the port used by smtp server?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Port", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Username","What is the username used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "User name", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Password","What is the password used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Password", $sInputBoxAnswer )
EndIf
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL,"Proxy server?","Does your network utilize a proxy server?")
If $iMsgBoxAnswer = $IDYES  Then
    $sInputBoxAnswer = InputBox("Proxy server","What is the proxy server address?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", $sInputBoxAnswer )
EndIf
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", "False" )
EndIf
EndIf

Global $oWordApp = _Word_Create(False)
Global $oDoc = _Word_DocAdd ( $oWordApp )
Global $oRange = $oDoc.Range
Global $oSpellCollection, $oAlternateWords
HotKeySet ( "^d", "stylish" )
Global $attach = ""
Global $array
$Form2 = GUICreate("Form2", 406, 514, 320, 200, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$handle = WinGetHandle ( $Form2 )
$MenuItem1 = GUICtrlCreateMenu("configure")
$MenuItem2 = GUICtrlCreateMenuItem("Attachments", $MenuItem1)
$Label1 = GUICtrlCreateLabel("Email Address", 128, 0, 130, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 70, 32, 273, 21)
$Label2 = GUICtrlCreateLabel("Attachments (Can drag and drop below)", 27, 64, 351, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 32, 104, 337, 21)
GUICtrlSetState ( -1, $GUI_DROPACCEPTED )
$Button9 = GUICtrlCreateButton("Add/Browse", 158, 136, 89, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Label4 = GUICtrlCreateLabel("Subject", 160, 184, 157, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("", 32, 216, 337, 21)
$Label3 = GUICtrlCreateLabel("Message", 160, 240, 172, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 32, 272, 345, 153, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$Button1 = GUICtrlCreateButton("Send", 30, 440, 113, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Save As Template", 160, 440, 105, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button6 = GUICtrlCreateButton ( "Use Template", 282, 440, 113, 33, $BS_NOTIFY )
GUICtrlSetCursor (-1, 0)
$Form1 = GUICreate("Spell check", 345, 251, 302, 218)
Global $handle2 = WinGetHandle ( $Form1 )
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
$Button3 = GUICtrlCreateButton("Send", 32, 201, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button4 = GUICtrlCreateButton("&Cancel", 240, 201, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button5 = GUICtrlCreateButton("Correct spelling", 128, 201, 83, 25, $BS_NOTIFY)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 0)
$Form3 = GUICreate("Form3", 286, 283, 192, 124)
$Label5 = GUICtrlCreateLabel("Attachments", 86, 8, 113, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$List1 = GUICtrlCreateList("", 16, 40, 249, 188, BitOR($GUI_SS_DEFAULT_LIST,$LBS_HASSTRINGS))
$Button7 = GUICtrlCreateButton("Delete", 40, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button8 = GUICtrlCreateButton("Back", 160, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form4 = GUICreate("Form4", 242, 95, 216, 123)
$Combo1 = GUICtrlCreateCombo("", 40, 56, 169, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label6 = GUICtrlCreateLabel("Templates", 72, 8, 96, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_DISABLE, $Form4)
GUISetState( @SW_DISABLE, $Form3 )
GUISetState( @SW_DISABLE, $Form1 )
GUISetState( @SW_SHOW, $Form2 )
$aRect = _GUICtrlEdit_GetRECT($Edit1)
$aRect[0] += 10
$aRect[1] += 10
$aRect[2] -= 10
$aRect[3] -= 10
_GUICtrlEdit_SetRECT($Edit1, $aRect)

While 1
    Global $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $Form2
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
                Case $GUI_EVENT_DROPPED
                    Sleep ( 200 )
                    $mult = StringSplit ( GUICtrlRead ( $Input2 ), "|" )
                    If @error Then
                        WinActivate ( $Form2 )
                        WinWaitActive ( $Form2 )
                        GUICtrlSetState ( $Input2, $GUI_FOCUS )
                        Send ( "{ENTER}", 0 )
                    Else
                        For $v = 1 To $mult[0] Step 1
                            $attach = $attach & $mult[$v] & ";"
                        Next
                        GUICtrlSetData ( $Input2, "" )
                            $sToolTipAnswer = ToolTip("The attachments were added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    EndIf

                Case $MenuItem2
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form3 )
                    GUISetState ( @SW_SHOW, $Form3 )
                    If $attach <> "" Then
                        $array = StringSplit ( StringTrimRight ( $attach, 1 ), ";" )
                        If @error Then
                            SetError ( 0 )
                            _GUICtrlListBox_AddString ( $List1, _GetFilename ( StringTrimRight ( $attach, 1 ) ) & "." & _GetFilenameExt ( StringTrimRight ( $attach, 1 ) ) )
                        Else
                            For $l = 1 To $array[0] Step 1
                                _GUICtrlListBox_AddString ( $List1, _GetFilename ( $array[$l] ) & "." & _GetFilenameExt ( $array[$l] ) )
                            Next
                        EndIf
                    Else
                        _GUICtrlListBox_AddString ( $List1, "You currently do not have any attachments." )
                    EndIf
                Case $Input2
                    $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                    GUICtrlSetData ( $Input2, "" )
                    $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                    Sleep ( 3000 )
                    ToolTip ("")

                Case $Button9
                    If GUICtrlRead ( $Input2 ) <> "" Then
                        $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                        GUICtrlSetData ( $Input2, "" )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    Else
                        $file = FileOpenDialog ( "Choose the file you want to attach.", "", "All (*.*)", 7, "", $Form2 )
                        $files = StringSplit ( $file, "|" )
                        If @error Then
                            SetError ( 0 )
                            $attach = $attach & $file & ";"
                            GUICtrlSetData ( $Input2, $file )
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                            GUICtrlSetData ( $Input2, "" )
                        Else
                            For $p = 2 To $files[0] Step 1
                                $attach = $attach & $files[1] & "\" & $files[$p] & ";"
                            Next
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                        EndIf
                    EndIf
                Case $Button1
                    _GUICtrlEdit_SetSel ( $Edit1, 0, -1 )
                    _SpellCheck ()
                Case $Button2;save as template
                    If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
                    $sInputBoxAnswer = InputBox("Template Name","What do you want to name this template?",""," ")
                    If @Error = 1 Then

                    Else
                        $name = $sInputBoxAnswer
                        $num = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                        $num += 1
                        $bodcap = _GUICtrlEdit_GetText ( $Edit1 )
                        $subcap = GUICtrlRead ( $Input3 )
                        $attcap = $attach
                        Local $holdarr[5][2] = [[3, ""], ["Name", $name], ["Body", $bodcap], ["Subject", $subcap], ["Attachments", $attcap]]
                        IniWriteSection ( @MyDocumentsDir & "\settings.ini", "Template " & $num, $holdarr )
                        IniWrite ( @MyDocumentsDir & "\settings.ini", "Number", "Template", $num )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 2000 )
                        ToolTip ( "" )
                    EndIf

                Case $Button6
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form4 )
                    GUISetState ( @SW_SHOW, $Form4 )
                    $numag = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag = 0 Then
                        MsgBox($MB_OK + $MB_ICONHAND,"No templates","You have not configured any templates.")
                    Else
                        For $h = 1 To $numag Step 1
                            GUICtrlSetData ( $Combo1, IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ) )
                        Next
                    EndIf

            EndSwitch
        Case $Form1
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $ListBox1
                    _SpellingSuggestions()
                Case $ListBox2
                    GUICtrlSetState($Button5, $GUI_ENABLE)
                Case $Button3
                    SendMessage ()
                Case $Button4
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Button5
                    _ReplaceWord()
            EndSwitch
        Case $Form3
            ToolTip ("")
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE, $Button8
                    ToolTip ("")
                    GUISetState ( @SW_HIDE, $Form3 )
                    GUISetState ( @SW_DISABLE, $Form3 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                    If UBound ( $array ) = 1 Then
                            $attach = ""
                        Else
                            $attach = ""
                            For $ff = 1 To UBound ( $array ) - 1 Step 1
                                $attach = $attach & $array[$ff] & ";"
                            Next
                        EndIf
                        _GUICtrlListBox_ResetContent ( $List1 )
                Case $List1
                    ToolTip ("")
                Case $Button7
                    If _GUICtrlListBox_GetSelCount = -1 Then
                        $sToolTipAnswer = ToolTip("Select something to delete first numbnuts.",Default,Default,"Idiot")
                    Else
                        ToolTip ("")
                        $seltext = _GUICtrlListBox_GetText ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                        For $ff = 1 To $array[0] Step 1
                            If StringInStr ( $array[$ff], $seltext ) > 0 Then
                                _ArrayDelete ( $array, $ff )
                                _GUICtrlListBox_DeleteString ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                                ExitLoop
                            EndIf
                        Next
                    EndIf
            EndSwitch
        Case $Form4
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form4 )
                    GUISetState ( @SW_DISABLE, $Form4 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Combo1
                    $sec = ""
                    $numag2 = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag2 = 0 Then

                    Else
                        $use = GUICtrlRead ( $Combo1 )
                        For $h = 1 To $numag2 Step 1
                            If StringCompare ( IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ), $use ) = 0 Then
                                $sec = "Template " & $h
                                ExitLoop
                            Else
                                ContinueLoop
                            EndIf
                        Next
                        GUISetState ( @SW_HIDE, $Form4 )
                        GUISetState ( @SW_DISABLE, $Form4 )
                        GUISwitch ( $Form2 )
                        GUISetState ( @SW_ENABLE, $Form2 )
                        GUISetState ( @SW_SHOW, $Form2 )
                        $attach = IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Attachments", "NA" )
                        GUICtrlSetData ( $Input3, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Subject", "NA" ) )
                        _GUICtrlEdit_SetText ( $Edit1, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Body", "NA" ) )
                    EndIf
            EndSwitch
    EndSwitch
WEnd
Func stylish ()
    $thestyle = GUIGetStyle ( $handle )
    If $trans = False Then
        GUISetStyle ( -1, $thestyle[1] + 32, $handle )
        WinSetTrans ( $handle, "", 170 )
        $trans = True
    Else
        GUISetStyle ( -1, $thestyle[1] - 32, $handle )
        WinSetTrans ( $handle, "", 255 )
        $trans = False
    EndIf
EndFunc
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc
Func _SpellCheck()
    Local $sText, $tText, $sWord

    $sText = _GUICtrlEdit_GetText ( $Edit1 )
    $oRange = $oWordApp.ActiveDocument.Range
    $oRange.Delete
    $oRange.InsertAfter($sText)
    _SetLanguage()

    $oSpellCollection = $oRange.SpellingErrors
    If $oSpellCollection.Count > 0 Then
        If BitAND ( WinGetState ( $handle ), 2 ) Then
            If $trans = True Then
                stylish ()
            EndIf
            GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
        EndIf

            ;
        _GUICtrlListBox_ResetContent($ListBox1)
        _GUICtrlListBox_ResetContent($ListBox2)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection.Count
                $sWord = $oSpellCollection.Item($i).Text
                _GUICtrlListBox_AddString($ListBox1, $sWord)
            Next
        GUICtrlSetData($Edit1, $oRange.Text)
    Else
        SendMessage ()
    EndIf
EndFunc   ;==>_SpellCheck

Func _SpellingSuggestions()
    Local $iWord, $sWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text

    $oAlternateWords = $oWordApp.GetSpellingSuggestions($sWord)
    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _HighlightWord()
    Local $sText, $iWord, $sWord, $iEnd, $iStart
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text
    $sText = $oRange.Text

    $iStart = ($oSpellCollection.Item($iWord).Start)
    $iEnd = ($oSpellCollection.Item($iWord).End)
    _GUICtrlEdit_SetSel($Edit1, $iStart, $iEnd)
EndFunc   ;==>_HighlightWord

Func _ReplaceWord()
    Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $iNewWord = _GUICtrlListBox_GetCurSel($ListBox2) + 1
    If $iWord == $LB_ERR Or $iNewWord == $LB_ERR Then
        MsgBox(48, "Error", "You must first select a word to replace, then a replacement word.")
        Return
    EndIf
    $oSpellCollection.Item($iWord).Text = $oAlternateWords.Item($iNewWord).Name

    GUICtrlSetData($Edit1, $oRange.Text)

    _SpellCheck()

    GUICtrlSetState($Button5, $GUI_DISABLE)
EndFunc   ;==>_ReplaceWord

Func _SetLanguage()
    $sLang = "English"
        $oWordApp.CheckLanguage = False
        $WdLangID = Number(1033)

        If $WdLangID Then
            With $oRange
                .LanguageID = $WdLangID
                .NoProofing = False
            EndWith
        EndIf
EndFunc   ;==>_SetLanguage

Func SendMessage ()
    If BitAND ( WinGetState ( $handle2 ), 2 ) Then
        GUISetState ( @SW_HIDE, $Form1 )
        GUISetState ( @SW_DISABLE, $Form1 )
        GUISwitch ( $Form2 )
        GUISetState ( @SW_ENABLE, $Form2 )
        GUISetState ( @SW_SHOW, $Form2 )
    EndIf
    $change = StringStripWS ( GUICtrlRead ( $Input1 ), 3 )
    GUICtrlSetData ( $Input1, $change )
    $body = GUICtrlRead ( $Edit1 )
    _GUICtrlEdit_SetText ( $Edit1, "" )
    ;$attach = StringStripCR ( $attach )
    $subject = GUICtrlRead ( $Input3 )
    If $attach <> "" Then
        $split = StringSplit ( StringTrimRight ( $attach, 1 ), ';' )
        If @error Then
            SetError ( 0 )
            $finattach = '-a:"' & $attach & '" '
        Else
            $finattach = Null
            For $i = 1 To $split[0] Step 1
                $finattach = $finattach & '-a:"' & $split[$i] & '" '
            Next
        EndIf
    EndIf
    $body = StringReplace ( $body, @CRLF, "\n" )
    #cs
    $split = StringSplit ( $body, "", $STR_NOCOUNT )
    For $i = 0 To UBound ( $split ) - 1 Step 1
        If $split[$i] = Chr ( 10 ) Then
            $split[$i] = "\n"
        ElseIf $split[$i] = Chr ( 13 ) Then
            $split[$i] = Null
        Else
            ContinueLoop
        EndIf
    Next
    $body = _ArrayToString ( $split, "" )
    ConsoleWrite ( $body )
    #ce
    If StringRegExp ( GUICtrlRead ( $Input1 ), "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" ) = 1 Then
        If $attach = "" Then
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" -host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
        Else
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
            ClipPut ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d' )
    ProcessWaitClose ( $proc )
    $text = StdoutRead ( $proc )
    ClipPut ( $text )
    MsgBox($MB_OK + $MB_SYSTEMMODAL,"Sent!","Message Sent!!")
        EndIf
    Else
MsgBox(16,"Not a valid email","Enter a correct email address please")
    EndIf
EndFunc

Func _GetFilename($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.FileName
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilename

Func _GetFilenameExt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Extension
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameExt

Func _GetFilenameInt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Name
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameInt

Func _GetFilenameDrive($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringUpper($oObjectFile.Drive)
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameDrive

Func _GetFilenamePath($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Path
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenamePath

Func _Exit()
    _Word_Quit ( $oWordApp )
    Exit
EndFunc   ;==>_Exit

Comments are welcome and appreciated. 

 

 

 

Edited by MattHiggs
Link to comment
Share on other sites

3 minutes ago, argumentum said:

I'd rather have it at @AppDataDir&"\CMailGui\settings.ini"

Thanks for sharing :) 

 
 

All a matter of preference.  I actually have mine in my OneDrive folder so I can use the tool on both work and personal computer and update the script as I like without the need to worry about copying and replacing the ini between computers...  Too much hassle.  Oh, and you are most welcome.

Edited by MattHiggs
Link to comment
Share on other sites

  • 1 month later...

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