Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How receive email? 1

Status
Not open for further replies.

bon011

Programmer
Jun 2, 2002
155
CZ
I am using CDO to send mails.
But now I need to receive mail from one account.
Does anybody have some helpfile or somethink like this?
 
bon011

CDO is mostly used for sending e-mails. You could use the Outlook activex on a form and direct the activex to the Inbox. The accounts a usually set up in the registry.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I have never work with this.

Can You tell me please if I can receive email that contains some files(tables), save this tables on disk and do somethink with tables?

All of this must be done by application itself.

Thanks a lot
 
bon011

Normally e-mails a received in an e-mail program (like outlook or outllok express) by using the send and receive button. So technically no, you cannot receive e-mails in VFP, but you can retreive the attachments of you e-mail messages. Take a look at faq184-1769 at the section for retreiving attachments from an e-mail

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I have problem with this:
createobject("MAPI.session")

I get this error:

Class definition MAPI.session is not found
What should I do? I tried to insert activeX Microsoft MAPI Session control v 6.0 but it still doesnt work.

 
bon011

Class definition MAPI.session is not found

MAPI.session is intergrated with CDO (Collaboration data objects). It would seem that your system does not have CDO. You may consider automating Outlook to retreive you attachments.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
* Copy and paste coding :

DO decl
#DEFINE SUCCESS_SUCCESS 0

PRIVATE hSession
hSession = getNewSession()

IF hSession = 0
? "Unable to log on."
ELSE
IF FILE("CSRESULT.DBF")
DELETE FILE CSRESULT.DBF
ENDIF
* resulting cursor
CREATE TABLE csResult (;
origname C(50), origaddr C(50), subj C(200), msg M,attachment M)

= ScanningMessages()

* it takes some time
= MAPILogoff (hSession, 0, 0, 0)

GO TOP
BROWSE NORMAL NOWAIT
ENDIF
* end of main

PROCEDURE ScanningMessages
#DEFINE MAPI_LONG_MSGID 16384
#DEFINE MAPI_UNREAD_ONLY 32

LOCAL lcBuffer, lnResult, lcMsgId, lnMsgCount
lcBuffer = Repli(Chr(0), 1024)

* retrieving message identifiers
lcMsgId = .Null.
lnMsgCount = 0

DO WHILE .T.
lnResult = MAPIFindNext (hSession, 0, .Null., lcMsgId,;
MAPI_LONG_MSGID, 0, @lcBuffer)

IF lnResult = SUCCESS_SUCCESS
lnMsgCount = lnMsgCount + 1
lcMsgId = SUBSTR(lcBuffer, 1,AT(Chr(0),lcBuffer)-1)
= ReadMessage(lcMsgId)
ELSE
EXIT
ENDIF
ENDDO
RETURN

PROCEDURE ReadMessage(lcMsgId)
#DEFINE MAPI_PEEK 128
#DEFINE MAPI_SUPPRESS_ATTACH 2048

LOCAL lnResult, lnMemPtr
lnMemPtr = 0

lnResult = MAPIReadMail (hSession, 0, lcMsgId,;
MAPI_PEEK+MAPI_SUPPRESS_ATTACH, 0,;
@lnMemPtr)

IF lnResult = SUCCESS_SUCCESS
= SaveMessage(lnMemPtr)
= MAPIFreeBuffer(lnMemPtr)
ENDIF
RETURN

PROCEDURE SaveMessage(lnMemPtr)
*| typedef struct {
*| ULONG ulReserved; 0:4
*| LPTSTR lpszSubject; 4:4
*| LPTSTR lpszNoteText; 8:4
*| LPTSTR lpszMessageType; 12:4
*| LPTSTR lpszDateReceived; 16:4
*| LPTSTR lpszConversationID; 20:4
*| FLAGS flFlags; 24:4
*| lpMapiRecipDesc lpOrigin; 28:4
*| ULONG nRecipCount; 32:4
*| lpMapiRecipDesc lpRecips; 36:4
*| ULONG nFileCount; 40:4
*| lpMapiFileDesc lpFiles; 44:4
*| } MapiMessage, FAR *lpMapiMessage; total = 48 bytes
#DEFINE MAPIMESSAGE_STRU_SIZE 48

LOCAL lcBuffer, lcSubject, lcNoteTxt

