Discussion:
Adding attachments to idMessage
(too old to reply)
Alistair
2005-06-01 02:47:05 UTC
Permalink
I have been pulling my hair out trying to figure out how to add an
attachment to an idMessage component (Delphi7). I can't find any examples
and the help files are just about useless. I can't figure out how everything
ties in together... If anyone has an example, or some suggestions, please
help. I get as far as:

IdMsgSend.create.MessageParts then I get lost. I know I am supposed to
create the idAttachments, but I have no idea how or where to do this...
Don
2005-06-01 04:26:46 UTC
Permalink
Post by Alistair
I have been pulling my hair out trying to figure out how to add an
attachment to an idMessage component (Delphi7).
For Indy 10:

//var AIdMessage: TIdMessage;
// AImgAtt: TIdAttachmentFile;
// AMemAtt: TIdAttachmentMemory;

AImgAtt := TIdAttachmentFile.Create(AIdMessage.MessageParts, 'c:\path\filename.jpg');
AMemAtt := TIdAttachmentMemory.Create(AIdMessage.MessageParts);

Indy 9 uses TIdAttachment and it's entirely file-based.

Sorry you find the help useless, but there are demos on both the Indy and AtoZed websites.
Post by Alistair
IdMsgSend.create.MessageParts then I get lost.
I have no clue what that is all about.
Alistair
2005-06-01 20:36:15 UTC
Permalink
I have now installed Indy 10. Now I get a different error when compiling my
.exe. "Unit idContext was compiled with a different version of
idSockethandle.TidSockethandle." In the uses section at the top of my code
page, IdExplicitTLSClientServerBase seems to be the problem... I can't
remove it either...
Post by Alistair
I have been pulling my hair out trying to figure out how to add an
attachment to an idMessage component (Delphi7).
For Indy 10:

//var AIdMessage: TIdMessage;
// AImgAtt: TIdAttachmentFile;
// AMemAtt: TIdAttachmentMemory;

AImgAtt := TIdAttachmentFile.Create(AIdMessage.MessageParts,
'c:\path\filename.jpg');
AMemAtt := TIdAttachmentMemory.Create(AIdMessage.MessageParts);

Indy 9 uses TIdAttachment and it's entirely file-based.

Sorry you find the help useless, but there are demos on both the Indy and
AtoZed websites.
Post by Alistair
IdMsgSend.create.MessageParts then I get lost.
I have no clue what that is all about.
Guillem
2005-06-02 08:52:52 UTC
Permalink
Hi,

you've got some old dcu file messing around. Assure you have get rid of all
Indy 9 files and recompile it
--
Best regards :)

Guillem Vicens
Dep. informática Green Service SA
www.clubgreenoasis.com
--
In order to send me a mail, remove the -nospam
Post by Alistair
I have now installed Indy 10. Now I get a different error when compiling my
.exe. "Unit idContext was compiled with a different version of
idSockethandle.TidSockethandle." In the uses section at the top of my code
page, IdExplicitTLSClientServerBase seems to be the problem... I can't
remove it either...
Alistair
2005-06-02 20:13:09 UTC
Permalink
Sorry if you thought I was multiposting... I thought it was a separate
issue...
Anyway, I have got rid of all indy 9 components, but still having issues.
var
MyList: TStringList;
Save_Cursor:TCursor;
AIdMessage: TIdMessage;
AImgAtt: TIdAttachmentFile;
AMemAtt: TIdAttachmentMemory;
Begin
MyList := TStringList.Create;
MyList.Add(Filename);
if not smtp1.Connected then
BEGIN
SMTP1.Host := editSMTPServer.Text;
SMTP1.Port := StrToInt(editSMTPPort.Text);
smtp1.Username := editSMTPName.Text;
SMTP1.Connect;
END;
with IdMessage do
begin
clearbody;
sender.Address := editFromAddress.Text;
From.Text := '***@mycompany.co.nz';
ReplyTo.EMailAddresses := '***@mycompany.co.nz';
Recipients.Add.Text := editToAddress.Text;
Recipients.EMailAddresses := editToAddress.Text;
Subject := 'file to send: - ' + extractfilename(FileName);
AImgAtt := TIdAttachmentFile.Create(AIdMessage.MessageParts, MyList);
AMemAtt := TIdAttachmentMemory.Create(AIdMessage.MessageParts);
end;

