Attach all files in directory to email?

Is it possible to use VBScript to attach all files with a particular
extension to an email?

How could this be done?
0
PAkerly
12/28/2009 9:39:09 PM
scripting.vbscript 564 articles. 0 followers. Follow

7 Replies
2210 Views

Similar Articles

[PageSpeed] 43

"PAkerly" <pakerly@gmail.com> said this in news item 
news:60dc06b6-6c7c-488a-8ac5-edb19784cffe@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 = "James@company.com"
	.To = "Jim@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") = "James@company.com"
		.Item (schema & "smtpaccountname") = "James@company.com"
		.Item (schema & "sendpassword") = "SomePassword"
	End With
	.Configuration.Fields.Update
	.Send
End With
 

0
Pegasus
12/29/2009 12:07:41 AM
On Dec 28, 7:07=A0pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "PAkerly" <pake...@gmail.com> said this in news itemnews:60dc06b6-6c7c-48=
8a-8ac5-edb19784cffe@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=3D1
> schema =3D "http://schemas.microsoft.com/cdo/configuration/"
> Set objEmail =3D CreateObject("CDO.Message")
> With objEmail
> =A0 =A0 =A0 =A0 .From =3D "Ja...@company.com"
> =A0 =A0 =A0 =A0 .To =3D "J...@company.com"
> =A0 =A0 =A0 =A0 .Subject =3D "Test Mail"
> =A0 =A0 =A0 =A0 .Textbody =3D "The quick brown fox " & Chr(10) & "jumps o=
ver the lazy dog"
> =A0 =A0 =A0 =A0 .AddAttachment "d:\Testfile.txt"
> =A0 =A0 =A0 =A0 With .Configuration.Fields
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusing") =3D 2
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserver") =3D "mail.c=
ompany.com"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserverport") =3D 25
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpauthenticate") =3D c=
doBasic
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusername") =3D "Ja..=
..@company.com"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpaccountname") =3D "J=
a...@company.com"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendpassword") =3D "Some=
Password"
> =A0 =A0 =A0 =A0 End With
> =A0 =A0 =A0 =A0 .Configuration.Fields.Update
> =A0 =A0 =A0 =A0 .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 =3D "C:\MYFiles"
strExt =3D "txt"

Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Set objFolder =3D objFSO.GetFolder(strFolder)

For Each objFile in objFolder.Files
    strFileExt =3D objFSO.GetExtensionName(objFile.Path)

        strFile =3D objFile.Path
next

'email the files, there are usually no more than 3 files.
Set objMessage =3D CreateObject("CDO.Message")
objMessage.Subject =3D "Example CDO Message"
objMessage.From =3D "me@HOST.COM"
objMessage.To =3D "me@HOST.COM"
objMessage.TextBody =3D "This is some sample message text."
objMessage.AddAttachment strFile
objMessage.AddAttachment strFile
objMessage.AddAttachment strFile

'=3D=3DThis section provides the configuration information for the remote
SMTP server.
'=3D=3DNormally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") =3D 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =3D
"myserver.host.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =3D
25
objMessage.Configuration.Fields.Update
'=3D=3DEnd remote SMTP server configuration section=3D=3D
objMessage.Send

Any ideas how I can make this work?
0
PAkerly
12/29/2009 2:10:58 PM

"PAkerly" <pakerly@gmail.com> said this in news item 
news:af062eab-c31a-44e9-a8fe-d98788704c4b@h2g2000vbd.googlegroups.com...
> On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
>> "PAkerly" <pake...@gmail.com> said this in news 
>> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe@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...@company.com"
>>         .To = "J...@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...@company.com"
>>                 .Item (schema & "smtpaccountname") = "Ja...@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 = "me@HOST.COM"
> objMessage.To = "me@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
 

0
Pegasus
12/29/2009 3:24:06 PM
On Dec 29, 10:24=A0am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "PAkerly" <pake...@gmail.com> said this in news itemnews:af062eab-c31a-44=
e9-a8fe-d98788704c4b@h2g2000vbd.googlegroups.com...
>
>
>
> > On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> >> "PAkerly" <pake...@gmail.com> said this in news
> >> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe@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 attach=
ed.
>
> >> const cdoBasic=3D1
> >> schema =3D "http://schemas.microsoft.com/cdo/configuration/"
> >> Set objEmail =3D CreateObject("CDO.Message")
> >> With objEmail
> >> =A0 =A0 =A0 =A0 .From =3D "Ja...@company.com"
> >> =A0 =A0 =A0 =A0 .To =3D "J...@company.com"
> >> =A0 =A0 =A0 =A0 .Subject =3D "Test Mail"
> >> =A0 =A0 =A0 =A0 .Textbody =3D "The quick brown fox " & Chr(10) & "jump=
s over the
> >> lazy dog"
> >> =A0 =A0 =A0 =A0 .AddAttachment "d:\Testfile.txt"
> >> =A0 =A0 =A0 =A0 With .Configuration.Fields
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusing") =3D 2
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserver") =3D "mai=
l.company.com"
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserverport") =3D =
25
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpauthenticate") =
=3D cdoBasic
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusername") =3D "J=
a...@company.com"
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpaccountname") =3D=
 "Ja...@company.com"
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendpassword") =3D "S=
omePassword"
> >> =A0 =A0 =A0 =A0 End With
> >> =A0 =A0 =A0 =A0 .Configuration.Fields.Update
> >> =A0 =A0 =A0 =A0 .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 =3D "C:\MYFiles"
> > strExt =3D "txt"
>
> > Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > Set objFolder =3D objFSO.GetFolder(strFolder)
>
> > For Each objFile in objFolder.Files
> > =A0 =A0strFileExt =3D objFSO.GetExtensionName(objFile.Path)
>
> > =A0 =A0 =A0 =A0strFile =3D objFile.Path
> > next
>
> > 'email the files, there are usually no more than 3 files.
> > Set objMessage =3D CreateObject("CDO.Message")
> > objMessage.Subject =3D "Example CDO Message"
> > objMessage.From =3D "m...@HOST.COM"
> > objMessage.To =3D "m...@HOST.COM"
> > objMessage.TextBody =3D "This is some sample message text."
> > objMessage.AddAttachment strFile
> > objMessage.AddAttachment strFile
> > objMessage.AddAttachment strFile
>
> > '=3D=3DThis section provides the configuration information for the remo=
te
> > SMTP server.
> > '=3D=3DNormally you will only change the server name or IP.
> > objMessage.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") =3D 2
> > 'Name or IP of Remote SMTP Server
> > objMessage.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =3D
> > "myserver.host.com"
> > 'Server port (typically 25)
> > objMessage.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =3D
> > 25
> > objMessage.Configuration.Fields.Update
> > '=3D=3DEnd remote SMTP server configuration section=3D=3D
> > 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 na=
me
> of the *last* file found, which is not really what you want. To attach al=
l
> files, you must move the loop further down, e.g. as below. I also note th=
at
> you're not checking for the correct file extension.
>
> objMessage.TextBody =3D "This is some sample message text."
> For Each objFile In objFolder.Files
> =A0 =A0 strFileExt =3D objFSO.GetExtensionName(objFile.Path)
> =A0 =A0 objMessage.AddAttachment objFile.Path
> Next

Does your code only grab text files? or all files?
0
PAkerly
12/29/2009 3:35:57 PM

"PAkerly" <pakerly@gmail.com> said this in news item 
news:f0f484a8-78c9-46b0-a709-45e2fe54c27c@33g2000vbe.googlegroups.com...
> On Dec 29, 10:24 am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
>> "PAkerly" <pake...@gmail.com> said this in news 
>> itemnews:af062eab-c31a-44e9-a8fe-d98788704c4b@h2g2000vbd.googlegroups.com...
>>
>>
>>
>> > On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
>> >> "PAkerly" <pake...@gmail.com> said this in news
>> >> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe@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...@company.com"
>> >>         .To = "J...@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...@company.com"
>> >>                 .Item (schema & "smtpaccountname") = 
>> >> "Ja...@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...@HOST.COM"
>> > objMessage.To = "m...@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.
 

