Sending HTML emails with Indy

, \t\t , This example shows how to send HTML emails using Delphi and Indy, with embedded images.,,, ,,, uses,  idMessage;,,procedure TForm1.Button1Click(Sender: TObject);,var,  html: TStrings;,  htmpart, txtpart: TIdText;,  bmppart: TIdAttachment;,  email: TIdMessage;,  filename: string;,begin,  filename := ExtractFilePath(Application.ExeName) + 'us.jpg';,,  html := TStringList.Create();,  html.Add('<html>');,  html.Add('<head>');,  html.Add('</head>');,  html.Add('<body><h1>Hello</h1>');,  html.Add('<img src="cid:us.jpg" />');,  html.Add('This is a picture of us!</body>');,  html.Add('</html>');,,  email := TIdMessage.Create(nil);,  email.From.Text := '[email protected]'; , ,  email.Recipients.EMailAddresses := '[email protected]';,  email.Subject := 'Hello';,  email.ContentType := 'multipart/mixed';,  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 := 'inline'og,   bmppart. extraheaders. værdier ['content-id ']: = os. jpg «,   bmppart.displayname: = os. jpg,,,   prøve,     idsmtp. connect();,     prøve,       idsmtp. send (e - mail),       showmessage ('sent),     undtagen,       på e: undtagelse,         showmessage ('failed: + e.message),    ;,   endelig     idsmtp. disconnect();,     e - mail. free();,     html. free();,  ;,;,,,,,  ,,,,



Previous:
Next Page: