-4

Using Indy 10.1.5 (the version shipped with D2007), I'm composing and sending an email message as part of an automated internal process.

The email is sent fine, but when the recipient receives the message the time appears incorrectly in the email client, causing the message to incorrectly sort in the inbox. This has caused the recipient to overlook the message (because it wasn't in the inbox in the proper sequence and scrolled off the bottom), causing minor processing delays.

Both the sender and recipient in the US Eastern time zone (UTC -0400). The message header is correctly showing the message date, but without including a time zone:

Date: Mon, 3 Aug 2015 11:12:21 +0000

When the email is received and viewed in Outlook, the message is being shown with the UTC offset:

Mon 08/03/2015 7:12 AM

The code that creates the message is pretty simple (copied/pasted and then anonymized and simplified). It creates a relatively short message body (providing info about the file attached), creates the attachment, and sends the message. (try..except and try..finally removed for brevity - they exist in the actual code.)

Msg := TIdMessage.Create;
// Also tried using False and setting Date property manually
Msg.UseNowForDate := True;   
for i := 0 to NumAddr do     // Number of recipients
begin
  Msg.Recipients.Add;
  Msg.Recipients[Msg.Recipients.Count - 1] := RecipAddr[i];
end;
Msg.FromList.Add;
Msg.FromList[0].Name := Sender Name;
Msg.FromList[0].Address := SenderAddress;
Msg.Subject := 'Some text';
Msg.Body.Add('A few lines of text providing summary info.');
TIdAttachmentFile.Create(Msg.MessageParts, FileToAttach);

Mail := TIdSMTP.Create;
Mail.Host := PrimaryMailServer;
Mail.Connect;
Mail.Send(Msg);
Mail.Disconnect;

I've read through the Indy documentation and examined all of the properties I can find for both TIdSMTP and TIdMessage, and can't find anything else that would correct this time zone mismatch.

Can anyone see what it is I'm missing here?

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 2
    I believe there were some GMT related bugs in older versions of Indy 10. I'm sure Remy can provide better insights but I've seen old posts on different sites where users described this problem and he said that upgrading to the latest Indy build has the GMT fixes included. – Sam M Aug 03 '15 at 18:54
  • 1
    @SamM: what you said is exactly correct. Most importantly, there was a bug in Indy's `OffsetFromUTC()` function that retrieves the local machine's UTC offset, which is used when calculating the timestamp for outgoing emails. If you cannot upgrade to a newer version of Indy, you will have to set `TIdMessage.UseNowForDate` to false and provide your own `TIdMessage.Date` value that accounts for the faulty offset so the proper timestamp value gets sent. – Remy Lebeau Aug 03 '15 at 22:18
  • 2
    @RemyLebeau - why not post the comment as an answer? – RBA Aug 04 '15 at 06:43

1 Answers1

2

10.1.5 is an outdated version of Indy 10. The current version is 10.6.2.

There were some UTC related bugs in earlier versions of Indy 10. In this case, there was a bug in Indy's OffsetFromUTC() function, which retrieves the local machine's UTC offset and is used when calculating the timestamp for outgoing emails. You should upgrade to a modern version of Indy 10, so you have the latest fixes, features, architectural changes, etc.

If you cannot upgrade, you will have to set the TIdMessage.UseNowForDate property to false and provide your own timezone-adjusted TDateTime value in the TIdMessage.Date property to account for Indy's faulty offset, so a proper timestamp value is sent.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770