EMail a file out of an Access Application

Hello!

I've posted this question some days ago, but no really satisfactory answer reached me. browdog nearly answerd my question, but not entirely.

Here is my problem:

I simply want to send a file (e.g. teris.exe) out of my access application. I need a code (or something else), where I can specify:

1. The deliverer
2. The topic
3. The file(s) and maybe some additional text
 Just as in any ordinary Mail.

So, I offer 100 Points for a complete answer. (I use Access 97)

Thanks in advance
casexpertAsked:
Who is Participating?
 
HelicopterCommented:
Thanks, I'm glad it works.
0
 
casexpertAuthor Commented:
Edited text of question
0
 
susannahbondCommented:
If the file you want to send is in the format .xls .rtf .txt
why don't you use SendObject, this will open mail add a file and add further text etc.

This is a sample of one I have used.....
 DoCmd SendObject A_REPORT, "AntennaStatusXLStagOrder", A_FORMATXLS, , , , "Analysis Request No. " & forms![site]![analysissub].form![ID] & ", data", "Please find attached a spreadsheet with the relevant antenna information for " & [SITeNAME] & ", site No. " & [Code]

I guess I may be missing the point, teris.exe is a program, do you want to send data or an external file?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
casexpertAuthor Commented:
Oh, susannahbond

If you would have read the question, you would have recognized, that my example is the file Tetris.exe. And as far as I'm informed, this is not a Access Report or Form or Table or something else. I know the SendObject Function, but this is not what I'm searching for
0
 
susannahbondCommented:
"Don't you cry for me"
0
 
josladCommented:
I did something like this recently.  Are you using Outlook98?

joslad
0
 
josladCommented:
Couple of other things I should have asked too.

Is the email address of the destination recipient stored in a field in the database.  Also, is the topic stored in a field.
0
 
casexpertAuthor Commented:
No, joslad

Just Microsoft Exchange
0
 
casexpertAuthor Commented:
To joslad:

If it is important to store the informations in data fields, it would be no problem
0
 
casexpertAuthor Commented:
Adjusted points to 150
0
 
HelicopterCommented:
Have you looked at MSDN Q153311 ?

I had a go with an attachment and the best I have got so far is that it waits in exchange in the outbox, but doesn't do the final delivery.

It also cocked up a dll and froze the computer several times (though not when I sent a message without an attachment)

Anyway it's worth having a look at, you might be able to work something out from it.
0
 
josladCommented:
The solution I had which does what you wanted, actually uses outlook98.  So, sorry cant help.


0
 
HelicopterCommented:
casexpert:this is the solution Microsoft offers. It is almost identical to the MSDN article I referred to. Remember to change the names of recipients and your profile name.




Using Automation to Send a Microsoft MAPI Message

There are five main steps in sending a MAPI message through Automation:


·      Initializing and logging onto the MAPI session
·      Creating a new message and adding it to the Outbox
·      Adding the recipients (To, CC, and BCC) and resolve names
·      Setting valid properties, such as text, subject, and importance
·      Sending the message



   '-------------------------------------------------------------------
   ' This procedure sets an object variable to the MAPI Session object
   ' using the CreateObject() function. Then, it logs on to the session
   ' using a predefined profile. Once logged on, the procedure creates
   ' a new message and adds it to the Messages collection of the user's
   ' OutBox. Then, it creates two recipients (one on the TO: line and
   ' one on the CC: line) and adds both to the Recipients collection

   ' of the message. Next, it resolves the names of all recipients.
   ' Then, it attaches a sample file before filling in the Subject,
   ' Text, and Importance attributes of the message.
   '-------------------------------------------------------------------
    Sub SendMAPIMessage()
        Dim MapiSession As Object
        Dim MapiMessage As Object
        Dim MapiRecipient As Object
        Dim MapiAttachment As Object

        Dim Recpt
        Dim errObj As Long
        Dim errMsg

        On Error GoTo MAPITrap
        ' Create the MAPI Session.
        Set MapiSession = CreateObject("Mapi.Session")

        ' Log on to the session. If the ProfileName argument is
        ' omitted, Microsoft Exchange prompts you for the profile to
        ' use. If the profile name is incorrect, you will receive a
        ' runtime error.


         MapiSession.Logon profilename:="Steven Buchanan"

        ' Add a message to the Outbox.
        Set MapiMessage = MapiSession.Outbox.Messages.Add

        ' Add the recipients of the message. Note, each recipient must
        ' be added separately to the Recipients collection of the
        ' Message object.

        With MapiMessage
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Nancy Davolio"

            MapiRecipient.Type = mapiTo
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Andrew Fuller"
            MapiRecipient.Type = mapiCc
            Set MapiRecipient = MapiMessage.Recipients.Add
            MapiRecipient.Name = "Michael Suyama"
            MapiRecipient.Type = mapiBcc

            ' Resolve each recipient's e-mail name.
            For Recpt = 0 To .Recipients.Count - 1

                .Recipients(Recpt).Resolve showdialog:=False
            Next

            ' Attach a file to the message.
            Set MapiAttachment = MapiMessage.Attachments.Add
            With MapiAttachment
                .Name = "Customers.txt"
                .Type = mapiFileData
                .Source = "C:\Examples\Customers.txt"
                .ReadFromFile filename:="C:\Examples\Customers.txt"
                .position = 2880

            End With

            ' Assign the text, subject, and importance of the message.
            .subject = "My Subject"
            .Text = "This is the text of my message." & vbCrLf & vbCrLf
            .importance = mapiHigh

            ' View the message in Microsoft Exchange before sending.
            ' Set the ShowDialog argument to False if you want to send
            ' the message without viewing it in Microsoft Exchange.


            .Send showdialog:=True
        End With
        Set MapiSession = Nothing  ' Clear the object variable.

    MAPIExit:
        Exit Sub

    MAPITrap:
        ' Strip out the OLE automation error.
        errObj = Err - vbObjectError

        Select Case errObj
            Case 275       ' User cancelled sending of message.
                Resume MAPIExit
            Case Else

                errMsg = MsgBox("Error " & errObj & " was returned.")
                Resume MAPIExit
            End Select
    End Sub



