Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   ¿como recibo el body cuerpo y adjuntos de un mail IMAP server ?? (https://www.clubdelphi.com/foros/showthread.php?t=90140)

JXJ 15-04-2016 10:44:30

¿como recibo el body cuerpo y adjuntos de un mail IMAP server ??
 
hola

duda de como puedo obtener el mensaje de un mail.
el body,.

tengo este codigo para IMAP de GMAIL. ya configure mi cuenta de gmail para que soporte
acceso de aplicaciones externas y como puedo bajar los archivos adjuntos.

Gracias.

Código Delphi [-]
unit GmailUnreadMailsU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdMessage, IdIOHandler, IdIOHandlerSocket,
  IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient,
  IdIMAP4;

type
  TGmailUnreadMailsF = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    EditCorreo: TEdit;
    EditPass: TEdit;
    BtnConecta: TButton;
    Memo1: TMemo;
    BtnGetNumlMailsInbox: TButton;
    IdIMAP41: TIdIMAP4;
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    IdMessage1: TIdMessage;
    BtnGetUnreadlMails: TButton;
    Memo2: TMemo;
    EditUUID: TEdit;
    BtnGetData: TButton;
    Label6: TLabel;
    Memo3: TMemo;
    Memo4: TMemo;
    procedure log(linea:string);
    procedure BtnConectaClick(Sender: TObject);
    procedure BtnGetNumlMailsInboxClick(Sender: TObject);
    procedure BtnGetUnreadlMailsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  GmailUnreadMailsF: TGmailUnreadMailsF;

implementation

{$R *.dfm}


procedure TGmailUnreadMailsF.log(linea:string);
begin
  Memo1.Lines.Add(linea);
end;


procedure TGmailUnreadMailsF.BtnConectaClick(Sender: TObject);
begin
      IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvSSLv3;
      IdIMAP41.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
      IdIMAP41.Host := 'imap.gmail.com';
      IdIMAP41.Port := 993;
      IdIMAP41.ReadTimeout := 30000;
      IdIMAP41.UseTLS := utUseImplicitTLS;
      IdIMAP41.Username := EditCorreo.Text;
      IdIMAP41.Password := EditPass.Text;
      IdIMAP41.Connect;

      if IdIMAP41.Connected then
      begin
       Label3.Caption := 'Si Conectado';
      end
      else
      begin
       Label3.Caption := 'No Conectado';
      end;


end;

procedure TGmailUnreadMailsF.BtnGetNumlMailsInboxClick(Sender: TObject);
var
 iTotalMsgsInbox : Integer;
begin

        if IdIMAP41.SelectMailBox('INBOX') then
          iTotalMsgsInbox := IdIMAP41.MailBox.TotalMsgs;
          IdIMAP41.StatusMailBox('INBOX', IdIMAP41.MailBox); // este es necesario sino no actualiza los valores


  log('Total de mails en la carpeta de INBOX es : '+ IntToStr(iTotalMsgsInbox) );



end;

procedure TGmailUnreadMailsF.BtnGetUnreadlMailsClick(Sender: TObject);
var
 nummsgs:Integer;
 n : Integer;
 i : Integer;
     TheUID: string;
         TheFlags: TIdMessageFlagsSet;
begin
  log('Total de mails en la carpeta de IdIMAP41.MailBox.UnseenMsgs es : '+ IntToStr(IdIMAP41.MailBox.UnseenMsgs) );
  log('Total de mails en la carpeta de IdIMAP41.MailBox.RecentMsgs es : '+ IntToStr(IdIMAP41.MailBox.RecentMsgs) );

  nummsgs:=idImap41.MailBox.TotalMsgs;

   
    for i := 0 to nummsgs-1 do
    begin
                idimap41.GetUID(i+1, TheUID);
                idimap41.UIDRetrieveFlags(TheUID, TheFlags);
                idimap41.UIDRetrieveHeader(TheUID, IdMessage1);
//                StringGrid1.Cells[0, i+1] := IntToStr(i+1);
            log(IntToStr( i+1) + ' '+ IntToStr(i+1));
//                StringGrid1.Cells[1, i+1] := TheUID;
            log(IntToStr( i+1) +' ' +  TheUID);
                if mfSeen in TheFlags then begin
//                    StringGrid1.Cells[2, i+1] := 'Yes';
             log(IntToStr(i+1 ) + ' ' + 'Yes'  );
                end else begin
//                    StringGrid1.Cells[2, i+1] := 'No';
            log(IntToStr( i+1) + ' ' +  'No');
                end;
//                StringGrid1.Cells[3, i+1] := IdMessage1.Subject;
            log(IntToStr( i+1) + IdMessage1.Subject);
            end;


//            idimap41.Retrieve(1, IdMessage1);
            idimap41.RetrieveHeader(1, IdMessage1);
//            idimap41.RetrieveEnvelope(1, IdMessage1);
            Memo3.Lines.Add(            IdMessage1.FromList.EMailAddresses);
            Memo3.Lines.Add(            IdMessage1.Recipients.EMailAddresses);
            Memo3.Lines.Add(            IdMessage1.Subject);
            Memo3.Lines.Add(            IdMessage1.CCList.EMailAddresses);
            Memo4.Lines.Add(            IdMessage1.Body.Text); // el texto no entra en el memo4 no se como


end;

end.

petercat 14-05-2019 00:05:21

Buenas
Consiguistes extraer el cuerpo y los adjuntos de un correo entrante atraves de gmail??


Un saludo


La franja horaria es GMT +2. Ahora son las 19:13:11.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi