Re: Time wrong in Message Header sent Via Indy TIdSMTP 10.1.5

Giganews Newsgroups
Subject: Re: Time wrong in Message Header sent Via Indy TIdSMTP 10.1.5
Posted by:  kgmccoydt (kgmccoy…@idk-inc.com)
Date: Tue, 18 Sep 2007

Rob Hoyer wrote:
> I have setup a program to send support email message.  Everything is working
> great except the email message sent time is wrong.  I set the
> TIdMessage.Date := Now() but the header contains the following date line:
> Date: Mon, 17 Sep 2007 11:18:06 +0000,  I assume that the +0000 meams GMT
> and that would explain why the email message says is was sent at 4:18 am.
> Other messages that are working correctly report the following Date: Sun, 16
> Sep 2007 22:16:31 -0700 translation 10:16 PM.

As you found out, you need to account for the local time zone and
daylight savings time, if any.

Try something like this:

USES
    WINDOWS;

..
..
..
CONST
    MinutesInDay    = 1440;        {Number of minutes in a day}

VAR
    Status :      DWORD;
    Info :        TTimeZoneInformation;
    IdMsgSend :    TIdMessage;
    SMTP :        TIdSMTP;
BEGIN
..
..
..
    Status                  := GetTimeZoneInformation(Info);
    IdMsgSend.Date          := Now + (Info.bias / MinutesInDay);
    IdMsgSend.UseNowForDate := False;
    SMTP.Send(IdMsgSend);
..
..
..

The above obviously won't compile, but it does show how to offset local
time properly in an SMTP header. This code automatically tracks daylight
savings time and also when the user changes the time zone in Windoze.

HTH,

Kevin G. McCoy

Replies

In response to

Time wrong in Message Header sent Via Indy TIdSMTP 10.1.5 posted by Rob Hoyer on Mon, 17 Sep 2007