• Send Email with/out attachment (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Send Email with/out attachment (Access 2000)

    Author
    Topic
    #391540

    How can I send an email through Access?
    I understand the docmd.sendobject method, but I do not want to send a form, report, etc.
    I wish to send an email to the address specified in the “cemail” field, with text based on the “E_txt” field and the subject based on the “esub” field.
    As an added benefit to my users, if they check the “e_attach” check box, they can send the attachment specified in the “letter” hypertext field.
    I can’t seem to find any mention of this in the help file – so any help is gratefully welcome!

    Thanks in advance!

    Viewing 2 reply threads
    Author
    Replies
    • #699768

      If you want to send an e-mail without an attachment, you can use

      DoCmd.SendObject ObjectType:=acSendNoObject, To:=Me.cemail, Subject:=esub, MessageText:=E_txt

      If you want to include an attachment, you’ll have to do it completely differently. SendObject doesn’t support attachments other than database objects. If you use Outlook, you can use Automation to control Outlook from Access in VBA to create a new e-mail, add an attachment etc.
      Because of the draconian security measures in Outlook, there are some extra things you have to do to make it work smoothly.
      It is possible, but it takes some work, and requires that you are comfortable with Access and Outlook VBA.

    • #700004

      This is a truncated version of automation code I put together. You will need to Dim all the variables and change the table and field names but it will get you started.

      If I’m trying to automate something in Office I usually find Helen Feddema has already worked out something similar that I can adapt.

      Set appOutlook = CreateObject(“Outlook.Application”)
      Set nms = appOutlook.GetNamespace(“MAPI”)
      Set pfld = nms.GetDefaultFolder(olFolderOutbox)
      Set itms = pfld.Items
      Set rst = CurrentDb.OpenRecordset(“MyEmailTable”)

      With rst
      strAddress = Nz(!Address)
      strSubject = Nz(!Heading)
      strBody = Nz(!Message)
      strLetter = Nz(!Title)
      strAtt = “MyFilename”

      End With
      Set itm = itms.Add(“IPM.Note”)

      With itm
      .Body = strBody & NL & NL & strSign
      .Subject = strSubject
      .To = strAddress
      .Attachments.Add strAtt
      .Send
      End With

      Hope it helps to get you sorted.

      Peter

    • #700008

      Sorry, should probably explain that I use NL instead of Chr(10) for new lines
      Peter

      • #700140

        Thanks Peter and Hans.

        I’m using Outlook Express and although I’ve dimmed the variable as so:

        Dim appOutlook As Object

        I’m getting the following error message:
        “Runtime error 429 ActiveX component can’t create object”
        at the line:

        Set appOutlook = CreateObject(“Outlook.Application”)

        I tried variations such as Outlook Express.Application and even OutlookExpress.Application but all had the same result.
        Any suggestions as to what the problem is?

        Thanks again for your time.

        • #700143

          Outlook Express doesn’t have an exposed object model, so you can’t control it using Automation the way you can control Outlook.

          I don’t know how to do this with Outlook Express; although you can create a command line to send mail from Outlook Express, there is no switch to attach a file as far as I know.

        • #700273

          I assumed you were using Outlook rather than Outlook Express and you know what they say about making assumptions.
          Sorry, can’t help you with OE.
          Peter

          • #700362

            Thanks Hans and Peter for your time, I will work around what you have said.

            • #700632

              Hi, you can use this code to send e-mails using the MAPI reference library. I haven’t tested it with Outlook Express, but it should work. The really nice thing about this code is that you don’t need to know the e-mail software ahead of time (like Outlook) and you don’t have to add any references in the database since it uses late binding.

              The code originally came from Bart (one of the loungers here). I translated some of his comments and added the ability to include attachments (up to two, although it’s easy to add more by editing the code). I couldn’t figure out how to run this new code by him first, so I hope he doesn’t mind my edits or reposting of it (since I also couldn’t find the original post without the search capability).

              The code is in the attached file.

              Brent

            • #939200

              I found this post when searching for a solution. I want to try to programmatically send emails with attachments without using Outlook.

              So I have copies all this code into a new class module, created a form with the required controls and a send button.

              The first time I clicked it complained that I wasn’t using Outlook, but I have not been able to explore that because on every subsequent time it stops at:

              Set clsMAPITest = New clsMAPI

              and when I explore further it is because the initialize method can’t execute this line.

              Set objMySes = CreateObject(“MAPI.Session”)

              I have just done some more testing, and can get it to work by setting Outlook as my default mail client.

              Can anyone tell me if this code should work with any email program, or just Outlook. (The setting where I am looking to use it uses Eudora)

            • #939265

              John,
              You will need vastly different code for an email client such as Lotus Notes. When I distribute an application to my clients which requires their clients to email them, I include a quick dialog box which requires the user to select either Lotus Notes or Outlook as their email client.
              There are some very helpful threads on this here – do a search (as I did originally) and you’ll find what you need.
              Cheers!

            • #939280

              Thanks

              In this case, the client uses Eudora (and is required to use only Eudora, by University policy).

              I have followed various threads on this subject for quite a while, and haven’t been aware of any way to programmatically make attachments (from outside the db) with Eudora. I searched again today, and found this thread, which included the claim that sending messages using MAPI worked without Outlook. It didn’t work for me, but I was hoping someone could give me a clear answer on whether MAPI only works with Outlook.

              I have just found another example of doing it with asp post 219398 which also uses Aspemail. I might be able use that but I am not sure if I can install the dll’s on the PCs.

            • #939202

              You can avoid Outlook entirely using the free email control at http://www.aspemail.com/%5B/url%5D

            • #939208

              Thanks, that looks interesting, but i don’t think I can use it in the current situation.

              My client works for a university and is not going to be allowed to install email dll’s and exe’s on the server.
              (My reading of the documentation says this is needed.)

              I need a solution that works entirely within the individual PC.

              In the post I was trying to use, Brent said that the solution he was posting did not need Outlook, so I hoped it would provide what I want.

            • #939223

              Installation on server is required only if he is doing a server-based application, and wants remote users to send email via the web app. If it is entirely workstation-based, then he would not need to install anything on the server, Of course, he may also be prohibitted from installing stuff on the workstation…

            • #939234

              Thanks

              I will download it and experiment with it and see how it goes.

              Even if I can’t use it for this project, it is worth knowing about for others.

              John

    Viewing 2 reply threads
    Reply To: Send Email with/out attachment (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: