473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mapi Fails on MapiSession.Outbox.Messages.Add

I am wirting an application in Access 2002 (XP) that needs to send email.
Since I hate the dialog boxes you get from all the Outlook warning messages,
I am trying to use the MAPI object. On *SOME* PC's the code runs fine, but
on others, the code can execute the logon portion of the code just fine, but
when it tries to create a message, I get the following error codes:

-2147221219, which when I look it up is MAPI_E_FAILONEPROVIDER. I can not
determine what the issue is.

The PCs have mixed OSs ranging from 98 to XP and various Access environment
ranging from none to XP. (I distribute code using Office Developer XP) I
have tested on my XP machine with Access XP installed and it works fine. I
have not found a pattern to the other PCs that don't work.

My code is below with the problem line marked with a '==>' in the l;eft
margin. The gstrMailProfile is a global variable that stores a profile
name. I have tested this by logging in without any profgile and having the
user pick a profile from the Outlook box.

I don't know what the error denotes or what the cause may be. Any
suggestion would be most helpfull! Thanks in advance.

-Graham

Public Function SendMAPIMessage() As Integer

SendMAPIMessage = 0

Dim MapiSession As Object
Dim MapiMessage As Object
Dim MapiRecipient As Object
Dim MapiAttachment As Object
Dim Recpt
Dim errObj As Long
Dim errMsg
Dim i As Integer
Dim iPosSemiColon As Integer
Dim sCurrentRecipient As String
Dim sTo As String
Dim sCC As String
Dim sBCC As String
Dim sSubject As String
Dim sBody As String
Dim sAttach As String

sTo = gstrMailTo
sCC = gstrMailCC
sBCC = gstrMailBCC
sSubject = gstrMailSubject
sBody = gstrMailBody
sAttach = gstrMailAttach

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:=Nz(gstrMailProfile, "")

' 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

While sTo <> ""
iPosSemiColon = InStr(1, sTo, ";")

If iPosSemiColon > 0 Then
sCurrentRecipient = Left(sTo, iPosSemiColon - 1)
sTo = Mid(sTo, iPosSemiColon + 1)
Else
sCurrentRecipient = sTo
sTo = ""
End If

Set MapiRecipient = MapiMessage.Recipients.Add
MapiRecipient.Name = sCurrentRecipient
MapiRecipient.Type = 1
'mapiTo = 1
'mapiCC = 2
'mapiBCC = 3
Wend

While sCC <> ""
iPosSemiColon = InStr(1, sCC, ";")

If iPosSemiColon > 0 Then
sCurrentRecipient = Left(sCC, iPosSemiColon - 1)
sCC = Mid(sCC, iPosSemiColon + 1)
Else
sCurrentRecipient = sCC
sCC = ""
End If

Set MapiRecipient = MapiMessage.Recipients.Add
MapiRecipient.Name = sCurrentRecipient
MapiRecipient.Type = 2
'mapiTo = 1
'mapiCC = 2
'mapiBCC = 3
Wend

While sBCC <> ""
iPosSemiColon = InStr(1, sBCC, ";")

If iPosSemiColon > 0 Then
sCurrentRecipient = Left(sBCC, iPosSemiColon - 1)
sBCC = Mid(sBCC, iPosSemiColon + 1)
Else
sCurrentRecipient = sBCC
sBCC = ""
End If

Set MapiRecipient = MapiMessage.Recipients.Add
MapiRecipient.Name = sCurrentRecipient
MapiRecipient.Type = 3
'mapiTo = 1
'mapiCC = 2
'mapiBCC = 3
Wend
' Resolve each recipient's e-mail name.
' Starting with Outlook version 8.03 (ref. Q172623)
' OLE Messaging 1.0 was replaced with Active Messaging 1.1.
' Outlook 98 (version 8.5) replaced Active Messaging
' with Microsoft CDO (Collaborative Data Objects) 1.21.
' OLE Messaging 1.0 uses a zero-based Recipients collection;
' Active Messaging 1.1 and Microsoft CDO 1.21 are 1-based.
For Recpt = 1 To .Recipients.Count
.Recipients(Recpt).Resolve showdialog:=False
Next

If sAttach <> "" Then
'Attach a file to the message.
'If FileExist(sFile) Then
Set MapiAttachment = MapiMessage.Attachments.Add
With MapiAttachment
.Name = Mid(sAttach, (InStrRev(sAttach, "\")) + 1)
'.Type = mapiFileData
'.Source = logfile
'.ReadFromFile filename:=logfile
.Source = sAttach
.ReadFromFile FileName:=sAttach
.Position = 2880
End With
'End If
End If
' Assign the text, subject, and importance of the message.
.Subject = sSubject
.Text = sBody & vbCrLf & vbCrLf

' 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.

'Set showdialog to False to send automatically.
'Set showdialog to true to display msg prior to sending.
.Send showdialog:=False

End With
MapiSession.Logoff
Set MapiSession = Nothing ' Clear the object variable.

SendMAPIMessage = 1 'Success

MAPIExit:
Exit Function

MAPITrap:
errObj = Err - vbObjectError ' Strip out the OLE automation error.
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 Function
Nov 12 '05 #1
0 3453

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Chris | last post by:
I'm trying to send an e-mail through outlook. So far I've gotten it to work with the mail script at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461 My only problem is that when I...
2
by: Adam Kinney | last post by:
I have an ASP application that logs into Exchange server to send email. The code looks like this: Set objSession = CreateObject("MAPI.Session") objSession.Logon "profileName" strMsg = ".."...
0
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after...
1
by: Bob Beed | last post by:
I want to be able to respond to a received email by sending 7 emails. This is not possible using Outlook express message rules I am therefore trying to use VB 6 MAPI. I have managed to get it to...
0
by: Kevin Quigley | last post by:
Hi, I have a web page that will send emails to various addresses, I've tried using the SmtpMail class but no matter what I try it will not work. I have an asp page that does actually work...
4
by: cj | last post by:
My application, brx729, creates a new MAPI email message and leaves it on the screen for the user to send. On one pc when it creates the email if you cancel the message my program throws the error...
3
by: sentiboy | last post by:
I am using the following code for sending email through mapi in VS 2005 environment: Public objSession As New MSMAPI.MAPISession Public objMessage As New MSMAPI.MAPIMessages ...
1
by: bobh | last post by:
Hi All, I've been using this function which I got from here for some time now in two of my AccessXP multiusers applications and it has worked without issue until lately it has stopped functioning...
1
by: cmahale | last post by:
Hi, I'm creating the vb application using MAPI control. I've added both controls in my vb program (MapiSession & Mapimessages). Please check my below code. Private Sub Form_Load() 'Sign...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.