因为环境中需要用到temail向多个邮件服务器发送邮件,所以利用Autoit做了个简单的UI界面,可以从文件读取邮件服务器和邮箱账号列表,并选择指定的邮件发送。

 

 
  
  1. #include <Process.au3>  
  2. #include <GuiConstantsEx.au3>  
  3. #include <WindowsConstants.au3>  
  4. #include <ButtonConstants.au3>  
  5. #include <StaticConstants.au3>  
  6. #include <file.au3>  
  7.  
  8.  
  9.  
  10. Global $default_path = "c:\temail" 
  11. _Main()  
  12.  
  13. Func _Main()  
  14.     Local $hGui$hFile$hFileSel 
  15.     Local $iMsg$sCurFilename$sTmpFile 
  16.       
  17.     Dim $aServers 
  18.     Dim $aAccounts 
  19.     _FileReadToArray("server.txt",$aServers) ;read smtp server list from server.txt  
  20.     _FileReadToArray("account.txt",$aAccounts) ;read email account list from account.txt  
  21.     ;$aServers[0] is array's length  
  22.       
  23.     ; Creating GUI and controls  
  24.     $hGui = GUICreate("Send Email use Temail", 500, 500, -1, $WS_EX_ACCEPTFILES)  
  25.       
  26.     ; CHECKBOX  
  27.     $lable6 = GUICtrlCreateLabel("Send eml file", 15, 30, 80, 20)  
  28.     $eml = GuiCtrlCreateCheckbox("1", 5,30, 10, 10)  
  29.     ;GuiCtrlSetState(-1, $GUI_CHECKED)  
  30.  
  31.  
  32.     $Lable1 = GUICtrlCreateLabel("From:",5,50,50,50)  
  33.     $From = GuiCtrlCreateInput("test@test.com", 5, 70, 100, 25)  
  34.     $Lable2 = GUICtrlCreateLabel("Cycles:",130,50,50,50)  
  35.     $cycle = GuiCtrlCreateInput("1", 130, 70, 50, 25)  
  36.     $Lable3 = GUICtrlCreateLabel("Subject:",200,50,50,50)  
  37.     $subject = GuiCtrlCreateInput("test for smex", 200, 70, 200, 25)  
  38.  
  39.  
  40.     $hFile = GUICtrlCreateInput($default_path, 5, 110, 350, 16, -1, $WS_EX_STATICEDGE)    
  41.     ;GUICtrlSetState(-1, $GUI_DROPACCEPTED)  
  42.     ;GUICtrlSetTip(-1, "You can drop files from shell here...")  
  43.     $hFileSel = GUICtrlCreateButton("...", 370, 110, 26, 18)  
  44.     $serverlist = "" 
  45.     $accountlist = "" 
  46.     For $x = 1 to $aServers[0]  
  47.         ;get serverlist format s1|s2|s3  
  48.         $serverlist = $serverlist & "|" & $aServers[$x]  
  49.     Next  
  50.     For $y = 1 to $aAccounts[0]  
  51.         $accountlist = $accountlist & "|" & $aAccounts[$y]  
  52.     Next  
  53.     ; LIST1  
  54.     $Lable4 = GUICtrlCreateLabel("Server:",5,140,140,25)  
  55.     $server = GuiCtrlCreateList("", 5, 160, 150, 90)  
  56.     GuiCtrlSetData(-1, $serverlist$aServers[2])  
  57.  
  58.     ; LIST2  
  59.     $Lable5 = GUICtrlCreateLabel("To:",160,140,140,50)  
  60.     $to = GuiCtrlCreateList("", 160, 160, 150, 90)  
  61.     GuiCtrlSetData(-1, $accountlist$aAccounts[2])  
  62.       
  63.     $l7 = GUICtrlCreateLabel("Command:",5,300,50,50)  
  64.     $edit = GUICtrlCreateEdit("",5,320,500,100)  
  65.     ; BUTTON  
  66.     $sendbtn = GuiCtrlCreateButton("Send Email", 10, 260, 100, 30)  
  67.     $copybtn = GuiCtrlCreateButton("Copy Command", 150,260,100,30)  
  68.     GUISetState()  
  69.  
  70.     While 1  
  71.         $iMsg = GUIGetMsg()  
  72.         ; Main "Select" statement that handles other events  
  73.         Select  
  74.         Case $iMsg = $hFileSel                
  75.                 $sTmpFile = FileOpenDialog("Select file:"$default_path,"All Files(*.*)", 1+2)  
  76.                 If @error Then ContinueLoop  
  77.                 GUICtrlSetData($hFile$sTmpFile); GUI will be updated at next iteration  
  78.         Case $iMsg = $sendbtn 
  79.                 $eml_value = GUICtrlRead($eml)  
  80.                 $from_value = GUICtrlRead($From)  
  81.                 $cycle_value = GUICtrlRead($cycle)  
  82.                 $subject_value = GUICtrlRead($subject)  
  83.                 $smtp_value = GUICtrlRead($server)  
  84.                 $to_value = GUICtrlRead($to)  
  85.                 $attach_value = GUICtrlRead($hFile)  
  86.                 if $cycle_value < 1 Then $cycle_value = 1 EndIf  
  87.                 If $eml_value = 1 Then   
  88.                     $sendcmd = "c:\temail\temail.exe /smtp=" & $smtp_value & " /from=" & $from_value & " /to=" & $to_value & " /i=" & $cycle_value & ' "' & $attach_value & '"' 
  89.                 Else  
  90.                     $sendcmd = "c:\temail\temail.exe /smtp=" & $smtp_value & " /from=" & $from_value & " /to=" & $to_value & " /i=" & $cycle_value & ' /subject="' & $subject_value & '" /a="' & $attach_value & '"' 
  91.                 EndIf                 
  92.                 GUICtrlSetData($edit,$sendcmd)  
  93.                 $rc=_RunDos($sendcmd)  
  94.         Case $iMsg = $copybtn 
  95.                 ClipPut(GUICtrlRead($edit))  
  96.         Case $iMsg = $GUI_EVENT_CLOSE 
  97.                 Exit 
  98.         EndSelect  
  99.     WEnd  
  100. EndFunc   ;==>_Main