Delphi / Indy

Hi

Using delphi 2007 and Indy 10 how do I receive and display emails  + attachments in delphi and not use Outlook etc

Thanks
KevinfeeningAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ephraim WangoyaCommented:
Use TidPop3 and TidMessage components
Set the pop3 as neccessary
  FPOP3Client.Host := Host;
  FPOP3Client.Port :=PortNumber
  FPOP3Client.Username := UserName;
  FPOP3Client.Password := UserPassword
  FPOP3Client.Connect;

  //Retreive your messages using CheckMessages
  MsgCount := FPOP3Client.CheckMessages;

  //You can use a loop to read the messages
  Loop := 1;
  while (Loop <= MsgCount)  do
  begin
    FMessage.Clear;
    FPOP3Client.Retrieve(Loop, FMessage);
   
    //Use the data in FMessage as you wish
  // FMessage.Subject
   //FMessage.From.Text

    FPOP3Client.Delete(Loop);
    Inc(Loop);  
  end;
  FPOP3Client.Disconnect;

Example reading the body
function getmailbodytext: string;
var
  Loop, MsgPart: Integer;
begin
  Result := '';
  MsgPart := Pred(FMessage.MessageParts.Count);
  for Loop := 0 to MsgPart -1 do
  begin
    if FMessage.MessageParts.Items[Loop] is TIdText then
      Result := Result + TrimStr(TIdText(FMessage.MessageParts.Items[Loop]).Body.Text);
  end;
  if MsgPart < 0 then
    Result := TrimStr(FMessage.Body.Text);

Open in new window


Exmple reading attachments
procedure getattachments
var
  FilName: string;
  I: Integer;
begin
  for I := 0 to FMessage.MessageParts.Count -1 do
    if FMessage.MessageParts[I] is TIdAttachment then
      with TIdAttachment(FMessage.MessageParts[I]) do
      begin
        Filname := 'C:\' + ExtractFileName(FileName);
        if not FileExists(FilName) then
        try
          SaveToFile(Filname);          
        except
          /Handle your error
        end;
      end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sepidehdamCommented:
Help to guide delphi 7
"ALTER TABLE add column.
By coding with Delphi 7
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.