Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Attachment problems by using Indy 10

1 view
Skip to first unread message

Z. Klencsar

unread,
Jun 8, 2008, 8:25:50 PM6/8/08
to
Hi!

I have downloaded the Indy 10 Delphi demo software project

http://www.indyproject.org/DemoDownloads/Indy_10_MailClient.zip

for IdPOP3 / IdSMTP / IdMessage (updated on the 6th February 2005) from
the site

http://www.indyproject.org/Sockets/Demos/index.EN.aspx

I compiled the project without change by using Delphi 2007 RC2 under
Windows XP SP2. I set the necessary Pop3 and SMTP settings, and sent an
E-mail to myself with one pdf file as attachment. The E-mail was sent,
but when I received the E-mail either by Thunderbird 2.0 or OE 6.0, the
attachment was not recognized: it was displayed as part of the body text
just like shown below:

********************************************
This is a multi-part message in MIME format

--uceCwi3=_SbZKIhfEaChAjcBu1b5YvKeuU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Try

--uceCwi3=_SbZKIhfEaChAjcBu1b5YvKeuU
Content-Type: application/octet-stream;
name="Flyer.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Flyer.pdf"

JVBERi0xLjYNJeLjz9MNCjQgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMTk3MTYwL08gNy9FIDE5
Mjk4OS9OIDEvVCAxOTcwMjAvSCBbIDE4OTYgMjkwXT4+DWVuZG9iag0gICAgICAgICAgICAgICAg...
**********************************************

How can one ensure (i.e. what should be changed in the settings or in
the program's source code) that the E-mail sent by the Indy demo program
becomes recognized automatically by these standard E-mail clients?

Also, I wrote my own sample program based on Indy 10 TIdMessage and
TIdSMTP components. This one can send simple text messages without any
problem. But when a file attachment is defined, then SMTP.SEND causes
the exception of 'Socket Error #10054 Connection reset by peer.'. What
could be the reason for that? (The attachment's size is small, so the
file size cannot be the problem.)

The relevant part of the code looks like the one below:

*****************************************
TIdText.Create(IdMessage.MessageParts,Memo.Lines);

{if the next line is removed, then the program works fine, a text
message is sent. if it is added as here, Socket Error #10054 occurs when
SMTP.Send(IdMessage) is called below, and as a result nothing is sent.}

TIdAttachmentFile.Create(IdMessage.MessageParts,'E:\Existingfile.bmp');


SMTP.AuthType:=atDefault;
SMTP.Username:=UserNameString;
SMTP.Password:=PassWordString;

SMTP.Host:=ServerName;
SMTP.Port:=25;

SMTP.Connect;

try
if SMTP.Authenticate then SMTP.Send(IdMessage);
finally
if SMTP.Connected then SMTP.Disconnect;
end;
******************************************

Any comment would be appreciated,

Zoltan

Remy Lebeau (TeamB)

unread,
Jun 9, 2008, 1:08:39 PM6/9/08
to

"Z. Klencsar" <z.kle...@somogy.hu> wrote in message
news:484c...@newsgroups.borland.com...

> I compiled the project without change by using Delphi 2007
> RC2 under Windows XP SP2.

Then you are using a very old version of Indy 10 and should consider
upgrading.

> The E-mail was sent, but when I received the E-mail either by
> Thunderbird 2.0 or OE 6.0, the attachment was not recognized:
> it was displayed as part of the body text just like shown below:

Please show the COMPLETE email data, including all top-level headers (the
Content-Type header in particular, which should be "multipart/mixed" in this
situation). For what you describe to happen, the TIdMessage component was
not configured properly for the type of email you want to send.

> Also, I wrote my own sample program based on Indy 10 TIdMessage
> and TIdSMTP components. This one can send simple text messages
> without any problem. But when a file attachment is defined, then
> SMTP.SEND causes the exception of 'Socket Error #10054 Connection
> reset by peer.'. What could be the reason for that? (The attachment's size
> is small, so the file size cannot be the problem.)

Actually, it could. The version of Indy you are using had a bug in the
TIdIOHandler.Write(TStream) method that would cause Indy to send too much
data to the socket at one time, causing all kinds of socket errors. That
was fixed in a later version.

> if SMTP.Authenticate then SMTP.Send(IdMessage);

Do not call Authenticate() manually like that. Send() does that internally
for you. Just call Send() by itself.

> if SMTP.Connected then SMTP.Disconnect;

Do not call Connected(). Call Disconnect() unconditionally.


Gambit


Z. Klencsar

unread,
Jun 11, 2008, 7:02:47 PM6/11/08
to
Dear Remy,

Thank you for your answer. Concerning the demo program you were
right: it did not set "multipart/mixed". Adding

IdMsgSend.ContentType:='multipart/mixed';

to

procedure TfrmMessageEditor.bbtnOkClick(Sender: TObject);

cured the problem.

Concerning my own program:

It seems that the problem is caused by the fact that I ported this
program from D7 to D2007. In a virgin program I can send attachments
with Indy 10 in D2007, but the same just does not work in the ported
program. As the latter was a small one, I think I will just rewrite it
in D2007 from scratch.

Thanks again,

Zoltan

Z. Klencsar

unread,
Jun 12, 2008, 7:56:26 PM6/12/08
to
Hi!

