因为环境中需要用到temail向多个邮件服务器发送邮件,所以利用Autoit做了个简单的UI界面,可以从文件读取邮件服务器和邮箱账号列表,并选择指定的邮件发送。
- #include <Process.au3>
- #include <GuiConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <ButtonConstants.au3>
- #include <StaticConstants.au3>
- #include <file.au3>
- Global $default_path = "c:\temail"
- _Main()
- Func _Main()
- Local $hGui, $hFile, $hFileSel
- Local $iMsg, $sCurFilename, $sTmpFile
- Dim $aServers
- Dim $aAccounts
- _FileReadToArray("server.txt",$aServers) ;read smtp server list from server.txt
- _FileReadToArray("account.txt",$aAccounts) ;read email account list from account.txt
- ;$aServers[0] is array's length
- ; Creating GUI and controls
- $hGui = GUICreate("Send Email use Temail", 500, 500, -1, $WS_EX_ACCEPTFILES)
- ; CHECKBOX
- $lable6 = GUICtrlCreateLabel("Send eml file", 15, 30, 80, 20)
- $eml = GuiCtrlCreateCheckbox("1", 5,30, 10, 10)
- ;GuiCtrlSetState(-1, $GUI_CHECKED)
- $Lable1 = GUICtrlCreateLabel("From:",5,50,50,50)
- $From = GuiCtrlCreateInput("test@test.com", 5, 70, 100, 25)
- $Lable2 = GUICtrlCreateLabel("Cycles:",130,50,50,50)
- $cycle = GuiCtrlCreateInput("1", 130, 70, 50, 25)
- $Lable3 = GUICtrlCreateLabel("Subject:",200,50,50,50)
- $subject = GuiCtrlCreateInput("test for smex", 200, 70, 200, 25)
- $hFile = GUICtrlCreateInput($default_path, 5, 110, 350, 16, -1, $WS_EX_STATICEDGE)
- ;GUICtrlSetState(-1, $GUI_DROPACCEPTED)
- ;GUICtrlSetTip(-1, "You can drop files from shell here...")
- $hFileSel = GUICtrlCreateButton("...", 370, 110, 26, 18)
- $serverlist = ""
- $accountlist = ""
- For $x = 1 to $aServers[0]
- ;get serverlist format s1|s2|s3
- $serverlist = $serverlist & "|" & $aServers[$x]
- Next
- For $y = 1 to $aAccounts[0]
- $accountlist = $accountlist & "|" & $aAccounts[$y]
- Next
- ; LIST1
- $Lable4 = GUICtrlCreateLabel("Server:",5,140,140,25)
- $server = GuiCtrlCreateList("", 5, 160, 150, 90)
- GuiCtrlSetData(-1, $serverlist, $aServers[2])
- ; LIST2
- $Lable5 = GUICtrlCreateLabel("To:",160,140,140,50)
- $to = GuiCtrlCreateList("", 160, 160, 150, 90)
- GuiCtrlSetData(-1, $accountlist, $aAccounts[2])
- $l7 = GUICtrlCreateLabel("Command:",5,300,50,50)
- $edit = GUICtrlCreateEdit("",5,320,500,100)
- ; BUTTON
- $sendbtn = GuiCtrlCreateButton("Send Email", 10, 260, 100, 30)
- $copybtn = GuiCtrlCreateButton("Copy Command", 150,260,100,30)
- GUISetState()
- While 1
- $iMsg = GUIGetMsg()
- ; Main "Select" statement that handles other events
- Select
- Case $iMsg = $hFileSel
- $sTmpFile = FileOpenDialog("Select file:", $default_path,"All Files(*.*)", 1+2)
- If @error Then ContinueLoop
- GUICtrlSetData($hFile, $sTmpFile); GUI will be updated at next iteration
- Case $iMsg = $sendbtn
- $eml_value = GUICtrlRead($eml)
- $from_value = GUICtrlRead($From)
- $cycle_value = GUICtrlRead($cycle)
- $subject_value = GUICtrlRead($subject)
- $smtp_value = GUICtrlRead($server)
- $to_value = GUICtrlRead($to)
- $attach_value = GUICtrlRead($hFile)
- if $cycle_value < 1 Then $cycle_value = 1 EndIf
- If $eml_value = 1 Then
- $sendcmd = "c:\temail\temail.exe /smtp=" & $smtp_value & " /from=" & $from_value & " /to=" & $to_value & " /i=" & $cycle_value & ' "' & $attach_value & '"'
- Else
- $sendcmd = "c:\temail\temail.exe /smtp=" & $smtp_value & " /from=" & $from_value & " /to=" & $to_value & " /i=" & $cycle_value & ' /subject="' & $subject_value & '" /a="' & $attach_value & '"'
- EndIf
- GUICtrlSetData($edit,$sendcmd)
- $rc=_RunDos($sendcmd)
- Case $iMsg = $copybtn
- ClipPut(GUICtrlRead($edit))
- Case $iMsg = $GUI_EVENT_CLOSE
- Exit
- EndSelect
- WEnd
- EndFunc ;==>_Main
转载于:https://blog.51cto.com/shuaiguo/620548