MAPI and Outlook 2003

Randal
Posts: 250
Joined: Mon Oct 24, 2005 8:04 pm

Post by Randal »

Customer is using Outlook 2003 w/SP2. He gets a msg prompting him to select a profile, there is only one defined. The email ends up in the outbox but he gets a msg that states- The following recipient(s) could not be reached:

The email address shown is enclosed in ' ', I think this may be why it's not being sent.

Unfortunately, the customer is in another state so it's a little difficult to diagnose. Any other ideas?

Thanks,
Randal Ferguson
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Randal,

Is this a 16bit FW application? If so, I had this problem with all versions of Outlook. The only solution I could come up with was to use an external 32bit FWH app to send the mail (called from the 16bit app).

If it is not a 16bit app, then how are you formatting the email address you are sending to MAPI?

James
Randal
Posts: 250
Joined: Mon Oct 24, 2005 8:04 pm

Post by Randal »

James,

This is a 16-bit app but I'm calling a 32-bit program written in FWH/xHarbour and passing the email address as a command line argument. This works fine with Outlook Express and other mapi programs.

Thanks,
Randal
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Randal,

So, if I understand you correctly, you are calling the MAPI client from a 32bit FWH program? Can we see the code doing the calling?

James
Randal
Posts: 250
Joined: Mon Oct 24, 2005 8:04 pm

Post by Randal »

James,

Here it is:

FUNCTION SendEmail(cToWhom)

Local afiles:={},cSubject,cBody,cFiles
Local path:="\"+curdir()+"\",oMail
LOCAL nRetCode

IF empty(cToWhom)
Msginfo("Invalid Email Address!")
RETURN NIL
ENDIF

if ! Empty(cFiles)
aadd(afiles,{cfiles,""})
endif

* nRetCode := MAPILogOn()

/* IF nRetCode == -1
MsgStop( "Error initializing mail" )
RETURN NIL
ENDIF */

nRetCode = MAPISendMail( , , ,;
DToS( date() ) + " " + time(), ;
, ,.t.,;
, { alltrim( cToWhom )}, )

IF nRetCode == 25
MsgStop("Invalid email address!", "Problem")
ELSEIF nRetCode = 1
* MsgStop("Operation Cancelled!", "Problem")
ELSEIF nRetCode <> 0
MsgStop(nRetCode, "Problem - MAPI Return Code")
ENDIF

MAPILogOff()

return nil
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Randal,

It looks like you have cToWhom as the 8th parameter. I think that if you don't provide a name as the 7th parameter, then you are supposed to put the address in the 7th postion. I am not sure about this, but it is worth a try.

Also below is another method of sending MAPI mail using only xHarbour that was posted by Ron Pinkas some time ago. Perhaps that will work.

James

Code: Select all

From: "Ron Pinkas" <Ron@remove-this.xharbour.com>
Subject: Re: How can I send mail ?
Date: Tuesday, March 23, 2004 11:04 AM

Here is a sample that should work with ANY provider of SimpleMAPI, including
Outlook and Oulook Express, as long as SimpleMAPI is properly configured.

//----------------------------------------------------------//
PROCEDURE Mail()

   LOCAL oSession, oMessage

   TRY
     oSession := CreateObject( "MSMAPI.MAPISession" )
     oSession:SignOn()
   CATCH
     Alert( "SimpleMapi not avilable." )
     BREAK
   END

   TRY
     oMessage := CreateObject( "MSMAPI.MAPIMessages" )
   CATCH
     Alert( "MSMAPI.Messages faild!" )
     BREAK
   END

   WITH OBJECT oMessage
        :SessionID := oSession:SessionID
        :Compose()

        :RecipAddress := "tests@xharbour.org"
        :AddressResolveUI := .T.
        :ResolveName()

        :MsgSubject := "email from xHarbour"
        :MsgNoteText := "Hi Brian, here it is..."

        :AttachmentIndex := 0
        :AttachmentPosition := 0
        :AttachmentPathName := "c:\xharbour\tests\test.prg"

        :Send( .F. ) // .T. Interactive or .F. for automated.
   END

   oSession:SignOff()

RETURN
//----------------------------------------------------------//
Randal
Posts: 250
Joined: Mon Oct 24, 2005 8:04 pm

Post by Randal »

James,

Thanks for the sample code. Is there some procedure to insure SimpleMapi is configured correctly?

According to the tmail source for FWH 2.7 it looks like the recipient should be the 9th parameter, or 8th if no origin name is provided?

