using MAPI to email from VB

Posted on 2002-05-16
Last Modified: 2010-05-18
I have a form showing contact data for clients and an email button to open the default MAPI client ready to fill in a message to the address shown on the form. The code behind the button is

Private Sub cmdemail_Click()
 cmdemail.Enabled = False
 MAPISess.Action = 1
    MapiMess.SessionID = MAPISess.SessionID
MapiMess.RecipAddress = email.Text
MapiMess.Send (True)
End Sub

On a machine using Outlook Express as the email client everything works well clicking on the button opens Outlook Express  with the recipients address filled in ans the email can be sent.

When the program is run on a PC running Outlook 2000
The code halts at 'MapiMess.Send (True)'

and I get the error message 'runtime error 32002 Unspecified failure has occured'

Anybody seen this before and know of a work around.

I need the function to work in both Outlook and outlook express.



I get the Message
Question by:Aerocom
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 70

Expert Comment

by:Éric Moreau
ID: 7013798
better use this free component to send mail:

Accepted Solution

Glowman earned 100 total points
ID: 7013871
I had the exact same problem using the MAPI controls and I found out that you need to use the "ResolveName" method before each address is added.  So your code would be changed to this :

Private Sub cmdemail_Click()
cmdemail.Enabled = False
MAPISess.Action = 1
   MapiMess.SessionID = MAPISess.SessionID
MapiMess.RecipAddress = email.Text
MapiMess.ResolveName   **~~**(Add this line)
MapiMess.Send (True)
End Sub

By adding that line you should be good to go.


Author Comment

ID: 7013926
Thanks Glowman it did the trick!!

It now works with outlook as well as O express.

I've been trying for days to find out what the error refered to but no luck on MSDN. Prooves that Experts Exchange is the place to go for those solutions that MS cannot or will not provide!!

Now I have to find out if it will work with Lotus Notes which a couple of my clients use.

Thanks again


Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 65
Excel - Save a copy of work book 13 91
Set email body to html using vbscript 6 71
VBA - If Bookmark = "XXBOOKMARKXX" then 15 51
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question