lcBuffer = Repli(Chr(0), MAPIMESSAGE_STRU_SIZE)
= Heap2Str(@lcBuffer, lnMemPtr, MAPIMESSAGE_STRU_SIZE)

lcSubject = GetStruParam(@lcBuffer, 5)
lcNoteTxt = GetStruParam(@lcBuffer, 9)

*| typedef struct {
*| ULONG ulReserved 0:4
*| ULONG ulRecipClass; 4:4
*| LPTSTR lpszName; 8:4
*| LPTSTR lpszAddress; 12:4
*| ULONG ulEIDSize; 16:4
*| LPVOID lpEntryID; 20:4
*| } MapiRecipDesc, FAR *lpMapiRecipDesc; total = 24 bytes
#DEFINE MAPIRECIPDESC_STRU_SIZE 24

LOCAL lnOrigPtr, lcOrigBuf, lcOrigName, lcOrigAddr
lnOrigPtr = buf2dword(SUBSTR(lcBuffer, 29,4))

lcOrigBuf = Repli(Chr(0), MAPIRECIPDESC_STRU_SIZE)
= Heap2Str(@lcOrigBuf, lnOrigPtr, MAPIRECIPDESC_STRU_SIZE)

lcOrigName = GetStruParam(@lcOrigBuf, 9)
lcOrigAddr = GetStruParam(@lcOrigBuf, 13)

INSERT INTO csResult VALUES (m.lcOrigName, m.lcOrigAddr,;
m.lcSubject, m.lcNoteTxt,"")
RETURN

FUNCTION GetStruParam (lcBuffer, lnOffs)
LOCAL lnPtr, lcResult
lnPtr = buf2dword(SUBSTR(lcBuffer, lnOffs,4))
RETURN Iif(lnPtr=0, "", mem2str(lnPtr))

FUNCTION getNewSession()
#DEFINE MAPI_LOGON_UI 1
#DEFINE MAPI_NEW_SESSION 2
#DEFINE MAPI_USE_DEFAULT 64
#DEFINE MAPI_FORCE_DOWNLOAD 4096 && 0x1000
#DEFINE MAPI_PASSWORD_UI 131072 && 0x20000

WAIT WINDOW "Creating a new MAPI session..." NOWAIT
LOCAL lnResult, lnSession, lcStoredPath
lcStoredPath = SYS(5) + SYS(2003)
lnSession = 0

* lnResult = MAPILogon (0, "Novell Default Settings", .Null.,;
MAPI_USE_DEFAULT+MAPI_NEW_SESSION, 0, @lnSession)

lnResult = MAPILogon (0, "", .Null.,;
MAPI_USE_DEFAULT+MAPI_NEW_SESSION, 0, @lnSession)

* sometimes you need to restore default path - Outlook Express
SET DEFAULT TO (lcStoredPath)
WAIT CLEAR
RETURN Iif(lnResult=SUCCESS_SUCCESS, lnSession, 0)

FUNCTION mem2str(lnMemBlock)
#DEFINE BUFFER_SIZE 16
#DEFINE EMPTY_BUFFER Repli(Chr(0), BUFFER_SIZE)
LOCAL lnPtr, lcResult, lcBuffer, lnPos
lnPtr = lnMemBlock
lcResult = ""

DO WHILE .T.
lcBuffer = EMPTY_BUFFER
= Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE)
lnPos = AT(Chr(0), lcBuffer)

IF lnPos > 0
lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1)
RETURN lcResult
ELSE
lcResult = lcResult + lcBuffer
lnPtr = lnPtr + BUFFER_SIZE
ENDIF
ENDDO

FUNCTION buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
Asc(SUBSTR(lcBuffer, 4,1)) * 16777216

PROCEDURE decl
DECLARE INTEGER MAPILogon IN mapi32;
INTEGER ulUIParam, STRING lpszProfileName,;
STRING lpszPassword, INTEGER flFlags,;
INTEGER ulReserved, INTEGER @lplhSession

DECLARE INTEGER MAPILogoff IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
INTEGER flFlags, INTEGER ulReserved

DECLARE INTEGER MAPIReadMail IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
STRING lpszMessageID, INTEGER flFlags,;
INTEGER ulReserved, INTEGER @lppMessage

