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?
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!
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!