Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

TIP [DELPHI] – Inviare una mail utilizzando le classi Indy

Digital Innovation Partner

TIP [DELPHI] – Inviare una mail utilizzando le classi Indy

Piccolo esempio base, per l’invio di una mail utilizzando la classe Indy TidMessage :


documentazione originale :

{http://www.dragonsoftru.com/articles/indy-email.html#part_3_4}

function TDmMail.SendHtmlMessage(AddrFrom, AddrTo, Subject, Body, AttachFiles: String): Boolean;
Var
Idm : TIdMessage;
TSFiles : TStringList;
IdA : TIdAttachment;
I : Integer;
lTextPart : TIdText;
lImagePart : TIdAttachment;

begin
IdSMTP.Connect(4000);
IdSMTP.Username := ‘ivo il tardivo’;
Idm := TIdMessage.Create(Self);

Idm.From.Address := ‘myemail@mydomain.com’;
Idm.Subject := ‘My test email’;
Idm.Recipients.Add.Address := ‘someoneemail@somedomain.com’;
Idm.Body.Clear;
lTextPart := TIdText.Create(Idm.MessageParts);
lTextPart.Body.Text := ‘This is a plain text message’;
lTextPart.ContentType := ‘text/plain’;
lTextPart := TIdText.Create(Idm.MessageParts);
lTextPart.Body.Text := ‘

This is a HTML message with picture
‘;
lTextPart.ContentType := ‘text/html’;
lImagePart := TIdAttachment.Create(Idm.MessageParts, ‘c:\02.JPG’);
lImagePart.ContentType := ‘image/jpg’;
lImagePart.Headers.Add(‘Content-ID: <02.JPG>‘);
IdSMTP.Send(Idm);
IdSMPT.Disconnect;
end;

Lascia un commento