0
Pegasus
12/29/2009 4:15:43 PM
On Dec 29, 11:15=A0am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "PAkerly" <pake...@gmail.com> said this in news itemnews:f0f484a8-78c9-46=
b0-a709-45e2fe54c27c@33g2000vbe.googlegroups.com...
>
>
>
> > On Dec 29, 10:24 am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> >> "PAkerly" <pake...@gmail.com> said this in news
> >> itemnews:af062eab-c31a-44e9-a8fe-d98788704c4b@h2g2000vbd.googlegroups.=
com...
>
> >> > On Dec 28, 7:07 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> >> >> "PAkerly" <pake...@gmail.com> said this in news
> >> >> itemnews:60dc06b6-6c7c-488a-8ac5-edb19784cffe@r14g2000vbc.googlegro=
ups.com...
>
> >> >> > Is it possible to use VBScript to attach all files with a particu=
lar
> >> >> > extension to an email?
>
> >> >> > How could this be done?
>
> >> >> Use the File System Object to pick up the names of all files with t=
he
> >> >> 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=3D1
> >> >> schema =3D "http://schemas.microsoft.com/cdo/configuration/"
> >> >> Set objEmail =3D CreateObject("CDO.Message")
> >> >> With objEmail
> >> >> =A0 =A0 =A0 =A0 .From =3D "Ja...@company.com"
> >> >> =A0 =A0 =A0 =A0 .To =3D "J...@company.com"
> >> >> =A0 =A0 =A0 =A0 .Subject =3D "Test Mail"
> >> >> =A0 =A0 =A0 =A0 .Textbody =3D "The quick brown fox " & Chr(10) & "j=
umps over the
> >> >> lazy dog"
> >> >> =A0 =A0 =A0 =A0 .AddAttachment "d:\Testfile.txt"
> >> >> =A0 =A0 =A0 =A0 With .Configuration.Fields
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusing") =3D 2
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserver") =3D "=
mail.company.com"
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpserverport") =
=3D 25
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpauthenticate")=
 =3D cdoBasic
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendusername") =3D=
 "Ja...@company.com"
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "smtpaccountname") =
=3D
> >> >> "Ja...@company.com"
> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Item (schema & "sendpassword") =3D=
 "SomePassword"
> >> >> =A0 =A0 =A0 =A0 End With
> >> >> =A0 =A0 =A0 =A0 .Configuration.Fields.Update
> >> >> =A0 =A0 =A0 =A0 .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 =3D "C:\MYFiles"
> >> > strExt =3D "txt"
>
> >> > Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> >> > Set objFolder =3D objFSO.GetFolder(strFolder)
>
> >> > For Each objFile in objFolder.Files
> >> > =A0 =A0strFileExt =3D objFSO.GetExtensionName(objFile.Path)
>
> >> > =A0 =A0 =A0 =A0strFile =3D objFile.Path
> >> > next
>
> >> > 'email the files, there are usually no more than 3 files.
> >> > Set objMessage =3D CreateObject("CDO.Message")
> >> > objMessage.Subject =3D "Example CDO Message"
> >> > objMessage.From =3D "m...@HOST.COM"
> >> > objMessage.To =3D "m...@HOST.COM"
> >> > objMessage.TextBody =3D "This is some sample message text."
> >> > objMessage.AddAttachment strFile
> >> > objMessage.AddAttachment strFile
> >> > objMessage.AddAttachment strFile
>
> >> > '=3D=3DThis section provides the configuration information for the r=
emote
> >> > SMTP server.
> >> > '=3D=3DNormally you will only change the server name or IP.
> >> > objMessage.Configuration.Fields.Item _
> >> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") =3D 2
> >> > 'Name or IP of Remote SMTP Server
> >> > objMessage.Configuration.Fields.Item _
> >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =3D
> >> > "myserver.host.com"
> >> > 'Server port (typically 25)
> >> > objMessage.Configuration.Fields.Item _
> >> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
=3D
> >> > 25
> >> > objMessage.Configuration.Fields.Update
> >> > '=3D=3DEnd remote SMTP server configuration section=3D=3D
> >> > 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 =3D "This is some sample message text."
> >> For Each objFile In objFolder.Files
> >> =A0 =A0 strFileExt =3D objFSO.GetExtensionName(objFile.Path)
> >> =A0 =A0 objMessage.AddAttachment objFile.Path
> >> Next
>
> > Does your code only grab text files? or all files?
>
> The code
>
> objMessage.TextBody =3D "This is some sample message text."
> For Each objFile In objFolder.Files
> =A0 =A0 strFileExt =3D objFSO.GetExtensionName(objFile.Path)
> =A0 =A0 objMessage.AddAttachment objFile.Path
> Next
>
> is actually your own code, not mine, and it grabs all files, which you wi=
ll
> see immediately when you modify it like so:
>
> objMessage.TextBody =3D "This is some sample message text."
> For Each objFile In objFolder.Files
> =A0 =A0 strFileExt =3D objFSO.GetExtensionName(objFile.Path)
> =A0 =A0 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 =3D "C:\MYFiles"
strExt =3D "txt"

