Link to home
Start Free TrialLog in
Avatar of Dale Fye
Dale FyeFlag for United States of America

asked on

Sending Attachment via CDO

I've got an Access database which a client wants to automate and send email messages along with attachments.  I'm using the Windows Task Scheduler to open the Access database, perform the internal operations and generate the reports, all of which is working.  Then after the files are created and the Access application is closed, the script continues and is supposed to send an email, with attachments,  to a group of recipients.  The code I'm running looks like:
Set Msg = CreateObject("CDO.Message")

If Err.Number <> 0 Then
    Exit function 
End If

With Msg	
    .From = strAddrFrom
    .To = strAddrTo
    .Subject  = "Daily production reports for: " & strdate 
    .TextBody = "Attached files are the production reports for " & strdate 
    for intloop = 0 to 4
        'The File function returns true if the file exists
        if file(strdatabasepath & "\" & Replace(strfiles(intLoop), " ", "_")) then
		.AddAttachment strdatabasepath & "\" & Replace(strfiles(intLoop), " ", "_")
	end if
    next 
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSTIMailSrvr
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sSTIMailPort
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = sSTISendUsingSMTP
    .Configuration.Fields.Update
    .Send
End With 

Open in new window

When I run this, either with or without the loop, it sends the email but without attachments.

I've found a couple of messages here on EE which imply that the files being uploaded to CDO have to reside on the the "server".  I'm assuming that means the email server, but the files are currently created on the users PC.

How do I go about loading these files to the server, or is there something else that I'm missing WRT sending the files via CDO?

Dale
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dale Fye

ASKER

Thanks for the suggestions guys.  Both recommendations caused me to go back and look at the names being given to the reports in the OutputTo method, and the values in the file array, strfiles(intLoop).  Unfortuantely, at some point the file names in the OutputTo method got changed and I didn't make the appropriate changes in the strFile( ) array.

After changing the values in the array, everything worked fine.