 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
dpap Guest
|
Posted: Sat Mar 19, 2005 9:11 am Post subject: Help on idSMTP |
|
|
Hi,
Bellow is the full source code of my test SMTP application (Delphi 5 ent,
Indy 10.0.52).
===================================================================
unit UnitMail1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
IdMessage, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP,IdText,
IdAttachmentFile,IdGlobalProtocols,StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
IdSMTP1: TIdSMTP;
IdMsg: TIdMessage;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
var x : string;
begin // code to generate a simple text file for attachment
with TFileStream.Create('testfile.txt',fmCreate) do begin
x := 'first line of text'#13#10;
writebuffer(x[1],length(x));
x := 'second line of text'#13#10;
writebuffer(x[1],length(x));
x := 'third line of text';
writebuffer(x[1],length(x));
free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
tmpStr : string;
i : integer;
begin
randomize;
with IdMsg do begin
clear;
MessageParts.Clear;
contentType := 'mutipart/mixed';
Charset := 'GREEK_CHARSET';
with TidText.Create(MessageParts) do begin
ContentType := 'text/plain';
Charset := 'GREEK_CHARSET';
Body.Text := 'some text '+floatToStr(random); // to make unique
strings
end;
From.name := 'myname';
From.Address := 'sombody (AT) somesite (DOT) com';
Recipients.add.Address := 'dpap (AT) softwaypro (DOT) gr';
Subject := 'my subject '+floatToStr(random); // to make unique
subject
Priority := mpHigh;
with TIdAttachmentFile.Create(MessageParts,'testfile.txt') do begin
ContentType := GetMIMETypeFromFile(StoredPathName);
end;
end;
// hostname,username, password (and nothing else) defined at the component
pallete
try
IdSMTP1.Connect;
try
IdSMTP1.Send(IdMsg);
finally
IdSMTP1.Disconnect;
end;
except
end;
close;
end;
end.
========================================
with this code I receive the mail with a attached file with the contents
bellow
==========================================
This is a multi-part message in MIME format
--13yd=_lbwldDkhD1IKjOGiBXzTyGmuWI4b
Content-Type: text/plain ; charset="GREEK_CHARSET"
Content-Transfer-Encoding: quoted-printable
some text 0,547443638788536
--13yd=_lbwldDkhD1IKjOGiBXzTyGmuWI4b
Content-Type: text/plain;
name="testfile.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="testfile.txt"
Zmlyc3QgbGluZSBvZiB0ZXh0DQpzZWNvbmQgbGluZSBvZiB0ZXh0DQp0aGlyZCBsaW5lIG9mIHRl
eHQ=
--13yd=_lbwldDkhD1IKjOGiBXzTyGmuWI4b--
=========================================
with other code combinations I receive the attached file as the real file
but without the body or body without attachment or body and the contents of
attachment file together
Also I notice that, if the attachment file doesn't exist the application
stucks at the instruction disconnect (!) not earlier (eg at
TIdAttachmentFile.Create)
What is my fault at the above code ?
Is there a detailed document about Indy10 components ?
thanks in advance
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Mar 19, 2005 10:08 am Post subject: Re: Help on idSMTP |
|
|
"dpap" <dpap (AT) softwaypro (DOT) gr> wrote
| Quote: | clear;
MessageParts.Clear;
|
You don't need to clear the MessageParts separately. TIdMessage.Clear()
does clear the MessageParts as well.
| Quote: | contentType := 'mutipart/mixed';
|
You misspelled the string value. It should be the following:
ContentType := 'multipart/mixed';
| Quote: | with TIdAttachmentFile.Create(MessageParts,'testfile.txt') do
begin |
That is not a valid filename. You omitted the drive, ie:
with TIdAttachmentFile.Create(MessageParts,'c:testfile.txt') do begin
| Quote: | with this code I receive the mail with a attached file with the
contents bellow
|
You did not show the main headers. Those are just as important as the
message's content.
Gambit
|
|
| Back to top |
|
 |
dpap Guest
|
Posted: Sat Mar 19, 2005 10:58 am Post subject: Re: Help on idSMTP |
|
|
Thanks again Remy
my blindness was the guilty.
now are all ok
| Quote: | contentType := 'mutipart/mixed';
You misspelled the string value. It should be the following:
ContentType := 'multipart/mixed';
|
|
|
| Back to top |
|
 |
|
|
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
|
|