Derk Posted October 25, 2011 Share Posted October 25, 2011 I have a script that sends an email using _INetSmtpMail but what i would like to do is create a GUI with two drop down lists and have the ability to choose the following. 1. FROM address 2.TO Adress. #include <INet.au3> #AutoIt3Wrapper_icon=alert.ico $begin=MsgBox(0x4, "Emergency Alerts(UDI)", "Are you sure you want to proceed?") if $begin = 7 then exit $s_SmtpServer = "Mail1" $s_FromName = "Emergency Alert (UDI)" $s_FromAddress = alerts@domain.com $s_ToAddress = "alerts@domain.com" $s_Subject = "********* EMERGENCY ALERT *********" Dim $as_Body[2] $as_Body[0] = "Attention all employees. Office Alert," $as_Body[1] = "please proceed in an orderly fashion to the safest exit. Thank you" $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1); Link to comment Share on other sites More sharing options...
water Posted October 25, 2011 Share Posted October 25, 2011 And what's your question? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Derk Posted October 25, 2011 Author Share Posted October 25, 2011 I am not sure how to incorporate this into what i have now. I want to create a script the allows me to click a drop down list and choose the FROM and TO email addresses. Link to comment Share on other sites More sharing options...
water Posted October 25, 2011 Share Posted October 25, 2011 Still no question. But I would suggest you read the GUI part of the AutoIt docu. This should give you a good start. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sleepydvdr Posted October 25, 2011 Share Posted October 25, 2011 It ain't pretty, but it will get you started. Like water said, you need to do some reading in the help file. Also, search the forum for Koda. It is a graphical designer. expandcollapse popup#AutoIt3Wrapper_icon=alert.ico #include <INet.au3> #include <GUIConstants.au3> #include <array.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 437, 175) $Label1 = GUICtrlCreateLabel("From:", 16, 16, 30, 17) $Combo1 = GUICtrlCreateCombo("", 16, 40, 305, 25) GUICtrlSetData($Combo1, "Emergency Alert (UDI)&senderaddress1@domain.com|Emergency Alert (UDI)&senderaddress2@domain2.com", "Emergency Alert (UDI)&senderaddress1@domain.com") $Label2 = GUICtrlCreateLabel("To:", 16, 88, 20, 17) $Combo2 = GUICtrlCreateCombo("", 16, 112, 305, 25) GUICtrlSetData($Combo2, "emailaddress1@domain.com|emailaddress2@domain2.com", "emailaddress1@domain.com") $Button1 = GUICtrlCreateButton("Send", 336, 72, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _SendMail() EndSwitch WEnd Func _SendMail() $temp = GUICtrlRead($Combo1) $s_FromAddress = StringSplit($temp, "&") _ArrayDisplay($s_FromAddress) $begin=MsgBox(0x4, "Emergency Alerts(UDI)", "Are you sure you want to proceed?") if $begin = 7 then exit $s_SmtpServer = "Mail1" ;$s_FromName = "Emergency Alert (UDI)" ;$s_FromAddress = alerts@domain.com ;$s_ToAddress = "alerts@domain.com" $s_Subject = "********* EMERGENCY ALERT *********" Dim $as_Body[2] $as_Body[0] = "Attention all employees. Office Alert," $as_Body[1] = "please proceed in an orderly fashion to the safest exit. Thank you" $Response = _INetSmtpMail ($s_SmtpServer, $s_FromAddress[1], $s_FromAddress[2], $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1); EndFunc #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
bb01 Posted November 4, 2011 Share Posted November 4, 2011 (edited) this is one i use, it allows for compessing files and then will send them as an attachment to a given email address from which ever email you put down... Will need tweaking to fit your needs.. but works well... expandcollapse popup;#AutoIt3Wrapper_icon=Icons\email.ico ; idea from ; http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/ ;################################## ; Include ;################################## #Include<file.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;################################## ; Variables ;################################## FileCopy("C:\Save\*.*", @ScriptDir & "\Resumes_&_Cover_Letters") Global $PIC_GUI_3 = @ScriptDir & '\Tech.bmp' Local $GUI_SS_DEFAULT_PIC Local $oIE, $GUIActiveX, $email2, $GUI_Button_File, $GUI_Button_send, $GUI_Button_Home Local $msg, $iItems, $aDrive, $aButtons, $oHTTP, $email21 $oIE = ObjCreate("Shell.Explorer.2") ; Create a simple GUI for our output GUICreate("Email Sender", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) GUISetBkColor(0x0000FF) GUICtrlCreatePic($PIC_GUI_3,0,0,800,600, BitOR($GUI_SS_DEFAULT_PIC, $WS_CLIPSIBLINGS)) $GUIActiveX = GUICtrlCreateObj ($oIE, -215, 0, 855, 550) $email2 = GUICtrlCreateButton("Email Address To Send To", 10, 555, 180, 20) ;$GUI_Button_CD = GUICtrlCreateButton("CD", 95, 560, 80, 20) $GUI_Button_File = GUICtrlCreateButton("Attach File/s", 200, 555, 135, 20) $GUI_Button_Home = GUICtrlCreateButton("Home", 345, 555, 135, 20) $GUI_Button_send = GUICtrlCreateButton("Send && Exit", 495, 555, 135, 20) GUISetState() ;Show GUI $oIE.navigate(@ScriptDir & "\Resumes_&_Cover_Letters") ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE FileDelete("C:\temp\resume\*.*") FileDelete("C:\temp\resume\7za.exe") FileDelete("C:\temp\*.*") DirRemove("C:\temp\", 1) ExitLoop Case $msg = $email2 $email21=InputBox("Email", "Enter Email Address To Send To", "") Case $msg = $GUI_Button_File DirCreate("C:\temp\resume") Send("^c") $oIE.navigate("C:\temp\resume") Send("^v") FileCopy(@ScriptDir & "\7zip\7za.exe", "C:\temp\*.*") ShellExecuteWait(@ScriptDir & "\7zip\testing.exe") $oIE.navigate(@ScriptDir & "\Resumes_&_Cover_Letters") Case $msg = $GUI_Button_Home $oIE.navigate(@ScriptDir & "\Resumes_&_Cover_Letters") Case $msg = $GUI_Button_send ExitLoop EndSelect WEnd GUIDelete() ;###FILL IN THIS INFO### ;$Name = InputBox("Email", "Enter Your Name", "") ;$User = InputBox("Email", "Enter Username", "") ;$Pass = InputBox("Email", "Enter Password", "", "*") $email1 = InputBox("Email", "Enter Your Email Address", "") $email2 = InputBox("Email", "Enter Email Address To Send To", "") ;$Subject = InputBox("Email", "Enter The Subject", "") $SmtpServer = "smtp.aol.com"; ; address for the smtp-server to use - REQUIRED $FromName = "-NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY- -NEOMA NO REPLY--NEOMA NO REPLY- -NEOMA NO REPLY-";($Name) ; name from who the email was sent $FromAddress = ($email1) ; address from where the mail should come $ToAddress = ($email21) ; destination address of the email - REQUIRED $Subject = "Here's Your Email";($Subject) ; subject from the email - can be anything you want it to be $Body = "Heres Your Files..." ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "C:\temp\Your_Files.zip" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "";"" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "username";($User) ; username for the account used from where the mail gets sent - REQUIRED $Password = "************";($Pass) ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 587;26 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS ;~ $IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS ;################################## ; Script ;################################## 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) EndIf ; ; 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 = 993, $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 : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) FileDelete("C:\temp\resume\*.*") FileDelete("C:\temp\resume\7za.exe") FileDelete("C:\temp\*.*") DirRemove("C:\temp\", 1) 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 "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" FileDelete("C:\temp\resume\*.*") FileDelete("C:\temp\resume\7za.exe") FileDelete("C:\temp\*.*") DirRemove("C:\temp\", 1) 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 ;----------------------------- End _Email_Sender ----------------------------------------- Edited November 4, 2011 by bb01 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now