::nRetCode = MAPISendMail( ::cSubject, ::cNoteText, ::cMsgType,;
DToS( ::dDate ) + " " + ::cTime,;
::cConversationID, ::lReceipt, ::lFromUser,;
::aOrigin, ::aRecipients, ::aFiles )

Thanks,
Randal
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Randal,

>Is there some procedure to insure SimpleMapi is configured correctly?

That I don't know.

According to the tmail source for FWH 2.7 it looks like the recipient should be the 9th parameter, or 8th if no origin name is provided?

Well, I can program, but I can't count. My mistake. aOrigin is either the name if you also have an address, or it is the address if you don't provide a name.

Let us know if that works.

James
Randal
Posts: 250
Joined: Mon Oct 24, 2005 8:04 pm

Post by Randal »

James,

Making the email address the 9th parameter causes a MAPI Error Code 2.

I compiled the SimpleMAPI sample you posted and I get the error message "SimpleMapi not available".

Thanks,
Randal Ferguson
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Randal,

>Making the email address the 9th parameter causes a MAPI Error Code 2.

It was already in the 9th slot. Did you mean 8th, or did you put it in the 10th by mistake?

>I compiled the SimpleMAPI sample you posted and I get the error message "SimpleMapi not available".

Maybe this will help:
If sending or receiving mail is not the primary function of your application, you can test the presence of simple MAPI in a system without incurring high cost of trying to load a DLL by testing the value of the MAPI variable. It is 1 if simple MAPI is installed. The variable is located in the [mail] section of Win.ini on 16-bit Windows and Windows NT version 3.51 and earlier; it is under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Messaging Subsystem in the registry on Windows 95 and Windows NT 4.0 and later.
Taken from this page:

http://msdn.microsoft.com/library/defau ... lemapi.asp

James
User avatar
VeRCE
Posts: 219
Joined: Fri Nov 04, 2005 2:34 pm
Location: Mexico D.F.
Contact:

Post by VeRCE »

Marco Turco wrote:I found th problem on msn.
It is a bug on Outlook 2003 sp1.
Thanks.
Marco
Where can i download the fix ???
Juan Carlos Salinas Ojeda
México. D.F.
-------------------------------------------------
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Post by Davide »

Marco Turco wrote:I found the problem on msn.
It is a bug on Outlook 2003 sp1.
Marco, I've the same problem with Outlook 2002.
I'm quite sure you've posted the URL which explains the problem, but I can no more find it.

BTW, did you find a solution ?

Hi,
Davide.
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Post by Marco Turco »

Hi Davide,
unfortunately Microsoft released a fix only for exchange server
and not for Outlook.

The only turnaround I found is to send email via OLE if Outlook is installed
otherwise I use the MAPI subset system.

You can make this using this function:

#include "FiveWin.ch"
#include "Mail.ch"

FUNCTION Interactivemessage()
paramet cSubject, cBody, aTo, aFiles, lDirectSend

LOCAL oOutLook,oMailItem,oRecip,oAttach,i

if lDirectSend=NIL
lDirectSend:=.f.
endif

if cSubject=NIL
cSubject:=""
endif
if cBody=NIL
cBody:=""
endif
if aFiles=NIL
aFiles:=array(0,0)
endif

lOffice:=.t.
TRY
oOutLook := CreateObject( "Outlook.Application" )
oMailItem := oOutLook:CreateItem( 0 )
oRecip := oMailItem:Recipients
CATCH
lOffice:=.f.
END

if lOffice
for i:=1 to len(aTo)
oRecip:Add( aTo[i,2] )
next

oMailItem:Subject := cSubject

oMailItem:Body := cBody

if len(aFiles)>0
oAttach := oMailItem:Attachments
for i:=1 to len(aFiles)
oAttach:Add( aFiles[i,1] )
next
endif

if lDirectSend
oMailItem:Send()
else
oMailItem:display(.t.)
endif
else
for i:=1 to len(aTo)
aTo[i,1]:=alltrim(aTo[i,2])
aTo[i,2]:=alltrim(aTo[i,2])
next


oMail:=tMail():New( cSubject,cBody,,,,, .f., .t.,,aTo,aFiles)

ACTIVATE MAIL oMail
retcode:=oMail:nRetCode
endif
return


Best Regards,

MArco
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Post by Davide »

Marco Turco wrote: unfortunately Microsoft released a fix only for exchange server
and not for Outlook.
Could you please post the URL ?
The only turnaround I found is to send email via OLE if Outlook is installed
otherwise I use the MAPI subset system.
Thank you. I'll try it.

Hi, Davide.
Post Reply