Attaching directory contents to email - Report Snapshots and other attachments

  • Thread starter Thread starter Silvester
  • Start date Start date
S

Silvester

Hi,

I have a directory where I have access report snapshots saved as well as
other files like pdfs and powerpoint.

I would like to be able to automate and attach all files/reports within a
given directory to a single email.

A simple docmd.sendobject will not work as I cannot attach other attachment
formats besides access reports.

I would prefer NOT to use outlook, preferably Outlook Express or simple mapi
clients.

Has anyone had success in doing this or can you point me to a source of
knowledge on this.

Thanks
 
If you clients are running Win2K or better then I recommend you look at Msft
CDO. Comes installed with the OS so there should be no install issues, and
because you can use late binding there are no missing references issues
either.

I have posted some sample code the demonstrates how to assemble an email
with attachments here http://www.worksrite.com/CDOMail.htm. I am using a
this code in several applications, and have not had a bit of trouble in
almost 2 years. You should have no trouble adapting this example to your
requirements.

Good luck with your project.
 
Thanks Ron,

I get the error "The transport failed to connect to the server" when I run
this code...

What basic references are essential to be set to get this to run. Perhaps I
have missed one.

TIA
 
Typically that error means that CDO could not find or authenticate to a SMTP
server to send the mail. Have you changed the settings for "smtpserver",
"sendusername", and "sendpassword"? Try using the settings that your email
client uses to connect to its server.
 
Hmmm. Our office setup is OE clients typically 192.168.0.1 running through a
proxy server. Is there any way to automatically configure these settings so
that end users won't have to figure this out ?

Thanks !
 
The way I have handled it in the past was to create one email account that
everyone would use. Then set the smtpserver to the name or IP address of a
SMTP mail server that will forward mail for that account, and you are good
to go.
 
Here's a code alternative for multiple attachments that I've got working if
anyone else is interested.
Invoke by using:

Call SendMailWithOE("Subject", "BODY", "(e-mail address removed)", "full path and
..format to attachment1" & "," & "full path and .format to attachment2")

_______________________________________________________________________
Option Compare Database
Option Explicit


Private Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As Long
End Type
Private Type MAPIFileDesc
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As Long
End Type
Private Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Originator As Long
Flags As Long
RecipCount As Long
Recipients As Long
FileCount As Long
Files As Long
End Type
Private Declare Function MAPISendMail _
Lib "C:\Program Files\Outlook Express\msoe.dll" ( _
ByVal Session As Long, _
ByVal UIParam As Long, _
Message As MAPIMessage, _
ByVal Flags As Long, _
ByVal Reserved As Long) As Long
Sub SendMailWithOE(ByVal vSubject As String, _
ByVal vMessage As String, _
ByRef vRecipients As String, _
Optional ByVal vFiles As String)
Dim aFiles() As String
Dim aRecips() As String
Dim FilePaths() As MAPIFileDesc
Dim Recips() As MapiRecip
Dim Message As MAPIMessage
Dim z As Long
aFiles = Split(vFiles, ",")
ReDim FilePaths(LBound(aFiles) To UBound(aFiles))
For z = LBound(aFiles) To UBound(aFiles)
With FilePaths(z)
..Position = -1
..PathName = StrConv(aFiles(z), vbFromUnicode)
End With
Next z
aRecips = Split(vRecipients, ",")
ReDim Recips(LBound(aRecips) To UBound(aRecips))
For z = LBound(aRecips) To UBound(aRecips)
With Recips(z)
..RecipClass = 1
If InStr(aRecips(z), "@") <> 0 Then
..Address = StrConv(aRecips(z), vbFromUnicode)
Else
..Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
With Message
..FileCount = UBound(FilePaths) - LBound(FilePaths) + 1
..Files = VarPtr(FilePaths(LBound(FilePaths)))
..NoteText = vMessage
..RecipCount = UBound(Recips) - LBound(Recips) + 1
..Recipients = VarPtr(Recips(LBound(Recips)))
..Subject = vSubject
End With
MAPISendMail 0, 0, Message, 0, 0
End Sub




Sub sendOEEMail()

'Error-handler inserted on 10/26/2005 '

On Error GoTo sendOEEMail_Error

Call SendMailWithOE("Subject", "BODY", "(e-mail address removed)", "full path and
..format to attachment1" & "," & "full path and .format to attachment2")


sendOEEMail_Exit:
SetDefaultPrinter (currPrinter)
Exit Sub

sendOEEMail_Error:

Select Case Err.Number

Case Else
MsgBox "Error - " & Err.Number & vbCrLf & vbCrLf & Error$, vbExclamation,
GetAppName()

End Select

Resume sendOEEMail_Exit

End Sub
 
Back
Top