SMTP1.Send(frmMain.IdMsgSend);
SMTP1.Disconnect;
end;
Post by Guillem
Hi,
you've got some old dcu file messing around. Assure you have get rid of all
Indy 9 files and recompile it
--
Best regards :)
Guillem Vicens
Dep. informática Green Service SA
www.clubgreenoasis.com
--
In order to send me a mail, remove the -nospam
Post by Alistair
I have now installed Indy 10. Now I get a different error when compiling my
.exe. "Unit idContext was compiled with a different version of
idSockethandle.TidSockethandle." In the uses section at the top of my code
page, IdExplicitTLSClientServerBase seems to be the problem... I can't
remove it either...
Alistair
2005-06-02 21:12:59 UTC
Permalink
Forgot to mention my issue!
it says my TIdAttachmentFile is "Undeclared Identifier"...
Post by Alistair
Sorry if you thought I was multiposting... I thought it was a separate
issue...
Anyway, I have got rid of all indy 9 components, but still having issues.
var
MyList: TStringList;
Save_Cursor:TCursor;
AIdMessage: TIdMessage;
AImgAtt: TIdAttachmentFile;
AMemAtt: TIdAttachmentMemory;
Begin
MyList := TStringList.Create;
MyList.Add(Filename);
if not smtp1.Connected then
BEGIN
SMTP1.Host := editSMTPServer.Text;
SMTP1.Port := StrToInt(editSMTPPort.Text);
smtp1.Username := editSMTPName.Text;
SMTP1.Connect;
END;
with IdMessage do
begin
clearbody;
sender.Address := editFromAddress.Text;
Recipients.Add.Text := editToAddress.Text;
Recipients.EMailAddresses := editToAddress.Text;
Subject := 'file to send: - ' + extractfilename(FileName);
AImgAtt := TIdAttachmentFile.Create(AIdMessage.MessageParts, MyList);
AMemAtt := TIdAttachmentMemory.Create(AIdMessage.MessageParts);
end;
SMTP1.Send(frmMain.IdMsgSend);
SMTP1.Disconnect;
end;
Post by Guillem
Hi,
you've got some old dcu file messing around. Assure you have get rid of all
Indy 9 files and recompile it
--
Best regards :)
Guillem Vicens
Dep. informática Green Service SA
www.clubgreenoasis.com
--
In order to send me a mail, remove the -nospam
Post by Alistair
I have now installed Indy 10. Now I get a different error when compiling my
.exe. "Unit idContext was compiled with a different version of
idSockethandle.TidSockethandle." In the uses section at the top of my code
page, IdExplicitTLSClientServerBase seems to be the problem... I can't
remove it either...
Don
2005-06-02 21:57:33 UTC
Permalink
Post by Alistair
Forgot to mention my issue!
it says my TIdAttachmentFile is "Undeclared Identifier"...
TIdAttachmentFile is located in IdAttachmentFile.pas. Is it in your uses clause?
Alistair
2005-06-02 22:47:22 UTC
Permalink
Ok, I have it all compiling now, but get access violations when I run this
part:
TIdAttachmentFile.Create(AIdMessage.MessageParts, FileName);

This application wasn't originally written by me, and was written in D5. I
am using D7 to make modifications as the way the e-mailing worked then does
not apply now, and I have no experience doing this... and unfortunately for
me, it's urgent.
Post by Alistair
Forgot to mention my issue!
it says my TIdAttachmentFile is "Undeclared Identifier"...
TIdAttachmentFile is located in IdAttachmentFile.pas. Is it in your uses
clause?
Don
2005-06-02 23:30:30 UTC
Permalink
Post by Alistair
Ok, I have it all compiling now, but get access violations when I run this
TIdAttachmentFile.Create(AIdMessage.MessageParts, FileName);
Is AIdMessage a TIdMessage instance that has already been instantiated?

Is Filename a string variable?

Loading...