BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is it correct way to forward message 'reading form pop and t

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
ganesh
Guest





PostPosted: Thu Nov 13, 2003 10:05 am    Post subject: Is it correct way to forward message 'reading form pop and t Reply with quote




Is it correct way to forward message 'reading form pop and then send thru smtp'



If Not idSmtp.Connected Then
idSmtp.Connect;

If Not IdPOP.Connected Then
IdPOP.Connect;

For i := 1 to IdPOP.CheckMessages Do
Begin
IdMessage1.NoDecode := True;
IdMessage1.Clear;
IdMessage1.ClearBody;
IdMessage1.ClearHeader;

If Not IdPOP.Retrieve(i, IdMessage1) Then
ShowMessage('not ret');



IdMessage1.Recipients.EMailAddresses := 'abcv.xya@s.co.uk';

idSmtp.Send(idMessage1);

Application.ProcessMessages;
End;
ShowMessage(IntToStr(idPop.CheckMessages));
IdPOP.Disconnect;
idSmtp.Disconnect;

it's working first time, But next time it doestn't send all messages, just send 1 message out of 6, i don't know what was the problem

but after first sending i can see all the emails still exists

any idea, i use indy 9.0.14, delphi 5 prof

Thanks
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Nov 13, 2003 6:44 pm    Post subject: Re: Is it correct way to forward message 'reading form pop a Reply with quote




"ganesh" <gsganesh (AT) yahoo (DOT) com> wrote


Quote:
For i := 1 to IdPOP.CheckMessages Do

I do not suggest you call CheckMessages() over and over like that. Call it
as a separate operation and store the result into a variable:

var
Count: Integer;

Count := IdPOP.CheckMessages;
For i := 1 to Count Do
...

Quote:
IdMessage1.Clear;
IdMessage1.ClearBody;
IdMessage1.ClearHeader;

There is not need to call ClearBody() and ClearHeader(), Clear() already
does that.

Quote:
If Not IdPOP.Retrieve(i, IdMessage1) Then
ShowMessage('not ret');

Your code suggests that you are continuing to process the message even when
Retreive() fails. If that is the case, you should put a call to "Continue"
into your loop if Retrieve() fails, ie:

If Not IdPOP.Retrieve(i, IdMessage1) Then
Begin
ShowMessage('not ret');
Continue;
End;

Quote:
ShowMessage(IntToStr(idPop.CheckMessages));

You did not delete any messages, so CheckMessages() is going to return the
same number that is did earlier.

Quote:
IdPOP.Disconnect;
idSmtp.Disconnect;

I would strongly suggest that you wrap the operations in try...finally
blocks so that you can disconnect correctly in case exceptions are thrown.
Currently, your code is not very exception-safe.

Quote:
but after first sending i can see all the emails still exists

You did not delete any messages from the POP server, so they will still
exist for the next time. After you send a message, you should call
TIdPOP3::Delete() to remove it from the server.

Try this code instead:

var
I, Count: Integer;

idSmtp.Connect;
Try
IdPOP.Connect;
Try
Count := IdPOP.CheckMessages;

For I := 1 to Count Do
Begin
IdMessage1.Clear;
IdMessage1.NoDecode := True;

If not IdPOP.Retrieve(I, IdMessage1) Then
Begin
ShowMessage('not ret');
Continue;
End;

IdMessage1.Recipients.EMailAddresses := 'abcv.xya@s.co.uk';
Try
idSmtp.Send(idMessage1);
Except
ShowMessage('not sent');
Continue;
End;

IdPOP.Delete(I);
End;
Finally
IdPOP.Disconnect;
End;
Finally
idSmtp.Disconnect;
End;


Gambit



Back to top
ganesh
Guest





PostPosted: Mon Nov 17, 2003 9:30 am    Post subject: Re: Is it correct way to forward message 'reading form pop a Reply with quote



Hi Remy,

Thanks for your reply, i don't want to delete any message from pop
server, because first time i pick up messages change the 'to address'
then send all the emails

the next time i've to send all the emails to another 'email id', i
could be n times, but still it's not working properly, i used exactly
the code as you except delete()

any idea, even i didn't get any error on smtp.send

Thanks
Ganesh

"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote

Quote:
"ganesh" <gsganesh (AT) yahoo (DOT) com> wrote in message
news:3fb36563$1 (AT) newsgroups (DOT) borland.com...

For i := 1 to IdPOP.CheckMessages Do

I do not suggest you call CheckMessages() over and over like that. Call it
as a separate operation and store the result into a variable:

var
Count: Integer;

Count := IdPOP.CheckMessages;
For i := 1 to Count Do
...

IdMessage1.Clear;
IdMessage1.ClearBody;
IdMessage1.ClearHeader;

There is not need to call ClearBody() and ClearHeader(), Clear() already
does that.

If Not IdPOP.Retrieve(i, IdMessage1) Then
ShowMessage('not ret');

Your code suggests that you are continuing to process the message even when
Retreive() fails. If that is the case, you should put a call to "Continue"
into your loop if Retrieve() fails, ie:

If Not IdPOP.Retrieve(i, IdMessage1) Then
Begin
ShowMessage('not ret');
Continue;
End;

ShowMessage(IntToStr(idPop.CheckMessages));

You did not delete any messages, so CheckMessages() is going to return the
same number that is did earlier.

IdPOP.Disconnect;
idSmtp.Disconnect;

I would strongly suggest that you wrap the operations in try...finally
blocks so that you can disconnect correctly in case exceptions are thrown.
Currently, your code is not very exception-safe.

but after first sending i can see all the emails still exists

You did not delete any messages from the POP server, so they will still
exist for the next time. After you send a message, you should call
TIdPOP3::Delete() to remove it from the server.

Try this code instead:

var
I, Count: Integer;

idSmtp.Connect;
Try
IdPOP.Connect;
Try
Count := IdPOP.CheckMessages;

For I := 1 to Count Do
Begin
IdMessage1.Clear;
IdMessage1.NoDecode := True;

If not IdPOP.Retrieve(I, IdMessage1) Then
Begin
ShowMessage('not ret');
Continue;
End;

IdMessage1.Recipients.EMailAddresses := 'abcv.xya@s.co.uk';
Try
idSmtp.Send(idMessage1);
Except
ShowMessage('not sent');
Continue;
End;

IdPOP.Delete(I);
End;
Finally
IdPOP.Disconnect;
End;
Finally
idSmtp.Disconnect;
End;


Gambit

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.