Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ivan  
#1 Posted : Monday, May 2, 2011 12:23:09 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
Delphi Example
After you received the emails from email server to the local folder, we can use the following code to parse the email now. The following code demonstrates how to parse from, to, cc, subject, body text, attachments of specified EML file.

Code:

// The following example codes demonstrate parsing email (*.EML) file
// To get full sample projects, please download and install EAGetMail on your machine.
// To run it correctly, please change email server, user, password, folder, file name value to yours

Unit Unit1; 

Interface 

Uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, EAGetMailObjLib_TLB; 

Type 
  TForm1 = Class(TForm) 
    Button1: TButton; 
    Procedure Button1Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  End; 

Const 
  MailServerPop3 = 0; 
  MailServerImap4 = 1; 

Var 
  Form1: TForm1; 

Implementation 

{$R *.dfm} 

Procedure TForm1.ParseEmail( fileName: WideString ); 
Var 
  oMail: TMail; 
  i, UBound: Integer; 
  addrs, atts: OleVariant; 
  addr: IMailAddress; 
  att: IAttachment; 
Begin 
  oMail := TMail.Create(Application); 
  oMail.LicenseCode := 'TryIt'; 
  oMail.LoadFile(fileName, false); 

  // Parse email sender
  ShowMessage( 'From: ' + oMail.From.Address ); 

  // Parse email to recipients
  addrs := oMail.ToAddr; 
  UBound := VarArrayHighBound( addrs, 1 ); 
  For i := 0 To UBound Do 
  Begin 
    addr := IDispatch(VarArrayGet(addrs, i)) As IMailAddress; 
    ShowMessage( 'To: ' + addr.Address ); 
  End; 

  // Parse email cc recipients
  addrs := oMail.Cc; 
  UBound := VarArrayHighBound( addrs, 1 ); 
  For i := 0 To UBound Do 
  Begin 
    addr := IDispatch(VarArrayGet(addrs, i)) As IMailAddress; 
    ShowMessage( 'Cc: ' + addr.Address ); 
  End; 

  // Parse email subject
  ShowMessage( 'Subject: ' + oMail.Subject ); 

  // Parse email text body
  ShowMessage( 'Text body: ' + oMail.TextBody ); 

  // Parse email HTML body
  ShowMessage( 'HTML body: ' + oMail.HtmlBody ); 

  // Parse attachment
  atts := oMail.Attachments; 
  UBound := VarArrayHighBound( atts, 1 ); 
  For i := 0 To UBound Do 
  Begin 
    att := IDispatch(VarArrayGet(atts,i)) As IAttachment; 
    ShowMessage( att.Name ); 
  End; 

End; 

Procedure TForm1.Button1Click(Sender: TObject); 
Begin 
  Try 
      ParseEmail('c:\my folder\test.eml'); 
  Except 
    On ep:Exception Do 
      ShowMessage( 'Error: ' + ep.Message ); 
  End; 

End; 

End. 

Click here to read original topic - full version ...

If you have any comments or questions about above example codes, please add your comments here.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.044 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.