Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Not Sending When Adding File Names to Body of Email

Status
Not open for further replies.

NiceArms

Programmer
May 21, 2009
105
GB
Hello,

I am having an issue with adding file names to the body of an email, when I add the file names which are passed to the body via a variable the email will not send (no error appears), however if I pass some text to the body the email sends.

Does anyone has any thoughts?

Code:
'on error resume next
EmailBody = "This is the start of the body"
Filenames = ""
schema = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/"[/URL]
Set objEmail = CreateObject("CDO.Message")
Set objFSO = CreateObject("Scripting.FileSystemObject")
filelocation = "C:\"
'get all file in folder
Set objFolder = objFSO.GetFolder(filelocation)
Set colFiles = objFolder.Files

'where we have files add to "Filenames"
For Each objFile in colFiles
    if objFile.DateCreated >= dateadd("s",-598,now()) then
		Filenames = Filenames & vbcrlf & objFSO.getfilename(objFile.name)
	end if
Next

'Merge the filenames in with the main text
EmailBody = EmailBody & Filenames [COLOR=#A40000]'if I remove this line the email is sent without issue but when I try to add "filenames" no email is sent and no error is prompted[/color]

'If there are files send an email
if Filenames > "" then
	'populate the email object
	With objEmail
		.From = "test@test.com"
		.To = "test@anothertest.com"
		.Subject = "A subject"
		.textBody = EmailBody

		With .Configuration.Fields
			.Item (schema & "sendusing") = xxx
			.Item (schema & "smtpserver") = "xxx.xxx.xxx.xxx"
			.Item (schema & "smtpserverport") = xxx
		End With
	
		.Configuration.Fields.Update
		.Send
	End With
end if

'Clear down the objects
set objEmail = nothing
set objFSO = nothing	
Set objFolder = nothing	
Set colFiles = nothing

I feel sorry for people who don't drink, when they wake up in the morning that's as good as the're going to feel all day!
 
Probably this:
Code:
if Filenames [highlight #FCE94F][b]<>[/b][/highlight] "" Then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top