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?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source