DECLARE INTEGER MAPIFreeBuffer IN mapi32 INTEGER pv

DECLARE INTEGER MAPIFindNext IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
STRING lpszMsgType, STRING lpszSeedMsgID,;
INTEGER flFlags, INTEGER ulReserved, STRING @lpszMsgID

DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
STRING @, INTEGER, INTEGER



 
* From Bill Too kctoo@netvigator.com
* Copy and paste coding :

DO decl
#DEFINE SUCCESS_SUCCESS 0

PRIVATE hSession
hSession = getNewSession()

IF hSession = 0
? "Unable to log on."
ELSE
IF FILE("CSRESULT.DBF")
DELETE FILE CSRESULT.DBF
ENDIF
* resulting cursor
CREATE TABLE csResult (;
origname C(50), origaddr C(50), subj C(200), msg M,attachment M)

= ScanningMessages()

* it takes some time
= MAPILogoff (hSession, 0, 0, 0)

GO TOP
BROWSE NORMAL NOWAIT
ENDIF
* end of main

PROCEDURE ScanningMessages
#DEFINE MAPI_LONG_MSGID 16384
#DEFINE MAPI_UNREAD_ONLY 32

LOCAL lcBuffer, lnResult, lcMsgId, lnMsgCount
lcBuffer = Repli(Chr(0), 1024)

* retrieving message identifiers
lcMsgId = .Null.
lnMsgCount = 0

DO WHILE .T.
lnResult = MAPIFindNext (hSession, 0, .Null., lcMsgId,;
MAPI_LONG_MSGID, 0, @lcBuffer)

IF lnResult = SUCCESS_SUCCESS
lnMsgCount = lnMsgCount + 1
lcMsgId = SUBSTR(lcBuffer, 1,AT(Chr(0),lcBuffer)-1)
= ReadMessage(lcMsgId)
ELSE
EXIT
ENDIF
ENDDO
RETURN

PROCEDURE ReadMessage(lcMsgId)
#DEFINE MAPI_PEEK 128
#DEFINE MAPI_SUPPRESS_ATTACH 2048

LOCAL lnResult, lnMemPtr
lnMemPtr = 0

lnResult = MAPIReadMail (hSession, 0, lcMsgId,;
MAPI_PEEK+MAPI_SUPPRESS_ATTACH, 0,;
@lnMemPtr)

IF lnResult = SUCCESS_SUCCESS
= SaveMessage(lnMemPtr)
= MAPIFreeBuffer(lnMemPtr)
ENDIF
RETURN

PROCEDURE SaveMessage(lnMemPtr)
*| typedef struct {
*| ULONG ulReserved; 0:4
*| LPTSTR lpszSubject; 4:4
*| LPTSTR lpszNoteText; 8:4
*| LPTSTR lpszMessageType; 12:4
*| LPTSTR lpszDateReceived; 16:4
*| LPTSTR lpszConversationID; 20:4
*| FLAGS flFlags; 24:4
*| lpMapiRecipDesc lpOrigin; 28:4
*| ULONG nRecipCount; 32:4
*| lpMapiRecipDesc lpRecips; 36:4
*| ULONG nFileCount; 40:4
*| lpMapiFileDesc lpFiles; 44:4
*| } MapiMessage, FAR *lpMapiMessage; total = 48 bytes
#DEFINE MAPIMESSAGE_STRU_SIZE 48

LOCAL lcBuffer, lcSubject, lcNoteTxt

lcBuffer = Repli(Chr(0), MAPIMESSAGE_STRU_SIZE)
= Heap2Str(@lcBuffer, lnMemPtr, MAPIMESSAGE_STRU_SIZE)

lcSubject = GetStruParam(@lcBuffer, 5)
lcNoteTxt = GetStruParam(@lcBuffer, 9)

*| typedef struct {
*| ULONG ulReserved 0:4
*| ULONG ulRecipClass; 4:4
*| LPTSTR lpszName; 8:4
*| LPTSTR lpszAddress; 12:4
*| ULONG ulEIDSize; 16:4
*| LPVOID lpEntryID; 20:4
*| } MapiRecipDesc, FAR *lpMapiRecipDesc; total = 24 bytes
#DEFINE MAPIRECIPDESC_STRU_SIZE 24

