Page 1 of 2

Is it possible to read and send mails from Exchange Server?

PostPosted: Tue Nov 17, 2009 12:16 pm
by Horizon
Hi,

Is it possible to read and send mails from Exchange Server? Is there any example for it?

Thanks in advance.

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Tue Nov 17, 2009 12:48 pm
by anserkk
Do you mean to say that you would like to Send/Receive email withot using Outlook Express/ MS Outlook or any other email client software

I believe that you can use CDO to access Exchange Server or any mail server to send and receive emails.
http://forums.fivetechsupport.com/viewtopic.php?f=3&t=15843

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Tue Nov 17, 2009 2:44 pm
by Horizon
Thanks Anser,

This example is related sending mails. Is there any examples that reading mails?

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Tue Nov 17, 2009 4:51 pm
by anserkk
Hi Hakan,

Sorry, I don't have any samples to demonstrate retrieval of email messages from a POP3 server. I have not tried this till now.
I think MAPI is the way to go for reading mails and CDO is used mostly for sending mails.

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Wed Nov 18, 2009 8:12 am
by anserkk
Hi all,

Anybody here tried to read a POP3 Server to find out new unread mails in a POP3 server. I understand that MAPI32.DLL is used and the progid for the DLL is
CREATEOBJECT (the ProgIDs for these controls are MSMAPI.MAPIMessages and MSMAPI.MAPISession).

But I am getting an error when I try this
Code: Select all  Expand view
oSession:=CreateObject("MSMAPI.MAPISession")


I get the following error

[list=]Application
===========
Path and name: D:\FwhExtra\FWHTests\ReadMail.exe (32 bits)
Size: 1,846,784 bytes
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 11/18/09, 13:40:20
Error description: Error TOleAuto/65535 : TOLEAUTO:NEW
Args:
[ 1] = C MSMAPI.MAPISession
[ 2] = U
[ 3] = U

Stack Calls
===========
Called from: => THROW(0)
Called from: source\rtl\win32ole.prg => TOLEAUTO:NEW(346)
Called from: source\rtl\win32ole.prg => CREATEOBJECT(78)
Called from: ReadMail.prg => MAIN(7)
[/list]

Any idea ? Do I have to use the DECLARE DLL ?

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Wed Nov 18, 2009 12:08 pm
by James Bott
Anser,

Have you tried searching the forum for "POP3?" I seem to remember there was some sample code for this.

James

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Wed Nov 18, 2009 12:28 pm
by anserkk
Dear Mr.James,

I tried the followinng link in the spanish forum, but unfortunately I could not get it work.
viewtopic.php?f=6&t=6258

As per the link, you need to download an OCX file named MSMAPI32.OCX. But even after registering the OCX, the program crashes. If you check the Valtype of the object created, instead of Object, it is showing as NUMERIC.

I am looking for a solution that works without any additional OCX control. I thought that the default CDO/MAPI would work without installing any additional OCX

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Wed Nov 18, 2009 12:57 pm
by James Bott
Anser,

Search for "TPOP3"

James

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Thu Nov 19, 2009 5:02 am
by anserkk
Dear Mr.James,

Thank you. FiveWin's TPop3 is working fine and this the one which I was looking for. Now I need to understand the techniques used to extract the header, attachments, Subject, Sender's details etc. from the array aMsgs

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Thu Nov 19, 2009 6:48 am
by James Bott
Anser, you can find that info here:

viewtopic.php?f=3&t=2069&p=8878&hilit=tpop3#p8878

James

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Thu Nov 19, 2009 9:19 am
by anserkk
Dear Mr.James,

Another problem which I see is that TPop3 downloads the whole email. (TelNet command RETR). I have to download the whole mail and then extract the headers from it and will be time consuming if attachments are there ( depends on the email size). Hope there is some other technique to get the header only (From,To,Subject,Email Size), so that it is faster. Nowadays, most mobile phone supports the retrieval of Email Headers. I know that TPop3 is supposed to be used to retrieve emails from POP3 servers. Just wondering whether another method exist to retrieve the header only. I did not find any TelNet commands to retrieve just the header. LIST will give the message no's and size in bytes

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Thu Nov 19, 2009 3:39 pm
by James Bott
Anser,

Just wondering whether another method exist to retrieve the header only.


I know that this is possible because I have a program that does it (not a FW program). I do not know how to do it using FWH. I would try searching the NET.

Regards,
James

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Fri Nov 20, 2009 6:00 am
by anserkk
Dear Mr.James,

With few minor changes in our own FiveWin Class TPop3, we can get the headers only from email. This method is fast, because the whole email is not downloaded, but just the headers. I modified the class with an additional data, so that the programmer can decide whether he wants to download the whole email message or just the header.

Code: Select all  Expand view
oInMail = TPop3():New( cIp,, cUserName, cPassword )  
oInMail:lHeaderOnly:=.T.  // Retrieves only the headers
 

The default value of the data ::lHeaderOnly is .F., and for those who require to download only the headers can set the value to .T.

This will be useful for those who want to check the email messages for a specific subject/From address in a much faster way.

Regards
Anser

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Fri Nov 20, 2009 7:40 am
by Horizon
Hi Anser,

Is it possible to share changes in TPop3 Class if you don't mind?

Thanks in advance.

Re: Is it possible to read and send mails from Exchange Server?

PostPosted: Fri Nov 20, 2009 7:50 am
by anserkk
The changes required in TPop3.Prg

CLASS TPop3
Code: Select all  Expand view
DATA   lHeaderOnly   // New Data


METHOD New()

Code: Select all  Expand view
  ::lHeaderOnly:=.F.  // Initialize the Value to .F.


In METHOD OnRead()

Line 147
Code: Select all  Expand view
         if ::lHeaderOnly
                    cCommand  = "TOP " + AllTrim( Str( 1, 4, 0 ) )+ " 0" + CRLF
                 Else
                    cCommand  = "RETR " + AllTrim( Str( 1, 4, 0 ) )+ CRLF
                 Endif
 

Line 161
Code: Select all  Expand view
         if ::lHeaderOnly
                    cCommand  = "TOP " + AllTrim( Str( ++::nAtMsg, 4, 0 ) ) + " 0" + CRLF
                 Else
                    cCommand  = "RETR " + AllTrim( Str( ++::nAtMsg, 4, 0 ) ) + CRLF
                 Endif
 

Line 183
Code: Select all  Expand view
        if ::lHeaderOnly
            cCommand  = "TOP " + AllTrim( Str( ++::nAtMsg, 4, 0 ) ) + " 0" + CRLF
        else
            cCommand  = "RETR " + AllTrim( Str( ++::nAtMsg, 4, 0 ) ) + CRLF
                 Endif
 

Mr.Antonio,

Do you mind including this modified class in the next FWH build ? I shall send the modified class to your mail id

Regards
Anser