Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #20  
Antiguo 18-10-2017
elguille elguille is offline
Miembro
 
Registrado: ene 2005
Posts: 114
Poder: 20
elguille Va por buen camino
Este codigo no me funcionaba. Despues de muchas vueltas he editado en WORD lo que queria enviar, lo he grabado con formato "pagina web filtrada" el cual graba un fichero htm y un directorio "nombre"_archivos donde estan las imagenes .
La función de envio
Código Delphi [-]
procedure emailhtml(host: string; nombre: string; password: string; port: integer; desde: string; hasta: string; asunto: string; cuerpo: string; adjunto: string; bcc: string);
var
  IDSMTP1: TIDSMTP;
  email: TIdMessage;
  htmpart, txtpart: TIdText;
  html: TStrings;
  mfic, mfichero: string;
  bmppart: TIdAttachmentfile;
begin
  screen.cursor := crhourglass;
  IDSMTP1 := TIDSMTP.Create(nil);
  IDSMTP1.UserNAME := nombre;
  IDSMTP1.password := password;
  IDSMTP1.host := host;
  IDSMTP1.port := port;

  html := TStringList.Create();
  html.Add(cuerpo);
  email := TIdMessage.Create(nil);
  with email do
  begin
    From.Text := desde;
    Recipients.EMailAddresses := hasta;
    Subject := asunto;
    CCList.EMailAddresses := '';
    BccList.EMailAddresses := bcc;
    ContentType := 'multipart/related; type="text/html"';
    txtpart := TIdText.Create(email.MessageParts);
    txtpart.ContentType := 'multipart/related; type="multipart/alternative"';

    txtpart := TIdText.Create(email.MessageParts);
    txtpart.ContentType := 'multipart/alternative';

    txtpart := TIdText.Create(email.MessageParts);
    txtpart.ContentType := 'text/plain';
    txtpart.ParentPart := 1;

    htmpart := TIdText.Create(email.MessageParts, html);
    htmpart.ContentType := 'text/html';
    htmpart.ParentPart := 1;

    if adjunto <> '' THEN
    begin
      mfichero := adjunto;
      if pos(';', mfichero) > 0 then
      begin
        while pos(';', mfichero) > 0 do
        begin
          mfic := copy(mfichero, 1, pos(';', mfichero) - 1);
          bmppart := TIdAttachmentfile.Create(email.MessageParts, mfic);
          bmppart.ContentType := 'image/jpg';
          bmppart.FileIsTempFile := true;
          bmppart.ContentDisposition := 'inline';
          bmppart.ContentID := '<' + extractfilename(mfic) + '>';
          bmppart.FileName := mfic;
          mfichero := copy(mfichero, pos(';', mfichero) + 1, 1000);
        end;
      end
      else
        TIdAttachmentfile.Create(email.MessageParts, mfichero);
    end;
  end;
  with IDSMTP1 do
  begin
    try
      if Connected then
        Disconnect;
      Connect;
    except
      raise Exception.Create('Error al conectar con el servidor.');
    end;
    if Connected then
    begin
      try
        Send(email);
      except
        on E: Exception do
        begin
          raise Exception.Create(E.classname + ' ' + E.message);
        end;
      end;
      try
        Disconnect;
      except
        raise Exception.Create('Error al desconectar del servidor.');
      end;
    end;
  end;
  html.Free;
  IDSMTP1.Free;
  email.Free;
  screen.cursor := crdefault;
end;
Con la llamada para el fichero email.htm
Código Delphi [-]
      TS2 := tstringlist.Create;
      TS2.LoadFromFile(extractfilepath(application.ExeName) + 'email.htm');
      TS2.Text := strreplace(TS2.Text, 'email_archivos/', 'cid:');
      mrut := extractfilepath(application.ExeName) + 'email_archivos\';
      if FindFirst(mrut + '*.*', faAnyFile, SearchRec) = 0 then
      begin
        REPEAT
          IF (SearchRec.Name <> '.') AND (SearchRec.Name <> '..') THEN
            mfic := mfic + mrut + SearchRec.Name + ';';
        UNTIL FindNext(SearchRec) <> 0;
        FINDCLOSE(SearchRec);
      end;
      emailhtml(ts[1], ts[2], ts[3], strtointdef(ts[4], 0), ts[5], ts[6], ts[7], TS2.Text, mfic,'');
      TS2.Free;
El email ahora se ve igual tanto en Outlook como yahoo y gmail. (Era uno de los problemas del codigo anterior)
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Enviar un correo desde delphi HTML flystar Varios 0 25-05-2010 19:12:45
ENVIAR CORREO mi cuenta de correo es GMAIL ASAPLTDA PHP 1 16-11-2006 00:54:03
Problemas al Enviar Correo con Ciertas Dir. de Correo AGAG4 Internet 2 01-02-2006 20:37:42
Como enviar un correo en formato HTML TDworD Internet 0 20-11-2004 20:01:13
Como enviar correo HTML? JDNA Internet 3 15-05-2004 07:21:03


La franja horaria es GMT +2. Ahora son las 16:20:41.


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
Copyright 1996-2007 Club Delphi