By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Help with Mapi emailing

P: n/a
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 debug mode it errors on the very first line of
code - Set MapiSession = CreateObject("Mapi.Session")
it display an error number 2147221934 which I could not find in
looking thru the Mapi error messages.

Anyone know what might be happening???
thanks
bobh.
Public Function SendMAPIMessage(strSubj As String, strMesTxt As
String, strAttchFile As String, strFrom As String)
On Error GoTo MAPITrap

' This procedure sets an object variable to the MAPI Session Object
' using the CreateObject() function. Then, it logs on to the session
' using a predefined profile. Once logged on, the procedure creates
' a new message and adds it to the Messages collection of the User 's
' OutBox. Then, it creates two recipients (one on the TO: line and
' one on the CC: line) and adds both to the Recipients collection
' of the message. Next, it resolves the names of all recipients.
' Then, it attaches a sample file before filling in the Subject,
' Text, and Importance attributes of the message.
'--------------------------------------------------------------------
Const mapiNormal = 3
Const mapiHigh = 2

Dim MapiSession As Object, MapiMessage As Object
Dim MapiRecipient As Object, MapiAttachment As Object
Dim errObj As Long
Dim errMsg
' 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:="Novell Default Settings"

' 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
'Set MapiRecipient = MapiMessage.Recipients.Add
'MapiRecipient.Name = "so******@company.com"

'Set MapiRecipient = MapiMessage.Recipients.Add
'MapiRecipient.Name = "so*****@here.com"

'Attach a file to the message.
Set MapiAttachment = MapiMessage.Attachments.Add
With MapiAttachment
.Name = strAttchFile
.Position = 2880
.Type = 1
.ReadFromFile FileName:=strFrom
End With

'Assign the text, subject, and importance of the message.
.Subject = strSubj
.Text = strMesTxt
.Importance = mapiHigh

'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.
.Send showdialog:=True

End With

Set MapiSession = Nothing ' Clear the object variable.

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

May 10 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 10 May 2007 12:47:44 -0700, bobh <vu******@isp.comwrote:

I sometimes get errors on that line if CDO is not installed:
http://support.microsoft.com/default...b;en-us;171440

-Tom.
>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 debug mode it errors on the very first line of
code - Set MapiSession = CreateObject("Mapi.Session")
it display an error number 2147221934 which I could not find in
looking thru the Mapi error messages.

Anyone know what might be happening???
thanks
bobh.
Public Function SendMAPIMessage(strSubj As String, strMesTxt As
String, strAttchFile As String, strFrom As String)
On Error GoTo MAPITrap

' This procedure sets an object variable to the MAPI Session Object
' using the CreateObject() function. Then, it logs on to the session
' using a predefined profile. Once logged on, the procedure creates
' a new message and adds it to the Messages collection of the User 's
' OutBox. Then, it creates two recipients (one on the TO: line and
' one on the CC: line) and adds both to the Recipients collection
' of the message. Next, it resolves the names of all recipients.
' Then, it attaches a sample file before filling in the Subject,
' Text, and Importance attributes of the message.
'--------------------------------------------------------------------
Const mapiNormal = 3
Const mapiHigh = 2

Dim MapiSession As Object, MapiMessage As Object
Dim MapiRecipient As Object, MapiAttachment As Object
Dim errObj As Long
Dim errMsg
' Create the MAPI Session.
Set MapiSession = CreateObject("Mapi.Session")
<clip>

May 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.