MAPI and Outlook 2003
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
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
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
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
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
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
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
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
//----------------------------------------------------------//
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
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
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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
>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
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
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:
http://msdn.microsoft.com/library/defau ... lemapi.asp
James
>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:
Taken from this page: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.
http://msdn.microsoft.com/library/defau ... lemapi.asp
James
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
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
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