BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to send binary file attachment with Indy (D7)?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Bo Berglund
Guest





PostPosted: Fri Sep 19, 2003 7:45 pm    Post subject: How to send binary file attachment with Indy (D7)? Reply with quote



I am trying to understand how to attach a binary file to an email
message using Indy9 TIdSmtp and TIdMessage. I need to send
automatically a PDF file from a document handling system when the user
updates the document. I have sent alerts this way before but without
any attachments.
Now I get confused reading the Indy help for the TIdMessage and really
I need a simple down-to-earth sample on how I can add a file from disk
to the message such that it will be attached when it is sent out.
The main message is a simple plaintext one with only some processing
codes.

Then on the other side using the TIdPOP3 component, how do I extract
the attachment back to a disk file?

Hope someone can help even if this has been asked a lot before. I
*have* googled but it did not turn up any code samples for my problem.

/Bo

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Sep 19, 2003 7:57 pm    Post subject: Re: How to send binary file attachment with Indy (D7)? Reply with quote




"Bo Berglund" <bo.berglund (AT) mailbox (DOT) swipnet.se> wrote

Quote:
I am trying to understand how to attach a binary file to an email
message using Indy9 TIdSmtp and TIdMessage.

Simply add a TIdAttachment instance to the TIdMessage::MessageParts
collection, ie:

with TIdAttachment.Create(IdMessage1.MessageParts, 'c:\somefile.pfd')
do
begin
ContentType := 'application/pdf';
FileName := 'somefile.pdf';
end;

Quote:
Then on the other side using the TIdPOP3 component, how
do I extract the attachment back to a disk file?

Again, use the MessageParts collection. Look for TIdAttachment instances
and use the TIdAttachment::SaveToFile() method when needed, ie:

var
i: Integer;

for i := 0 to IdMessage1.MessageParts.Count-1 do
begin
if (IdMessage1.MessageParts[i] is TIdAttachment) then
begin
with (IdMessage1.MessageParts[i] as TIdAttachment) do
SaveToFile('c:\' + FileName);
end;
end;


Gambit




Back to top
Bo Berglund
Guest





PostPosted: Fri Sep 19, 2003 8:16 pm    Post subject: Re: How to send binary file attachment with Indy (D7)? Reply with quote



Thanks I will try that for sure,
but now I have a follow-up question:
You write that I should set ContentType:='application/pdf'.
Is this string one of a number of official strings and if so where can
I find all available strings?
For example if I have a proprietary binary file named like:
mybinaryfile.xyzbin
which is used as data in some application, then what would be the
proper string to set?
'application/xyzbin' or what?

What does the application part mean?

A bit confused...

/Bo

On Fri, 19 Sep 2003 12:57:10 -0700, "Remy Lebeau (TeamB)"
<gambit47 (AT) yahoo (DOT) com> wrote:

Quote:

"Bo Berglund" <bo.berglund (AT) mailbox (DOT) swipnet.se> wrote in message
news:3immmvs0l35vrdtqrjrb3njsg4fj1aqpur (AT) 4ax (DOT) com...
I am trying to understand how to attach a binary file to an email
message using Indy9 TIdSmtp and TIdMessage.

Simply add a TIdAttachment instance to the TIdMessage::MessageParts
collection, ie:

with TIdAttachment.Create(IdMessage1.MessageParts, 'c:\somefile.pfd')
do
begin
ContentType := 'application/pdf';
FileName := 'somefile.pdf';
end;

Then on the other side using the TIdPOP3 component, how
do I extract the attachment back to a disk file?

Again, use the MessageParts collection. Look for TIdAttachment instances
and use the TIdAttachment::SaveToFile() method when needed, ie:

var
i: Integer;

for i := 0 to IdMessage1.MessageParts.Count-1 do
begin
if (IdMessage1.MessageParts[i] is TIdAttachment) then
begin
with (IdMessage1.MessageParts[i] as TIdAttachment) do
SaveToFile('c:\' + FileName);
end;
end;


Gambit



Back to top
Ignacio Vazquez
Guest





PostPosted: Fri Sep 19, 2003 8:53 pm    Post subject: Re: How to send binary file attachment with Indy (D7)? Reply with quote

"Bo Berglund" <bo.berglund (AT) mailbox (DOT) swipnet.se> wrote in message
[email]aoommv0uogadlltclqfbf2sclbpt9g8vld (AT) 4ax (DOT) com[/email]...
Quote:
Is this string one of a number of official strings and if so where can
I find all available strings?

Yes.

ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/

Quote:
For example if I have a proprietary binary file named like:
mybinaryfile.xyzbin
which is used as data in some application, then what would be the
proper string to set?
'application/xyzbin' or what?

No. It depends on the application, although application/x-xyzbin might be
allowed (the x- represents a non-standard MIME type).

Quote:
What does the application part mean?

That it's a data file for a specific application.

Cheers,
Ignacio

--
No, don't send me e-mail directly. No, just don't.




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Sep 19, 2003 9:14 pm    Post subject: Re: How to send binary file attachment with Indy (D7)? Reply with quote


"Bo Berglund" <bo.berglund (AT) mailbox (DOT) swipnet.se> wrote


Quote:
You write that I should set ContentType:='application/pdf'.
Is this string one of a number of official strings

For the PDF format, yes.

Quote:
and if so where can I find all available strings?

I got it from the Windows Registry for the .pdf file extension.

Quote:
For example if I have a proprietary binary file named like:
mybinaryfile.xyzbin
which is used as data in some application, then what would
be the proper string to set?

Indy has a TIdMIMETable class for helping with that. Indy provides a global
GetMIMETypeFromFile() function that accesses it for you for ths specific
purpose. For example:

ContentType := GetMIMETypeFromFile('c:mybinaryfile.xyzbin');

Quote:
'application/xyzbin' or what?

No, unless that is the official registered content type for that format,
which may or may not be the case.


Gambit




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.