TIdEmailAddressItem undeclared
Hello,
If you use ShellExecute you use/start an external application to send your email.
So, this application can not handle attachments in the execute parameters.
(I wonder how you fill the body and the mail address details.. and if this is possible
why doesn't it support attachments too?)
Two ways to send email with Delphi is to use OLE Automation, like
using Outlook components (standard in Delphi) but for this you need Outlook.
Another way is to use special (free) email components like the Indy components:
{code}
procedure MyObject.SendMail;
var
IdSMTP: TIdSMTP;
IdMessage: TIdMessage;
IdEmailAddressItem: TIdEmailAddressItem;
IdAttachment: TIdAttachment;
begin
IdSMTP := TIdSMTP.Create(nil);
try
IdSMTP.Host := 'localhost';
IdSMTP.Port := 25;
IdSMTP.AuthType := satNone;//satDefault;
//IdSMTP.Username := 'username';
//IdSMTP.Password := 'password';
IdSMTP.Connect;
if IdSMTP.Authenticate then
begin
IdMessage := TIdMessage.Create(nil);
try
IdMessage.From.Name := 'No-Reply';
IdMessage.From.Address := '[email protected]';
IdMessage.Subject := 'E-Mail subject';
IdMessage.Body.Add('This is a message');
IdEmailAddressItem := IdMessage.Recipients.Add;
IdEmailAddressItem.Address := '[email protected]';
try
IdAttachment := TIdAttachmentFile.Create(IdMessage.MessageParts, 'c:\path\to\attachmentfile.doc');
IdSMTP.Send(IdMessage);
finally
IdAttachment.Free;
end;
finally
IdMessage.Free;
end;
end;
IdSMTP.Disconnect;
finally
IdSMTP.Free;
end;
end;
{code}
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line