473,698 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapi Fails on MapiSession.Out box.Messages.Ad d

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_FAILONEP ROVIDER. 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 sCurrentRecipie nt 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("M api.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.Log on profilename:=Nz (gstrMailProfil e, "")

' Add a message to the Outbox.
==> Set MapiMessage = MapiSession.Out box.Messages.Ad d

' 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
sCurrentRecipie nt = Left(sTo, iPosSemiColon - 1)
sTo = Mid(sTo, iPosSemiColon + 1)
Else
sCurrentRecipie nt = sTo
sTo = ""
End If

Set MapiRecipient = MapiMessage.Rec ipients.Add
MapiRecipient.N ame = sCurrentRecipie nt
MapiRecipient.T ype = 1
'mapiTo = 1
'mapiCC = 2
'mapiBCC = 3
Wend

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

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

Set MapiRecipient = MapiMessage.Rec ipients.Add
MapiRecipient.N ame = sCurrentRecipie nt
MapiRecipient.T ype = 2
'mapiTo = 1
'mapiCC = 2
'mapiBCC = 3
Wend

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

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

Set MapiRecipient = MapiMessage.Rec ipients.Add
MapiRecipient.N ame = sCurrentRecipie nt
MapiRecipient.T ype = 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.Cou nt
.Recipients(Rec pt).Resolve showdialog:=Fal se
Next

If sAttach <> "" Then
'Attach a file to the message.
'If FileExist(sFile ) Then
Set MapiAttachment = MapiMessage.Att achments.Add
With MapiAttachment
.Name = Mid(sAttach, (InStrRev(sAtta ch, "\")) + 1)
'.Type = mapiFileData
'.Source = logfile
'.ReadFromFile filename:=logfi le
.Source = sAttach
.ReadFromFile FileName:=sAtta ch
.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:=Fal se

End With
MapiSession.Log off
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 3464

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

Similar topics

14
4823
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 call Resolve() and Send(), I get confirmation dialogs. I will be sending out quite a few e-mails at a time, and would rather not have the user have to click yes for every single one. Does anyone know a workaround? I know about smtplib, but I...
2
4712
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 = ".." Set objMessage = objSession.Outbox.Messages.Add objMessage.Subject = "Customer Comment" objMessage.Text = strMsg
0
3701
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 days of reading posts and testing, I see it is not - unless I'm missing something? I'm not an email guru. All of my users will be running at least Windows 2000, most on XP sp2. Some of my users will have Outlook, many will be using Outlook...
1
7972
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 work but occasionally 2 or 3 of my reply emails seem to get stuck in the outlook express Outbox. It is almost as if the VB6 is too fast for Outlook Express. I have tried putting a delay into my VB6 routine but with limited success.
0
1430
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 using mapi.session... <% Const cStrServer = "sciehex01" Const cStrMailbox = "weeklyreportuser"
4
4049
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 System.Runtime.InteropServices.COMException (0x800A7D01): User cancelled process at MSMAPI.MAPIMessagesClass.Send(Object vDialog) at brx729.Form1.SndMAPIMail(String subj, String msg) at brx729.Form1.MailMenuItem_Click(Object sender, EventArgs...
3
4693
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 objSession.DownLoadMail = False objSession.UserName = "MyUsername" objSession.Password = "MyPassword" objSession.SignOn()
1
2852
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 on several user pc's and I don't know why. I've asked our PC Services group what they changed on the pc's that this does not work on and they say 'nothing'. Well something has changed cause this did work at one time. When I step thru it in...
1
1756
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 on to the MAPI Session MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Fetch
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7732
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.