Recent

Author Topic: [CLOSED] IMAP Synapse - Check if there are new messages  (Read 1007 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 746
[CLOSED] IMAP Synapse - Check if there are new messages
« on: October 05, 2021, 03:55:43 pm »
I can login to my email providers server, get mails and so on.
What logic do I have to use see if there are new messages?
« Last Edit: October 06, 2021, 07:13:28 am by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

paweld

  • Sr. Member
  • ****
  • Posts: 314
Re: IMAP Synapse - Check if there are new messages
« Reply #1 on: October 05, 2021, 04:33:42 pm »
Code: Pascal  [Select][+][-]
  1. uses
  2.   imapsend, mimemess, ssl_openssl, ssl_openssl_lib, synacode,
  3.   mimepart, synachar;
  4.  
  5. procedure TForm1.Button2Click(Sender: TObject);
  6. var
  7.   ImapClient: TIMAPSend;
  8.   ListaMsg, Msg: TStringList;
  9.   i, j: Integer;
  10. begin
  11.   ListaMsg := TStringList.Create;
  12.   Msg := TStringList.Create;
  13.   ImapClient := TIMAPSend.Create;
  14.   ImapClient.TargetHost := mailhost;
  15.   ImapClient.TargetPort := mailport;
  16.   ImapClient.UserName := maillogin;
  17.   ImapClient.Password := mailpasswd;
  18.   ImapClient.AutoTLS := True;
  19.   ImapClient.FullSSL := True;
  20.   ImapClient.Login;
  21.   ImapClient.SelectFolder('INBOX');
  22.   if ImapClient.SearchMess('UNSEEN', ListaMsg) then
  23.   begin
  24.     for i := 0 to ListaMsg.Count - 1 do
  25.     begin
  26.       Msg.Clear;
  27.       ImapClient.FetchMess(StrToInt(ListaMsg[i]), Msg);
  28.       memo1.Lines.Add(msg.Text);
  29.       memo1.Lines.Add('---');
  30.     end;
  31.   end;
  32.   Msg.Free;
  33.   ListaMsg.Free;
  34. end;
Best regards
paweld

pcurtis

  • Hero Member
  • *****
  • Posts: 746
Re: IMAP Synapse - Check if there are new messages
« Reply #2 on: October 05, 2021, 04:40:45 pm »
I haven't tried but won't that just show unseen messages?
And fetchmess will mark the message as read.
« Last Edit: October 05, 2021, 05:06:19 pm by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1021
    • Lebeau Software
Re: IMAP Synapse - Check if there are new messages
« Reply #3 on: October 05, 2021, 06:49:44 pm »
I haven't tried but won't that just show unseen messages?

Yes.  You could alternatively try 'NEW' instead, which searches for messages that are both '\Recent' and '\Unseen'.

And fetchmess will mark the message as read.

I don't know. It depends on what criteria Fetchmess() actually retreives.  Not all FETCH parameters set the '\Seen' flag on a message.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

pcurtis

  • Hero Member
  • *****
  • Posts: 746
Re: [CLOSED] IMAP Synapse - Check if there are new messages
« Reply #4 on: October 06, 2021, 07:17:05 am »
thanks paweld and Remy Lebeau for putting me on the right path.
Windows 10
Laz 2.0.10
FPC 3.2.0

 

TinyPortal © 2005-2018