MIME problems with TIdSMPTServer -> File -> TIdSMTP -> Exchange Server

Giganews Newsgroups
Subject: MIME problems with TIdSMPTServer -> File -> TIdSMTP -> Exchange Server
Posted by:  Nicholas Ring (Nicholas.Ri…@smf.com.au)
Date: Wed, 7 Mar 2007

Hello,

What I need is a 'server' that stores emails, so later on it can send
to an Exchange server. The reason why we can't send directly to the
Exchange server is because it could be down for backup purposes. Doing
things this way gains us around two extra hours of overnight business
processing.

What I am trying to do is:
* In one thread, to use a TIdSMTPServer to get the emails, save them to
a directory, and
* In another thread, 'poll' the directory to see if there are any
emails waiting to be sent and attempt to send them to the Exchange
server. If a successful send occurs, the email is deleted from the
directory, otherwise a re-trying will occur later on.

The problem I am having is with MIME encoded emails... The message body
doesn't seem to make it to the server. In the exampe below, in OutLook
I get:

--- Msg Body Start ---
This is a multi-part message in MIME format
---- Msg Body End ----

And not

--- Msg Body Start ---
This is a test!
---- Msg Body End ----

As I would expect.

If I add

IdMessage.Encoding                  := meUU;

In my "Test Email" code, when the email is finally picked from the
Exchange server (after going through my server), I get the message body
that I expect to see.

What am I doing wrong with MIME encoding?

Cheers,
Nick

The (cut down) code that I am using is as follows:

--- Server Start ---
IdSmtpServer                        := TIdSMTPServer.Create(nil);
IdSmtpServer.NoDecode              := True;
IdSmtpServer.ReceiveMode            := rmMessageParsed;
IdSmtpServer.OnReceiveMessageParsed := IdSmtpServerReceiveMessageParsed;
IdSmtpServer.Active := True;
---- Server End ----

--- Resender Start ---
IdMessage := TIdMessage.Create(nil);
IdMessage.LoadFromFile(DirEmail + SearchRec.Name);

IdSMTP    := TIdSMTP.Create(nil);
IdSMTP.AuthenticationType := atNone

IdSMTP.Connect;
try
  IdSMTP.Send(IdMessage);
finally
  IdSMTP.Disconnect;
end;
FreeAndNil(IdSMTP);
[Set up SMTP

---- Resender End ----

--- Test Email Start ---
IdMessage                          := TIdMessage.Create(nil);
IdMessage.From.Text                := 'so…@address.com.au';
IdMessage.Recipients.EMailAddresses := 'so…@address.com.au';
IdMessage.Subject                  := 'Testing';
IdMessage.Body.Text                := 'This is a test!';

TIdAttachment.Create(IdMessage.MessageParts, 'C:\rfc821.txt.pdf');
TIdAttachment.Create(IdMessage.MessageParts, 'C:\rfc2821.txt.pdf');

IdSMTP                    := TIdSMTP.Create(nil);
IdSMTP.Host              := 'localhost';
IdSMTP.AuthenticationType := atNone;

IdSMTP.Connect;
try
  IdSMTP.Send(IdMessage);
finally
  IdSMTP.Disconnect;
end;
FreeAndNil(IdMessage);
FreeAndNil(IdSMTP);
---- Test Email End ----

--

Replies