Set objFSO =3D CreateObject("Scripting.FileSystemObject")
Set objFolder =3D objFSO.GetFolder(strFolder)

Set objMessage =3D CreateObject("CDO.Message")
objMessage.Subject =3D "Testing my files email"
objMessage.From =3D "me@server.com"
objMessage.To =3D "me@server.com"
objMessage.TextBody =3D "This is a test, files should be attached to
this email."
For Each objFile In objFolder.Files
    strFileExt =3D 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") =3D 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =3D
"server.host.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =3D
25
objMessage.Configuration.Fields.Update
'=3D=3DEnd remote SMTP server configuration section=3D=3D
objMessage.Send

MsgBox "Finished! An email is being sent"


Any idea why it might be taking so long?
0
PAkerly
12/29/2009 5:46:16 PM

"PAkerly" <pakerly@gmail.com> said this in news item 
news:4ec8ef2d-21b8-4e00-ad31-07acda6ec635@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@server.com"
> objMessage.To = "me@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. 

0
Pegasus
12/29/2009 6:31:14 PM
Reply:

Similar Artilces:

SBS 2003 and Email Not Receiving
We have SBS 2003 Installed. We had a linkys router that we replaced with a small business cisco gigabit router. After the router changed, internet would work, we can send email to extrenal, send and receive intenral emails but receiving external wouldnt work. We ran the Email/Internet repair via SBS. Receiving external email worked. Few hours later it stoped. We ran it again and it works. This keeps going..it works for few hours and than stops. Is there something that we missed or a setting that we need to setup on the router so it keeps it up all the time. Thanks -- mal...

i want to compress photos in attachment
i want to compress photos in attachment pl. give me some sol. regards www.irfranview.com "compress photos in attachment" <compress photos in attachment@discussions.microsoft.com> wrote in message news:738E96D6-F0E2-4FFF-8570-6A8F00E492D1@microsoft.com... :i want to compress photos in attachment : : pl. give me some sol. : : regards On Apr 22, 7:50=A0am, compress photos in attachment <compress photos in attachm...@discussions.microsoft.com> wrote: > i want to compress photos in attachment > > pl. give me some sol. > > regards...

Emails #8
i am recieving my emails ten minutes after everyone else in the company and it is started to effect urgent matters, i havegone into outlok tools to see if i could change anything but that doesnt seem to have worked, can someone please help What version of Outlook are you using? If Outlook 2003 do you have the Junk Mail filter turned on? Is this an Exchange Environment? If so, what version. "Kim" <anonymous@discussions.microsoft.com> wrote in message news:fb2901c43e6f$d095b2a0$a501280a@phx.gbl... >i am recieving my emails ten minutes after everyone else > in the co...

Retrieve Lost Email
How can I retrieve a user's email message if they accidently delete? Is there a folder that I can look into? Thanks. -- Semper Fi ------------ Never retreat. Never surrender. if you have Deleted Items Retention configured, you can recover it from Outlook - Tools, Recover Deleted items...if not, you're looking at a restore... "Devil Dog" <DevilDog@discussions.microsoft.com> wrote in message news:AEBB32DF-97CE-4595-9B2D-61057B928062@microsoft.com... > How can I retrieve a user's email message if they accidently delete? Is > there a folder that I can look...

Email with no address, subject or content
Please bear with me if this subject has been covered ad nauseum, but I frequently receive email with no "From:" address, no subject and no apparent content. I'm running Outlook 2002. Can anyone tell me what's going on here? Is it an attempt to plant a Web bug? Regardless, I would like to create a rule that automatically dumps such mail in my spam folder. Using the rules wizard I see how to redirect email from a specific address, but leaving the address field blank doesn't work. Thanks in advance for any help. mb ...

Ugly lines between emails in viewing pane
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel Email Client: pop I have Outlook at work and you can turn these lines off but I cant find anywhere to turn these off in Entourage 2008. They weren't there in Entourage 2004. Is there anyway of turning these off to get a clean view? I've looked in preferences and customising only seems to extend to choice of columns. Andrea AndreaA@officeformac.com wrote: > I have Outlook at work and you can turn these lines off but I cant > find anywhere to turn these off in Entourage 2008. They weren't the...