It turned out that I still cannot make Indy 10 (downloaded as latest
version on 11 of June, 2008) to work correctly. When an attachment is
defined, then the success of the send command depends on the content
(presumably mainly on the length) of the textual part (TIdText)! For
short body text (e.g. 'Body') everything is always fine, the E-mail is
sent with the attachment. For longer body text (several lines, around
700 characters) I keep getting (almost always: very rarely the E-mail is
sent correctly even in this case) the

'Socket Error #10054 Connection reset by peer.'

error when the TIdSMTP.Send(...) procedure is called.

(The Indy 10 demo shows the same effect if 'multipart/mixed' is set.)

Zoltan

Remy Lebeau (TeamB)

unread,
Jun 12, 2008, 9:12:05 PM6/12/08
to

"Z. Klencsar" <z.kle...@somogy.hu> wrote in message
news:4851b79e$1...@newsgroups.borland.com...

> It turned out that I still cannot make Indy 10 (downloaded
> as latest version on 11 of June, 2008) to work correctly.

You need to be more specific.

> When an attachment is defined, then the success of the send
> command depends on the content (presumably mainly on the length)
> of the textual part (TIdText)!

Sounds like you are still not setting up the TIdMessage properly before
sending it. Please show ALL of your actual code that deals with the
TIdMessage setup. The code you posted earlier is not enough to diagnose
your problem.


Gambit


Z. Klencsar

unread,
Jun 13, 2008, 1:45:08 PM6/13/08
to
Dear Gambit,

Below is the code that sets up TIdMessage and TIdSMTP in my program:

> IdMessage.Clear;
>
> if LB_Attachment.Count>0 then
> begin
> IdMessage.ContentType:='multipart/mixed';
>
> TIdText.Create(IdMessage.MessageParts,Memo_Email.Lines);
>
> for i:=0 to LB_Attachment.Count-1 do
> begin
> if FileExists(LB_Attachment.Items.Strings[i]) then
> With TIdAttachmentFile.Create(IdMessage.MessageParts,LB_Attachment.Items.Strings[i]) do
> begin
> ContentDisposition:='attachment';
> end
> else RaiseError('Could not find attachment: '+LB_Attachment.Items.Strings[i]);
> end;
> end
> else
> begin
> IdMessage.ContentType:='text/plain';
> IdMessage.Body.Text:=Memo_Email.Text;
> end;
>
> IdMessage.Subject:=LE_Subject.Text;
>
> IdMessage.From.Name:=LE_SenderName.Text;
> IdMessage.From.Address:=LE_SenderEmail.Text;
> IdMessage.ReplyTo.EMailAddresses:=LE_ReplyTo.Text;
>
> IdMessage.CCList.EMailAddresses:=LE_CC.Text;
> IdMessage.BccList.EMailAddresses:=LE_BCC.Text;
> IdMessage.Recipients.EMailAddresses:=ToEmail;
>
> SMTP.AuthType:=satDefault;
> SMTP.Username:=LE_UserName.Text;
> SMTP.Password:=LE_Password.Text;
> SMTP.Host:=LE_HostName.Text;
> SMTP.Port:=25;
> SMTP.HeloName:=LE_HeloName.Text;
>
> TRY
> SMTP.Connect;
>
> TRY
> SMTP.Send(IdMessage); {This causes 'Socket Error #10054 Connection reset by peer.' if there is an attachment.}
> EXCEPT
> ...
> END;
>
> FINALLY
> SMTP.Disconnect;
> END;

Zoltan

Z. Klencsar

unread,
Jun 13, 2008, 2:17:48 PM6/13/08
to
Dear Gambit,

Below is the code that sets up TIdMessage and TIdSMTP in my program:

(the rest of the settings are left as they are default)

> IdMessage.Clear;
>
> if LB_Attachment.Count>0 then
> begin
> IdMessage.ContentType:='multipart/mixed';
>
> TIdText.Create(IdMessage.MessageParts,Memo_Email.Lines);
>
> for i:=0 to LB_Attachment.Count-1 do
> begin
> if FileExists(LB_Attachment.Items.Strings[i]) then

> begin


> With TIdAttachmentFile.Create(IdMessage.MessageParts,LB_Attachment.Items.Strings[i]) do

Remy Lebeau (TeamB)

unread,
Jun 13, 2008, 6:44:57 PM6/13/08
to

"Z. Klencsar" <z.kle...@somogy.hu> wrote in message
news:4852b9c0$1...@newsgroups.borland.com...

> > SMTP.Send(IdMessage); {This causes 'Socket Error #10054
> Connection reset by peer.' if there is an attachment.}

Make sure you are using an up-to-date version of Indy. The version of Indy
that shipped with D2007 is outdated, and had a bug in it anyway when
transmitting TStream objects over a connection (which is what happens when
sending an attachment). The bug would enable write buffering, storing the
entire file in memory before sending it to the socket, causing socket errors
due to dumping too much data into it at a time. Sounds like you might be
hitting up on that bug. It was fixed in a later release of Indy.


Gambit


Z. Klencsar

unread,
Jun 14, 2008, 6:41:37 PM6/14/08
to
Dear Gambit,

When I right click on the TidSMTP or TidMessage components during
design time, it tells me that it is version Indy 10.2.3. I think that is
the latest version which I installed a few days ago.

Zoltan

0 new messages