chachew Posted August 25, 2011 Posted August 25, 2011 I am using the SMTP mailer: http://www.autoitscript.com/forum/topic/...iler-that-supports-html-and-at It works perfectly except i need to attach all files within a folder ("C:\test") The problem is there can be any number of file and any random name for each file. The thing that is the same is the extension of XXXXXXX.ejpg. Is there a way to wildcard the files like $AttachFiles = "C:\test\*.ejpg"
KaFu Posted August 25, 2011 Posted August 25, 2011 For sure there is... but before that, how about using a pre-processing function to zip all files in the target directory and attach only the resulting zip file? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
hannes08 Posted August 25, 2011 Posted August 25, 2011 I am using the SMTP mailer: http://www.autoitscript.com/forum/topic/...iler-that-supports-html-and-at It works perfectly except i need to attach all files within a folder ("C:\test") The problem is there can be any number of file and any random name for each file. The thing that is the same is the extension of XXXXXXX.ejpg. Is there a way to wildcard the files like $AttachFiles = "C:\test\*.ejpg" #include <file.au3> #include <array.au3> $a_files = _FileListtoArray("C:\test", "*.jpg", 1) $AttachFiles = _ArrayToString($a_files, ";", 1) Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
chachew Posted August 25, 2011 Author Posted August 25, 2011 #include <file.au3> #include <array.au3> $a_files = _FileListtoArray("C:\test", "*.jpg", 1) $AttachFiles = _ArrayToString($a_files, ";", 1) Hmmm, now i'm getting an error: Error code:1 Description:0
chachew Posted August 25, 2011 Author Posted August 25, 2011 For sure there is... but before that, how about using a pre-processing function to zip all files in the target directory and attach only the resulting zip file?I was looking at that first, that would be the best option. Was looking at the Zip.au3 thread somewhere in here but am having some issues with that at the moment. Any advice on that? Newb at Autoit
hannes08 Posted August 25, 2011 Posted August 25, 2011 Hmmm, now i'm getting an error: Error code:1 Description:0Works fine for me, pal,Error code 1 for _FileListtoArray() means: Path not found or invalid. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
chachew Posted August 25, 2011 Author Posted August 25, 2011 Soo do i have these variables in the correct location? Looks correct to me but....not completely sure Works fine for me, pal, Error code 1 for _FileListtoArray() means: Path not found or invalid. #Include <file.au3> #include <array.au3> $SmtpServer = "smtp.test.com" ; address for the smtp-server to use - REQUIRED $FromName = "Test name" ; name from who the email was sent $FromAddress = "test@test.com" ; address from where the mail should come $ToAddress = "help@test.com" ; destination address of the email - REQUIRED $Subject = "Email update" ; subject from the email - can be anything you want it to be $Body = "here are you files" ; the messagebody from the mail - can be left blank but then you get a blank mail $a_files = _FileListtoArray("C:\test", "*.ejpg", 1) $AttachFiles = _ArrayToString($a_files, ";", 1) $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" ; username for the account used from where the mail gets sent - REQUIRED $Password = "password" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 1 ; 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 ;##################################
hannes08 Posted August 25, 2011 Posted August 25, 2011 Looks okay for me, too. You might want to add a _ArrayDisplay($a_files) after the line with _FileListtoarray() for debuggung reasons. What filetypes are .Ejpg files? Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
chachew Posted August 25, 2011 Author Posted August 25, 2011 (edited) Looks okay for me, too. You might want to add a _ArrayDisplay($a_files) after the line with _FileListtoarray() for debuggung reasons. What filetypes are .Ejpg files? The .ejpg files are an encrypted image file, after adding the _ArrayDisplay($a_files) i get: [0]|2 [1]|13-13-52=08-25-11-back.ejpg [2]|13-13-52=08-25-11-front.ejpg After i close the Display window i get the Error code:1 Description:0 error again. If i have $a_files = _FileListToArray("C:\test", "\*.ejpg", 1) i get no error and no _ArrayDisplay but if i have $a_files = _FileListToArray("C:\test\", "*.ejpg", 1) i get the _ArrayDisplay and the error When i have it as: $a_files = _FileListToArray("C:\test", "\*.ejpg", 1) i still recieve the emails just with no attachments Edited August 25, 2011 by mkirkland
hannes08 Posted August 25, 2011 Posted August 25, 2011 If it shows you the _ArrayDisplay, then it's been fine so far. Showing no Array Display means that there's been an error. Can you post your complete script and mark the exac line where the error occurs? Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
chachew Posted August 25, 2011 Author Posted August 25, 2011 If it shows you the _ArrayDisplay, then it's been fine so far. Showing no Array Display means that there's been an error. Can you post your complete script and mark the exac line where the error occurs? I only get the error message after i see the output of the _ArrayDisplay expandcollapse popup#Include <file.au3> #include <array.au3> $SmtpServer = "smtp.test.com" ; address for the smtp-server to use - REQUIRED $FromName = "Test name" ; name from who the email was sent $FromAddress = "test@test.com" ; address from where the mail should come $ToAddress = "help@test.com" ; destination address of the email - REQUIRED $Subject = "Email update" ; subject from the email - can be anything you want it to be $Body = "here are you files" ; the messagebody from the mail - can be left blank but then you get a blank mail $a_files = _FileListtoArray("C:\test", "*.ejpg", 1) $AttachFiles = _ArrayToString($a_files, ";", 1) $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" ; username for the account used from where the mail gets sent - REQUIRED $Password = "password" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 1 ; 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 = 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 : $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]) 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="" 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
chachew Posted August 26, 2011 Author Posted August 26, 2011 I ended up getting the Zip.au3 to work so i just zip it first then attach the .zip file so that actually works out even better for me. Thanks for all the help!
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