Cannot open Excel attachment from e-mail when Excel is already ope
This is driving me crazy. If I already have Excel open (with or with out a spreadsheet open) I cannot open an Excel spreadsheet attached to an e-mail. If I close Excel and retry it will open Excel and the spreadsheet. Any ideas? I hate having to close all my open spreadsheets when I want to open a spreadsheet that's been e-mailed to me! One of these usually works with a similar problem starting workbooks by double clicking them in Windows Explorer. Maybe one will work for you and your email problem. Tools|Options|General|Ignore other applications (uncheck it) --- or --- Close E...

Delete dead mailbox from active directory
We have four exchange servers - two E2K and two E2k3. One of the E2k server just died due to corrupt array control. We had no mailboxes or anything else on that server. One of our administrator must have created one mailbox on that server by mistake and he never realized that until now. server died and we deleted that mailbox from active directory but, when i try to remove the server from system manager i get message saying can't remove because there are mailboxes associated with this information store. Is there any other way i can remove that server from active directory or s...

can't send or receive emails
this just happened this week. I get this message....The connection to the server has failed. Subject 'help', Account: 'mail.comcast.net', Server: 'smtp.comcast.net', Protocol: SMTP, Port: 80, Secure(SSL): No, Socket Error: 10060, Error Number: 0x800CCC0E........your advice to to change smtp port to 25 or 587 or 80 does not work???? Port 80 is definitely wrong for that server; whose advice was that? Comcast wants you to use these email settings: http://www.comcast.com/Customers/FAQ/FaqDetails.ashx?Id=3D2288 Note that the outgoing server now requires port 5...

Content of emails is changing without any reason !
Hallo I changed operating system last week. From Win XP to Win 7. Used to work with Outlook Express at full satisfaction. I could transfer most of my emails automatically with export/import features of Microsoft software. But I suddenly discover 1 very big problem (bug ???) I am used to work with several maps, and hereby go to several levels deep. Such as : Saved mails Companyname Projectname Date of action Department Activity Name of patient Different emails So sometimes maps can go several levels deep. When I check ema...

multiple email identities
HELP! My husband and I share the same computer and we have our email come to our inbox through Microsoft Outlook. However it is merging our accounts- how do we seperate into 2 identities so we each get our own mail! It is so frustrating! Please help! Thanks Kat Outlook does not use Identities - it uses profiles. See this page for more information: http://www.slipstick.com/outlook/share.htm --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After s...

Lost Active Directory for Microsoft CRM 3.0
Hi, We recently had a server failure on our Domain Controller which was unrecoverable and our backups for active directory failed to restore. The CRM database and application are on a seperate server so is fully intact. But we have lost the AD, which means no access. My question is what is the best method if any to recover the CRM system? I was hoping in version 3.0 this is possible as i know 1.2 was a nightmare due to the security descriptors. Am i able to reinstall and attach to existing database and apply CRM customization? Thanks, Pete Pete, You're in luck, this shouldn'...

Outlook receiving zip files
Why is it when I try to send zipped files to my address; it gets returned as service unavailable? Hello Omar, your Exchange dont allow you to send this! Please speak with your Domain Admin "Omar" <anonymous@discussions.microsoft.com> schrieb im Newsbeitrag news:0754E7DA-31DC-4966-9FC1-C290A8D8222C@microsoft.com... > Why is it when I try to send zipped files to my address; it gets returned as service unavailable? Hi Omar, your Provider don�t supportet this part of file! -- Gestern lief noch alles, ich habe nichts gemacht! Bitte in der Newsgroup antworten, damit jeder d...

Starting an Office Program (word, excel) in Outlook to send email
I'm taking an Outlook 2002 class. The latest assignment requires I open a Microsoft app in Outlook to send an email. Troubleshooting so far: Have tried to install some addl features from CD, restarted the pc (O/S WINXP) but still get error "Cannot complete action". Get no reason why Outlook cannot perform this action and the HELP hasn't only points me to inserting an object or some variation thereof. My Outlook is configured to use with AOL 9.0. Steps (abbreviated) given in textbook to perform: Actions New mail using Microsoft Office Also tried to perform from Wo...

Re: teach me how to send friends email
<jim.cooke@cox.net> wrote in message news:... > how do i send email? ...

