电子邮件发送的时间错误

电子邮件发送的时间错误

我对通过 mail.utils 发送的电子邮件的时间感到困惑。Thunderbird 显示的电子邮件发送日期比mail实际发送日期早 24 小时。

为了显示标题的差异,我从命令行发送了 2 封电子邮件。一封直接通过邮件发送,另一封通过 php 发送。

mike@wilma:/etc/mail$ echo "Test" | mail -a "X-datesent:$(date +'%H:%M:%S')" -s 'CLI test' [email protected]
mike@wilma:/etc/mail$ php -r 'mail("[email protected]", "PHP test", "test", "X-datesent:" . date("H:i:s")) ;'

生成的电子邮件标题mail

Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
    by mail.mike-mac.gen.nz (Postfix) with ESMTP id CD9DA2BC003C
    for <[email protected]>; Tue, 10 Oct 2023 01:16:31 +1300 (NZDT)
Received: from mail.mike-mac.gen.nz ([127.0.0.1])
    by localhost (wilma.mike-mac.gen.nz [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id TiMiAEKqCXmS for <[email protected]>;
    Tue, 10 Oct 2023 01:16:31 +1300 (NZDT)
Received: by mail.mike-mac.gen.nz (Postfix, from userid 1000)
    id B2D082BC003D; Tue, 10 Oct 2023 01:16:30 +1300 (NZDT)
X-datesent: 01:16:30
Subject: CLI test
To: <[email protected]>
User-Agent: mail (GNU Mailutils 3.14)
Date: Tue, 10 Oct 2023 01:16:30 -1100
Message-Id: <[email protected]>
From: Mike McIntyre <[email protected]>

使用 PHP 生成的电子邮件标题是

Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
    by mail.mike-mac.gen.nz (Postfix) with ESMTP id ECCD12BC003C
    for <[email protected]>; Tue, 10 Oct 2023 01:16:38 +1300 (NZDT)
Received: from mail.mike-mac.gen.nz ([127.0.0.1])
    by localhost (wilma.mike-mac.gen.nz [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id WrHE2C9CcL7b for <[email protected]>;
    Tue, 10 Oct 2023 01:16:38 +1300 (NZDT)
Received: by mail.mike-mac.gen.nz (Postfix, from userid 1000)
    id D60532BC003D; Tue, 10 Oct 2023 01:16:38 +1300 (NZDT)
To: [email protected]
Subject: PHP test
X-datesent:01:16:38
Message-Id: <[email protected]>
Date: Tue, 10 Oct 2023 01:16:38 +1300 (NZDT)
From: Mike McIntyre <[email protected]>

我能看到的唯一区别是在Date:标题中

追溯mail源头,获取版本

mike@wilma:/etc/mail$ which mail
/usr/bin/mail
mike@wilma:/etc/mail$ file /usr/bin/mail
/usr/bin/mail: symbolic link to /etc/alternatives/mail
mike@wilma:/etc/mail$ file /etc/alternatives/mail
/etc/alternatives/mail: symbolic link to /usr/bin/mail.mailutils
mike@wilma:/etc/mail$ file /usr/bin/mail.mailutils
/usr/bin/mail.mailutils: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f7eaf662d3c899c2ea6118af56f4709a9a1fae74, for GNU/Linux 3.2.0, stripped

mike@wilma:/etc/mail$ mail --version
mail (GNU Mailutils) 3.14
Copyright (C) 2007-2022 Free Software Foundation, inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

时区信息是

mike@wilma:/etc/mail$ timedatectl
               Local time: Tue 2023-10-10 01:28:02 NZDT
           Universal time: Mon 2023-10-09 12:28:02 UTC
                 RTC time: Mon 2023-10-09 12:28:02
                Time zone: Pacific/Auckland (NZDT, +1300)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

我正在使用 postfix 和 dovecot,如果它们有帮助的话。

干杯

麦克风

编辑#1

mike@wilma:~$ cat /etc/sysconfing/clock
cat: /etc/sysconfing/clock: No such file or directory
mike@wilma:~$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 36 Jun  5 15:51 /etc/localtime -> /usr/share/zoneinfo/Pacific/Auckland

编辑 #2
我在 crontab 中添加了以下行

*/5 * * * * echo "testing"

生成的电子邮件具有正确的时间,crontab 生成的错误电子邮件也是如此。

在不知道 crontab 如何生成电子邮件的情况下,我认为这将问题缩小到直接通过生成的电子邮件/usr/bin/mail.mailutils

编辑 #3 尝试用这个强制 TZ 值

mike@wilma:~$ cat /etc/profile.d/mailutils-date.sh 
# this is an attempt to fix the Date field in emails generated by mail.utils
if [ -z "${TZ}" ]
then
 TZ=`cat /etc/timezone`
 export TZ
fi
### after reboot ###
mike@wilma:~$ echo $TZ
Pacific/Auckland

相关内容