Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: MessageParts.Count always 0 (zero)
| Subject: | Re: MessageParts.Count always 0 (zero) |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 2 Aug 2006 10:31:45 |
"Cornie" <cornievs@gmail.com> wrote in message
news:44cfceb9@newsgroups.borland.com...
> object Msg: TIdMessage
That is not the data I wanted to see. I wanted to see the raw email message
data that is being transmitted.
> Procedure TICXF.StartConnectionForMail(Mail:Boolean=True);
You should be using a repeat..until loop instead of a while loop when
looking for filenames.
Also, you are clearing the TIdMessage.Body but not the TIdMessage.Headers at
all.
Also, you are formatting the email wrong to begin with. You are storing the
text content into the Body property regardless of whether there are
attachments or not. You need to put the text into a TIdText object instead
if you use attachments. You also need to set the TIdMessage's ContentType
property accordingly.
Try this code instead:
procedure TICXF.StartConnectionForMail(Mail: Boolean = True);
var
I: Integer;
sFolder: String;
sr: TSearchRec;
begin
sFolder := ExtractFilePath(Application.ExeName) +
'\Data\InFoX\OutBox\';
MailSize := 0;
ToSend := TStringList.Create;
if FindFirst(Folder + '*.InfoX', faAnyFile and (not faDirectory),
sr) = 0 then
try
repeat
ToSend.Add(sFolder + sr.Name);
Inc(MailSize, sr.Size);
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
if ToSend.Count > 0 then
begin
with IdMsgSend do
begin
Clear;
From.Text := Data.SDS_CompanyINFOX_EMAIL.Value;
ReplyTo.EMailAddresses := From.Text;
Recipients.EMailAddresses :=
Data.SDS_CompanyINFOX_SERVER_MAIL.Value;
Subject := 'InfoStar InfoX Document - (' +
Data.SDS_CompanyINFOX_CODE.Value + ') - (' + DateTimeToStr(Now) + ')';
Priority := mpHighest;
ContentType := 'multipart/mixed';
with TIdText.Create(MessageParts, nil) do
begin
Body.Text := 'Sent by InfoStar Accounting.';
ContentType := 'text/plain';
end;
for I := 0 to ToSend.Count-1 do
begin
with TIdAttachmentFile.Create(MessageParts, ToSend[I])
do
ContentType := GetMIMETypeFromFile(FileName);
end;
end;
MailSize := Trunc(MailSize * 1.4);
end;
end else
Note('There are no packages to send.');
If Data.SDS_CompanyINFOX_DUN_MANUAL_DISC.Value <> 1 then
begin
if not Ras.RasAvailable then
begin
Note('Dial Networking not available');
Exit;
end;
RAS.EntryIndex := GetInfoXRasIndex;
if RAS.EntryIndex = -1 then
begin
Note('Your InfoX Dial-up Connection is invalid.' + CR +
'Please correct in the Company Setup -> InFoX');
Exit;
end;
If not Ras.Connected then
begin
Ras.Dial(Ras.EntryIndex);
Exit;
end;
SetStatus('Dial-up Connection already connected!');
end;
RasConnected(nil);
end;
> How is it possible to automatic parsing?
The TIdMessage.NoDecode property has to be set to False (its default value)
before retreiving the message data from the server. The message data will
automatically be parsed into the TIdMessage.Body or TIdMessage.MessageParts
property accordingly. Setting the NoDecode property to True disables the
parsing and will download the raw data as-is into the TIdMessage.Body
property without processing it.
Also, there is another condition that would cause the MessageParts.Count
property to be 0 when NoDecode is False - if the message data is not
MIME-encoded to begin with. In which case, all of the content will be
stored in the TIdMessage.Body property instead. Did you check for that yet?
Again, since you have not yet shown the actual message data, it is very
difficult to diagnose your problem.
> My main issue is still that Msg.MessageParts.Count is zero.
Then your message is not properly MIME-encoded to beign with. Again, please
show the actual message data.
Gambit