Ian Branch 127 Posted June 6, 2021 Hi Team, D10.4.2, Indy 10. Trying to get an example from the internet working before I try to plug in my own parameters.. unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, Vcl.StdCtrls, IdEMailAddress, IdGlobal, IdAttachment, IdText, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL; type TForm2 = class(TForm) Button1: TButton; IdSMTP1: TIdSMTP; IdMessage1: TIdMessage; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; lSMTP: TIdSMTP; lMessage: TIdMessage; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; // to allow SSL authenticate // implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var lTextPart: TIdText; lImagePart: TIdAttachment; begin // ... here we need to set required properties for SMTP component. for moe visit How to send Email in Delphi?// lSMTP.Host := 'xxx'; lSMTP.AuthType := satDefault; lSMTP.Username := 'xxxx'; lSMTP.Password := 'xxxx'; lSMTP.Port := 587; lMessage.From.Address := 'yourGmailaddress@gmail.com'; lMessage.Subject := 'My test email with HTML body'; lMessage.Recipients.Add.Address := 'receipent@gmail.com'; lMessage.Body.Clear; // here we have initiated TIdtext object for plain text message in body// lTextPart := TIdText.Create(lMessage.MessageParts); lTextPart.Body.Text := 'This is a plain text message'; lTextPart.ContentType := 'text/plain'; // here we have initiated another TIdtext object for HTML text message in body// lTextPart := TIdText.Create(lMessage.MessageParts); lTextPart.ContentType := 'text/html'; lTextPart.Body.Text := '<html><body><b>Hello World</b><a href="htmlbodyIMG0000.JPG" ></body></html>'; // here we have initiated TIDAttachment object to add image file as attachment to mail as we have use this image in above HTML body message // lImagePart := TIdAttachment.Create(lMessage.MessageParts, 'htmlbodyIMG0000.JPG'); lImagePart.ContentType := 'image/jpg'; lImagePart.Headers.Add('Content-ID: <htmlbodyIMG0000.JPG>'); // if an image is used // // ... write your code to send a message for more visit How to send Email in Delphi? // lSMTP.Connect(); try lSMTP.Send(lMessage); ShowMessage('Email sent'); finally lSMTP.Disconnect(); end; // end; I have the following showing.. The 'note' for TIdAttachment is as follows.. The 'note' for 'htmlbodyIMG0000.JPG' is as follows.. The code is from 2016. Has there been a change around TIdAttachment since? If so, what should the line say/read? Regards & TIA, Ian Share this post Link to post
Lajos Juhász 293 Posted June 6, 2021 You can find information here: https://www.indyproject.org/2005/08/17/html-messages/ Share this post Link to post
Ian Branch 127 Posted June 6, 2021 Hi Lajos, Ahhh. Thank you. Regards, Ian Share this post Link to post
Remy Lebeau 1394 Posted June 7, 2021 (edited) Quote Has there been a change around TIdAttachment since? Yes. TIdAttachment is an abstract base class in Indy 10, it has no such constructor. You are looking for TIdAttachmentFile instead. I suspect the code you are trying to compile is actually meant for Indy 9, not 10. In Indy 9, TIdAttachment was a concrete class that only supported files. TIdAttachment was redesigned in Indy 10 to be a base class with new descendants introduced (TIdAttachmentFile, TIdAttachmentMemory, etc). Also, the structure of your email is not setup correctly for HTML, with images. The article Lajos linked to explains in detail how it should be setup. And Indy has a TIdMessageBuilderHtml class to help with this task, see https://www.indyproject.org/2008/01/16/new-html-message-builder-class/ Edited June 7, 2021 by Remy Lebeau 1 Share this post Link to post