From: Pegasus [MVP] on 29 Dec 2009 11:15 "PAkerly" <pakerly(a)gmail.com> said this in news item news:f0f484a8-78c9-46b0-a709-45e2fe54c27c(a)33g2000vbe.googlegroups.com... > On Dec 29, 10:24 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: >> "PAkerly" <pake...(a)gmail.com> said this in news >> itemnews:af062eab-c31a-44e9-a8fe-d98788704c4b(a)h2g2000vbd.googlegroups.com... >> >> >> >> > On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: >> >> "PAkerly" <pake...(a)gmail.com> said this in news >> >> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe(a)r14g2000vbc.googlegroups.com... >> >> >> > Is it possible to use VBScript to attach all files with a particular >> >> > extension to an email? >> >> >> > How could this be done? >> >> >> Use the File System Object to pick up the names of all files with the >> >> desired extension, then use the script below to generate the mail >> >> message. >> >> You need to inlcude one .AddAttachment line for each file to be >> >> attached. >> >> >> const cdoBasic=1 >> >> schema = "http://schemas.microsoft.com/cdo/configuration/" >> >> Set objEmail = CreateObject("CDO.Message") >> >> With objEmail >> >> .From = "Ja...(a)company.com" >> >> .To = "J...(a)company.com" >> >> .Subject = "Test Mail" >> >> .Textbody = "The quick brown fox " & Chr(10) & "jumps over the >> >> lazy dog" >> >> .AddAttachment "d:\Testfile.txt" >> >> With .Configuration.Fields >> >> .Item (schema & "sendusing") = 2 >> >> .Item (schema & "smtpserver") = "mail.company.com" >> >> .Item (schema & "smtpserverport") = 25 >> >> .Item (schema & "smtpauthenticate") = cdoBasic >> >> .Item (schema & "sendusername") = "Ja...(a)company.com" >> >> .Item (schema & "smtpaccountname") = >> >> "Ja...(a)company.com" >> >> .Item (schema & "sendpassword") = "SomePassword" >> >> End With >> >> .Configuration.Fields.Update >> >> .Send >> >> End With >> >> > OK Here is what I am doing, I thought that this would grab all files >> > but it is only getting and attaching one, multiple times... >> >> > 'Grab all .txt files >> > strFolder = "C:\MYFiles" >> > strExt = "txt" >> >> > Set objFSO = CreateObject("Scripting.FileSystemObject") >> > Set objFolder = objFSO.GetFolder(strFolder) >> >> > For Each objFile in objFolder.Files >> > strFileExt = objFSO.GetExtensionName(objFile.Path) >> >> > strFile = objFile.Path >> > next >> >> > 'email the files, there are usually no more than 3 files. >> > Set objMessage = CreateObject("CDO.Message") >> > objMessage.Subject = "Example CDO Message" >> > objMessage.From = "m...(a)HOST.COM" >> > objMessage.To = "m...(a)HOST.COM" >> > objMessage.TextBody = "This is some sample message text." >> > objMessage.AddAttachment strFile >> > objMessage.AddAttachment strFile >> > objMessage.AddAttachment strFile >> >> > '==This section provides the configuration information for the remote >> > SMTP server. >> > '==Normally you will only change the server name or IP. >> > objMessage.Configuration.Fields.Item _ >> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 >> > 'Name or IP of Remote SMTP Server >> > objMessage.Configuration.Fields.Item _ >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = >> > "myserver.host.com" >> > 'Server port (typically 25) >> > objMessage.Configuration.Fields.Item _ >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = >> > 25 >> > objMessage.Configuration.Fields.Update >> > '==End remote SMTP server configuration section== >> > objMessage.Send >> >> > Any ideas how I can make this work? >> >> When you get out of your file scanning loop then strFile is set to the >> name >> of the *last* file found, which is not really what you want. To attach >> all >> files, you must move the loop further down, e.g. as below. I also note >> that >> you're not checking for the correct file extension. >> >> objMessage.TextBody = "This is some sample message text." >> For Each objFile In objFolder.Files >> strFileExt = objFSO.GetExtensionName(objFile.Path) >> objMessage.AddAttachment objFile.Path >> Next > > Does your code only grab text files? or all files? The code objMessage.TextBody = "This is some sample message text." For Each objFile In objFolder.Files strFileExt = objFSO.GetExtensionName(objFile.Path) objMessage.AddAttachment objFile.Path Next is actually your own code, not mine, and it grabs all files, which you will see immediately when you modify it like so: objMessage.TextBody = "This is some sample message text." For Each objFile In objFolder.Files strFileExt = objFSO.GetExtensionName(objFile.Path) wscript.echo objFile.Path Next wscript.quit Remember to run the code with cscript.exe from a Command Prompt.
From: PAkerly on 29 Dec 2009 12:46 On Dec 29, 11:15 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: > "PAkerly" <pake...(a)gmail.com> said this in news itemnews:f0f484a8-78c9-46b0-a709-45e2fe54c27c(a)33g2000vbe.googlegroups.com... > > > > > On Dec 29, 10:24 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: > >> "PAkerly" <pake...(a)gmail.com> said this in news > >> itemnews:af062eab-c31a-44e9-a8fe-d98788704c4b(a)h2g2000vbd.googlegroups.com... > > >> > On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: > >> >> "PAkerly" <pake...(a)gmail.com> said this in news > >> >> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe(a)r14g2000vbc.googlegroups.com... > > >> >> > Is it possible to use VBScript to attach all files with a particular > >> >> > extension to an email? > > >> >> > How could this be done? > > >> >> Use the File System Object to pick up the names of all files with the > >> >> desired extension, then use the script below to generate the mail > >> >> message. > >> >> You need to inlcude one .AddAttachment line for each file to be > >> >> attached. > > >> >> const cdoBasic=1 > >> >> schema = "http://schemas.microsoft.com/cdo/configuration/" > >> >> Set objEmail = CreateObject("CDO.Message") > >> >> With objEmail > >> >> .From = "Ja...(a)company.com" > >> >> .To = "J...(a)company.com" > >> >> .Subject = "Test Mail" > >> >> .Textbody = "The quick brown fox " & Chr(10) & "jumps over the > >> >> lazy dog" > >> >> .AddAttachment "d:\Testfile.txt" > >> >> With .Configuration.Fields > >> >> .Item (schema & "sendusing") = 2 > >> >> .Item (schema & "smtpserver") = "mail.company.com" > >> >> .Item (schema & "smtpserverport") = 25 > >> >> .Item (schema & "smtpauthenticate") = cdoBasic > >> >> .Item (schema & "sendusername") = "Ja...(a)company.com" > >> >> .Item (schema & "smtpaccountname") = > >> >> "Ja...(a)company.com" > >> >> .Item (schema & "sendpassword") = "SomePassword" > >> >> End With > >> >> .Configuration.Fields.Update > >> >> .Send > >> >> End With > > >> > OK Here is what I am doing, I thought that this would grab all files > >> > but it is only getting and attaching one, multiple times... > > >> > 'Grab all .txt files > >> > strFolder = "C:\MYFiles" > >> > strExt = "txt" > > >> > Set objFSO = CreateObject("Scripting.FileSystemObject") > >> > Set objFolder = objFSO.GetFolder(strFolder) > > >> > For Each objFile in objFolder.Files > >> > strFileExt = objFSO.GetExtensionName(objFile.Path) > > >> > strFile = objFile.Path > >> > next > > >> > 'email the files, there are usually no more than 3 files. > >> > Set objMessage = CreateObject("CDO.Message") > >> > objMessage.Subject = "Example CDO Message" > >> > objMessage.From = "m...(a)HOST.COM" > >> > objMessage.To = "m...(a)HOST.COM" > >> > objMessage.TextBody = "This is some sample message text." > >> > objMessage.AddAttachment strFile > >> > objMessage.AddAttachment strFile > >> > objMessage.AddAttachment strFile > > >> > '==This section provides the configuration information for the remote > >> > SMTP server. > >> > '==Normally you will only change the server name or IP. > >> > objMessage.Configuration.Fields.Item _ > >> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 > >> > 'Name or IP of Remote SMTP Server > >> > objMessage.Configuration.Fields.Item _ > >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = > >> > "myserver.host.com" > >> > 'Server port (typically 25) > >> > objMessage.Configuration.Fields.Item _ > >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = > >> > 25 > >> > objMessage.Configuration.Fields.Update > >> > '==End remote SMTP server configuration section== > >> > objMessage.Send > > >> > Any ideas how I can make this work? > > >> When you get out of your file scanning loop then strFile is set to the > >> name > >> of the *last* file found, which is not really what you want. To attach > >> all > >> files, you must move the loop further down, e.g. as below. I also note > >> that > >> you're not checking for the correct file extension. > > >> objMessage.TextBody = "This is some sample message text." > >> For Each objFile In objFolder.Files > >> strFileExt = objFSO.GetExtensionName(objFile.Path) > >> objMessage.AddAttachment objFile.Path > >> Next > > > Does your code only grab text files? or all files? > > The code > > objMessage.TextBody = "This is some sample message text." > For Each objFile In objFolder.Files > strFileExt = objFSO.GetExtensionName(objFile.Path) > objMessage.AddAttachment objFile.Path > Next > > is actually your own code, not mine, and it grabs all files, which you will > see immediately when you modify it like so: > > objMessage.TextBody = "This is some sample message text." > For Each objFile In objFolder.Files > strFileExt = objFSO.GetExtensionName(objFile.Path) > wscript.echo objFile.Path > Next > wscript.quit > > Remember to run the code with cscript.exe from a Command Prompt. So I have this code working but it seems to take at least 3 or 4 minutes to actually send the email. I have put in a messagebox in the For Next loop and it finds the files quickly, but I dont get the email for about 4 minutes. I also dont get the Finished message for a while. 'Email the files strFolder = "C:\MYFiles" strExt = "txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder(strFolder) Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Testing my files email" objMessage.From = "me(a)server.com" objMessage.To = "me(a)server.com" objMessage.TextBody = "This is a test, files should be attached to this email." For Each objFile In objFolder.Files strFileExt = objFSO.GetExtensionName(objFile.Path) objMessage.AddAttachment objFile.Path msgbox "Got file!" Next 'Configuration Info objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server.host.com" 'Server port (typically 25) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update '==End remote SMTP server configuration section== objMessage.Send MsgBox "Finished! An email is being sent" Any idea why it might be taking so long?
From: Pegasus [MVP] on 29 Dec 2009 13:31 "PAkerly" <pakerly(a)gmail.com> said this in news item news:4ec8ef2d-21b8-4e00-ad31-07acda6ec635(a)g12g2000vbl.googlegroups.com... > > So I have this code working but it seems to take at least 3 or 4 > minutes to actually send the email. I have put in a messagebox in the > For Next loop and it finds the files quickly, but I dont get the email > for about 4 minutes. I also dont get the Finished message for a while. > > 'Email the files > strFolder = "C:\MYFiles" > strExt = "txt" > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objFolder = objFSO.GetFolder(strFolder) > > Set objMessage = CreateObject("CDO.Message") > objMessage.Subject = "Testing my files email" > objMessage.From = "me(a)server.com" > objMessage.To = "me(a)server.com" > objMessage.TextBody = "This is a test, files should be attached to > this email." > For Each objFile In objFolder.Files > strFileExt = objFSO.GetExtensionName(objFile.Path) > objMessage.AddAttachment objFile.Path > msgbox "Got file!" > Next > 'Configuration Info > objMessage.Configuration.Fields.Item _ > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 > 'Name or IP of Remote SMTP Server > objMessage.Configuration.Fields.Item _ > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = > "server.host.com" > 'Server port (typically 25) > objMessage.Configuration.Fields.Item _ > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = > 25 > objMessage.Configuration.Fields.Update > '==End remote SMTP server configuration section== > objMessage.Send > > MsgBox "Finished! An email is being sent" > > > Any idea why it might be taking so long? It would make more sense to put the line [msgbox "Got file!"] *after* the [next] line so that you can see when all files are attached. The time to transmit the message depends on a number of factors, e.g. - The number of files - The size of all attachments - The speed of the link to your SMTP server - How quickly the SMTP server processes your message - The speed of the link from your POP3 server to your PC - How often your mail client polls the POP3 server To locate the bottle neck you need to perform some tests, e.g. vary the number/size of the attachments and/or use some other application to send a test mail, e.g. Outlook Express.
First
|
Prev
|
Pages: 1 2 Prev: Rename files based on file name? Next: printui.dll command line in a batch file |