Dimsn
0
Q:

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}
0

New to Communities?

Join the community