Here is fix for Windows file problems
If you have installed a Windows update and started having problems opening, closing, copying files, see: http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.excel.misc&mid=1fe358b1-c8eb-4217-ad2a-4b9fcf741916 A better solution is offered at http://support.microsoft.com/kb/918165 "Problems in Windows Explorer or the Windows shell after you install security update MS06-015". Patricia Shannon wrote: > If you have installed a Windows update and started having problems opening, > closing, copying files, see: > > http://ww...

Importing AOL Email File Cabinet
Is it possible to tranfer a complete AOL Email File Cabinet into outlook? AFAIK, no, but see if anything here will do it: http://www.slipstick.com/config/convmsg.htm - check out Address Magic Plus first, it can convert almost anything. -- Diane Poremsky [MVP - Outlook] Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM Outlook Tips: http:/...

no access to send internet email
Hi, Exchange 2003. Can a mail enabled user be restricted to send internal email only and not internet email? Nich Hello, > Exchange 2003. Can a mail enabled user be restricted to send internal email > only and not internet email? yes, that is possible. There are multiple ways to archive this goal. Depents on your infrastructure,too. If you have mailing to external over an SMTP Connector, try this: First look into your SMTP Connector, you will find Delivery Restrictions there. It is self explaining. If you have trouble with that or you won't find it, then i will need additi...

unable to read file #7
Does anyone know how to solve this error? This is the second time I have had the same error on the same file. Last time I was able to recover from a saved copy and updated fine. This time whenI opened the copy and updated it, then saved it, I got the same error when I tried to open it again, Now I don't have a good copy. I have downloaded all avaliable updates and tried running "Excel.exe /regserver>ok" This did not help. I also ran defran on the drive. "Randell" wrote > Does anyone know how to solve this error? This is the > second time I have had th...

delays in recieving outside emails
For whatever reasons that I can not find, our Exchange 2003 server has started experiencing longs delays in recieving emails. At this time, outgoing emails to not seem to be affected. Checked internal and external DNS, contacted ISP, looked at all the usual suspects but still cannot find out what would causing these delays. Any pointers in a new direction would be helpful Please share what evidence of said delays you have. In particular, please look at the Internet headers of one of these delayed messages and share what you find. -- Ed Crowley MVP - Exchange "Protecting the w...

Email Statements from Collection Module
When I attempt to email statements from the Collection Module I am getting an error message, ' Wrong number of arguments to 'RM_Statements_Update_Header' ...

Exporting contacts in a csv file
I am a mysterious problem exporting my contacts as csv file. The resulting file has only 58 contacts out of almost 1200 contacts in my outlook. These contacts appear to be the last 58 contacts added. (I say appear because the attribute "createdon" is not exported so I can't be exact. Why is this? cinnamngrl <cinnamngrl@gmail.com> wrote: > I am a mysterious problem exporting my contacts as csv file. The > resulting file has only 58 contacts out of almost 1200 contacts in my > outlook. These contacts appear to be the last 58 contacts added. (I > say appea...

a few basic question about resource files
Hi, I have an application that uses resource files to contain the string values for each language. I have created the required resource files in my project, but I don't speak the languages I wish to have resources for. What I would like to do, is somehow allow the end user to edit the resource file themselves so they can set the string values as needed. Is there a way to edit the resource files that ship with my application and get installed ? or Is there a way to have external resource files (not embedded into my application) that can be updated/replaced with o...

Publisher can not save file
I recently started having troubles with my Publisher 2003. Whenever I go to save my files now, using save as or just the save button, it gives me a dialog box that says "Can not save file." It does that twice, then it disappears. I also noticed that when it does this, it leaves the .tmp files in the directory where I tried to save. I can change the name of the files, and sometimes it will save it. Most of the time not though. I have NAV, and I noticed that it was said there was an issue with Publisher and NAV. Is this the same with the 2005 version, and is this anything anyone...

SBS 2003 moving of users files
I run SBS 2003 and due to the amount of data on the users drive it has become chokers and have installed a new 1tb drive to keep up with demand for space. I need to move all the data to the new drive but unsure of the process. Is there an easy way of doing this? As it needs to be done asap Thanks -- JimmyJames ------------------------------------------------------------------------ JimmyJames's Profile: http://forums.techarena.in/members/255792.htm View this thread: http://forums.techarena.in/small-business-server/1357051.htm http://forums.techarena.in You c...