Este ejemplo muestra cómo enviar mensajes de correo electrónico HTML y utilizando Delphi Indy, con imágenes incrustadas.


 usos 
IdMessage;

procedimiento TForm1.Button1Click (Sender: TObject);
var
Html: TStrings;
Htmpart, txtpart: TIdText;
Bmppart: TIdAttachment;
Correo electrónico: TIdMessage;
Nombre de archivo: string;
empezar
Nombre de archivo: = ExtractFilePath (Application.ExeName) + 'us.jpg';

html: = TStringList.Create ();
html.Add ( '<html>');
html.Add ( '<head>');
html.Add ( '</ head>');
html.Add ( '<body> <h1> Hola </ h1>');
html.Add ( '<img src="cid:us.jpg" />');
html.Add ( 'Esta es una foto de nosotros! </ body>');
html.Add ( '</ html>');

correo electrónico: TIdMessage.Create = (nil);
email.From.Text: ="Pete@NooooSpammmm.Droopyeyes.com ';
email.Recipients.EMailAddresses: = 'Pete@NoooSpammmm.droopyeyes.com';
email.Subject: = 'Hola';
email.ContentType: = 'multiparte / mixto ";
email.Body.Assign (html);

txtpart: = TIdText.Create (email.MessageParts);
txtpart.ContentType: = 'text / plain ";
txtpart.Body.Text: ='';

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

bmppart: = TIdAttachment.Create (email.MessageParts, filename);
bmppart.ContentType: = "image / jpeg ';
bmppart.FileIsTempFile: = true;
bmppart.ContentDisposition: = 'en línea';
bmppart.ExtraHeaders.Values [ 'contenido-id']: = 'us.jpg';
bmppart.DisplayName: = 'us.jpg';

intentar
idSMTP.Connect ();
intentar
idSMTP.Send (correo electrónico);
ShowMessage ( 'Enviado');
excepto
sobre E: Exception do
ShowMessage ( 'Error:' + E. Mensaje);
final;
finalmente
idSMTP.Disconnect ();
email.Free ();
html.Free ();
final;
final;

Average rating: