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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send email attachment by date

Status
Not open for further replies.

mhowell1

MIS
Jan 21, 2011
2
US
I'm new to vbscript and need help sending an attachment by date via email. Im not using outlook and can already send an email with an attachment. I use the code below to send the attachment.

message.addattachment "d:\program files\reports\test.txt"
.From = "mike@domain.com"

However, the filename will change each day and I need to send the email each day. So, I guess I need to be able to attach a file based on date. So, if there is a new file in the directory today I would attach that file. Not sure how to do this though.
 
mhowell1:
You can use the file system object to get the last modified date of the file:
Code:
Dim sFile, dteFileLastMod
sFile = "d:\program files\reports\test.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
dteFileLastMod = f.DateLastModified

And then use the DateDiff function to compare that date with the current date/time. (Below is just a rough idea of how it works)
Code:
If DateDiff("d",dteFileLastMod, Now()) > 1 Then
   ... send email ...
End if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top