Geeks With Blogs

News View Steve Michelotti's profile on LinkedIn


Mark Pearl

 

So, a morning of bashing my head an a new found appreciation for .Net…

Today I had to do some legacy app programming in vb6…

The issue we were trying to resolve was that we had an application sending emails via the MAPIMessages library. Everything worked fine in Windows XP, but if the user ran the same program in Windows 7 you would get a Runtime error ‘32002’.

After a fair amount of searching on the internet I got several conflicting reasons as to why this was “crashing”. To save those other poor soles that may come across this problem I have pasted a working vb6 solution that works in Windows 7 below…

Public Function TestEmail(ByRef MAPIMessages As MAPIMessages, ByRef MAPISession As MAPISession)
        Let MAPISession.DownLoadMail = False
        '---------------------------------------------------
        'Sign on Session
        '---------------------------------------------------
        If (MAPISession.SessionID = 0) Then
            Call MAPISession.SignOn
        End If

        With MAPIMessages
            .SessionID = MAPISession.SessionID
            .Compose
            .AddressResolveUI = False

            .MsgSubject = "This is a subject."
            .MsgNoteText = "This is a body."

            .RecipIndex = 0
            .RecipType = 1
            .RecipAddress = "smtp: youremail@gmail.com"
            .RecipDisplayName = "smtp: youremail@gmail.com"
        

            .Send False
        End With
End Function

Now there are a few gotchas that you have to be careful about…

You need to set the RecipDisplayName correctly, if you do not, even if the RecipAddress is correct it will return an error.

You also need to turn the AddressResolveUI to false…

Provided you have those two things done… it should work fine…

Good luck!

Posted on Tuesday, May 31, 2011 12:48 PM VB6 | Back to top


Comments on this post: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Thank You very much on this... I have been looking for this solution for ages.
I had this working fine for Thunderbird.. but Outlook is another problem.

Thank You!!!
Left by Mike Neary on Oct 11, 2011 7:40 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Great to hear this was useful for someone.
Left by Mark Pearl on Oct 11, 2011 9:01 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Thanks for posting, ran into the same error and I added 3 things:
.RecipIndex = 0
.RecipType = 1
.RecipDisplayName = "smtp: youremail@gmail.com"
Left by Pete on Dec 15, 2011 11:31 PM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Hi there,
I have been testing similar code fragments for a few days now. I'm not getting an error but Calling MAPISession1.SignOn isn't setting SessionID (it is always 0) and so on .Compose I get error 32053 "MAPI Failure: Valid session ID does not exist". I was hoping someone could point me toward a solution.

I have been using CDO and just using my own light email from but now more customers want application output sent to their desktop email client. I'm just trying to emulate shell sendto mail from windows explorer. I didn't think the method for doing this would be top secret.

Thank you,
Ron
Left by Ron on Mar 01, 2012 8:33 PM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Hi,

I have got the same error but I have attachment. How to handle attachment with MAPI?

I'd appreciate if someone could answer me. Thanks!
Left by Yoyo on Apr 17, 2012 9:58 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Mark, you have saved me from going completely bald! I don't know which of your caveats did it, but it works, and that's all I care about. THANK YOU!
Left by Bill Hileman on Jan 07, 2013 3:32 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Hi Mark,
I'm using Windows 8 (64) and Outlook 2010, and it is not working.
It starts an old version of Outlook (2000), I don't know why.
And then nothing happens...
I'd appreciate if you could answer me.
Thank you!
Left by Sayeg on Apr 25, 2013 3:23 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
Hi,

It really works!
But if I have an attachment, I get the same error, like Yoyo.
How to handle attachment?

I'd appreciate if someone could answer me.
Thanks!
Left by Sayeg on Apr 25, 2013 4:04 PM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
How to handle multiple attachments as i am able to send 1 attachment but it gives the same error in case of multiple attachments. Did some tries from forums but in vain. Here's the code

MAPISession1.SignOn

With MAPIMessages1
.SessionID = MAPISession1.SessionID
'Start by telling the control that we are composing an e-mail
.Compose
'Use whatever is in the Textboxes as the information for our e-mail.
.RecipIndex = 0
.RecipType = 1
.RecipDisplayName = "smtp: abc@hotmail.com"
.RecipDisplayName = "smtp: abc@hotmail.com"

.MsgSubject = "MAPI subject with attachments"
.MsgNoteText = "This is atest"




.AttachmentIndex = .AttachmentCount
.AttachmentType = mapData
.AttachmentPosition = 0
.AttachmentPathName = "C:\test.csv"
.AttachmentName = "test.csv"

.AttachmentIndex = .AttachmentCount
.AttachmentType = mapData
.AttachmentPosition = 0
.AttachmentPathName = "E:\holidays_2013.xls"
.AttachmentName = "holidays_2013.csv"
.ResolveName
'Send the e-mail message to the Recipient
.Send
End With
Left by abbid on Apr 29, 2013 3:56 AM

# re: Sending emails with VB6 & MAPIMessages returns Unspecified Failure has Occurred (Runtime error ‘32002’:)
Requesting Gravatar...
This worked for me! Awesome!
Left by Zipper on May 16, 2014 7:29 AM

Your comment:
 (will show your gravatar)


Copyright © MarkPearl | Powered by: GeeksWithBlogs.net | Join free