LOCAL lnOrigPtr, lcOrigBuf, lcOrigName, lcOrigAddr
lnOrigPtr = buf2dword(SUBSTR(lcBuffer, 29,4))

lcOrigBuf = Repli(Chr(0), MAPIRECIPDESC_STRU_SIZE)
= Heap2Str(@lcOrigBuf, lnOrigPtr, MAPIRECIPDESC_STRU_SIZE)

lcOrigName = GetStruParam(@lcOrigBuf, 9)
lcOrigAddr = GetStruParam(@lcOrigBuf, 13)

INSERT INTO csResult VALUES (m.lcOrigName, m.lcOrigAddr,;
m.lcSubject, m.lcNoteTxt,"")
RETURN

FUNCTION GetStruParam (lcBuffer, lnOffs)
LOCAL lnPtr, lcResult
lnPtr = buf2dword(SUBSTR(lcBuffer, lnOffs,4))
RETURN Iif(lnPtr=0, "", mem2str(lnPtr))

FUNCTION getNewSession()
#DEFINE MAPI_LOGON_UI 1
#DEFINE MAPI_NEW_SESSION 2
#DEFINE MAPI_USE_DEFAULT 64
#DEFINE MAPI_FORCE_DOWNLOAD 4096 && 0x1000
#DEFINE MAPI_PASSWORD_UI 131072 && 0x20000

WAIT WINDOW "Creating a new MAPI session..." NOWAIT
LOCAL lnResult, lnSession, lcStoredPath
lcStoredPath = SYS(5) + SYS(2003)
lnSession = 0

* lnResult = MAPILogon (0, "Novell Default Settings", .Null.,;
MAPI_USE_DEFAULT+MAPI_NEW_SESSION, 0, @lnSession)

lnResult = MAPILogon (0, "", .Null.,;
MAPI_USE_DEFAULT+MAPI_NEW_SESSION, 0, @lnSession)

* sometimes you need to restore default path - Outlook Express
SET DEFAULT TO (lcStoredPath)
WAIT CLEAR
RETURN Iif(lnResult=SUCCESS_SUCCESS, lnSession, 0)

FUNCTION mem2str(lnMemBlock)
#DEFINE BUFFER_SIZE 16
#DEFINE EMPTY_BUFFER Repli(Chr(0), BUFFER_SIZE)
LOCAL lnPtr, lcResult, lcBuffer, lnPos
lnPtr = lnMemBlock
lcResult = ""

DO WHILE .T.
lcBuffer = EMPTY_BUFFER
= Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE)
lnPos = AT(Chr(0), lcBuffer)

IF lnPos > 0
lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1)
RETURN lcResult
ELSE
lcResult = lcResult + lcBuffer
lnPtr = lnPtr + BUFFER_SIZE
ENDIF
ENDDO

FUNCTION buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
Asc(SUBSTR(lcBuffer, 4,1)) * 16777216

PROCEDURE decl
DECLARE INTEGER MAPILogon IN mapi32;
INTEGER ulUIParam, STRING lpszProfileName,;
STRING lpszPassword, INTEGER flFlags,;
INTEGER ulReserved, INTEGER @lplhSession

DECLARE INTEGER MAPILogoff IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
INTEGER flFlags, INTEGER ulReserved

DECLARE INTEGER MAPIReadMail IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
STRING lpszMessageID, INTEGER flFlags,;
INTEGER ulReserved, INTEGER @lppMessage

DECLARE INTEGER MAPIFreeBuffer IN mapi32 INTEGER pv

DECLARE INTEGER MAPIFindNext IN mapi32;
INTEGER lhSession, INTEGER ulUIParam,;
STRING lpszMsgType, STRING lpszSeedMsgID,;
INTEGER flFlags, INTEGER ulReserved, STRING @lpszMsgID

DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
STRING @, INTEGER, INTEGER



 
kctoo

Nice code, you may want to give credit to the author. The code looks familiar.

And also I get an error (Undeclared DLL) at this line:
= Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
kctoo

Also the code does not work in Windows XP.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
mgagnon

It need to declare DLL first. So U should run "DECL" sub procedure. It is working in XP

kctoo
 
kctoo
It need to declare DLL first. So U should run "DECL" sub procedure. It is working in XP

It must be a configuration issue, I get a "unable to logon" message.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top