TIP [DELPHI] – Inviare una mail utilizzando le classi Indy
Piccolo esempio base, per l’invio di una mail utilizzando la classe Indy TidMessage :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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 := '<html><body><center><b>This is a HTML message with picture</b><BR><img src="cid:02.JPG" ></center></body></html>'; 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; |