0
 
HelicopterCommented:
Me again. This bit is useful too:

Microsoft OLE Messaging

The Microsoft OLE Messaging server works with MAPI. It allows you to send, receive and process electronic mail, including faxes. This server does not support early binding so you must use late binding.  MAPI can become challenging because you may find two mail servers available on your PC: the “Mapi.Session” server described herein and the “MSMAPI.MAPISession” that is part of  MSMAPI.OCX. You can call CreateObject successfully with “MSMAPI.MAPISession” but this instance is very different from a OLE Messaging instance.

For Office 97 users, you should consider automating Microsoft Outlook  for your electronic messaging needs.  The object model is much simpler and documented much better than the OLE Messaging 1.0 library.

NOTE: The following examples require the Microsoft OLE Messaging 1.0 Object Library(mdisp32.tlb) in order to work. It is not provided with the Microsoft Exchange component which ships with Windows 95. You must purchase Microsoft Exchange separately to obtain this object library.

(mdisp32.tlb should be in your system folder, you need to make a reference to it from access)
0
 
casexpertAuthor Commented:
Thank you for your answer, helicopter,

but as I tryed the code the following Error occured:

Error 196695 was returned

The Error occurs here:

        ' Attach a file to the message.
         Set MapiAttachment = MapiMessage.Attachments.Add
         With MapiAttachment
             .Name = "Langbrit.xls"
             .Type = mapiFileData                      ******  ERROR IN THIS LINE ************
             .Source = "C:\Temp\Langbrit.xls"
             .ReadFromFile filename:="C:\Temp\Langbrit.xls"
             .position = 2880
           
         End With

0
 
HelicopterCommented:
These values range from 1 to 4 (look up mapiattachmenttype in the object browser) Is your error because you haven't made a reference to the OLEmessaging library.

If not, try the other values.
0
 
casexpertAuthor Commented:
Post the answer again. It is great. It works!!! I love it. Yes.




0
 
casexpertAuthor Commented:
One more thing, heli!

Do you know how I can send more than one file ?
0
 
casexpertAuthor Commented:
Oh, heli!

I encountered, that my (always opend) MS Exchange closes, when I use your code.

How can I permit this ?
0
 
HelicopterCommented:
Blimey, I missed my chance there didn't I?

I would guess to add more attachments you would repeat the code:

                 Set MapiAttachment = MapiMessage.Attachments.Add
                  With MapiAttachment
                      .Name = "Customers.txt"
                      .Type = mapiFileData
                      .Source = "C:\Examples\Customers.txt"
                      .ReadFromFile filename:="C:\Examples\Customers.txt"
                      .position = 2880

                  End With

with different values, or maybe put it into a loop with passed parameters.

I don't know why exchange would close. Have you tried experimenting with the line:

 .Send showdialog:=True

by making it false. Otherwise try stepping through the code and seeing where it closes. My guess is it would be at the set obj=nothing line. I'll have a look when I get home tonight as I don't have exchange here at work.


0
 
casexpertAuthor Commented:
No, heli, it's ok. The obj=nothing line is the cause.

Post me something as answer so I can credit you the points
0
 
casexpertAuthor Commented:
Maybe you could tell me a solution for another problem:

How can I indicate, that I receive a special type of Mail and automatically save the Attachment file of this Mail in a specified folder

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.