I can't find a reason for it in the postfix settings, but duplicate emails are being sent, under different uid's. Looking at the email headers, they have unique ids, and each with a different Postfix, from userid
. For example, one says:
Received: by localhost.localdomain (Postfix, from userid 1000)
id AFFE880C9E43; Thu, 7 Mar 2024 03:04:02 -0800 (PST)
While the other says:
Received: by localhost.localdomain (Postfix, from userid 0)
id A076980CB3FD; Thu, 7 Mar 2024 03:04:02 -0800 (PST)
The mail logs show postfix/pickup
lines showing two uid's as well, and then the email being sent twice on the postfix/smtp
lines:
Mar 7 20:57:01 localhost postfix/pickup[1523368]: A0DA580CC916: uid=1000 from=<[email protected]>
Mar 7 20:57:01 localhost postfix/cleanup[1534353]: A0DA580CC916: message-id=<Aej4eFk4CtMsohU6wbxrlXigdloI53zuZDvecHneZ9Y@localhost>
Mar 7 20:57:01 localhost postfix/qmgr[1487578]: A0DA580CC916: from=<[email protected]>, size=1059, nrcpt=1 (queue active)
Mar 7 20:57:01 localhost postfix/pickup[1523368]: C74B180CB50F: uid=0 from=<[email protected]>
Mar 7 20:57:01 localhost postfix/cleanup[1534353]: C74B180CB50F: message-id=<jUeGOoaBFebz2tFQZEhCnoShgiL8EL0RhvaynFZKM@localhost>
Mar 7 20:57:01 localhost postfix/qmgr[1487578]: C74B180CB50F: from=<[email protected]>, size=1046, nrcpt=1 (queue active)
Mar 7 20:57:04 localhost postfix/smtp[1534359]: A0DA580CC916: to=<[email protected]>, relay=d96439a.ess.barracudanetworks.com[209.222.82.255]:25, delay=2.6, delays=0.19/0.01/0.41/1.9, dsn=2.0.0, status=sent (250 OK ([email protected]:250 Ok: queued as D76BE1180056))
Mar 7 20:57:04 localhost postfix/qmgr[1487578]: A0DA580CC916: removed
Mar 7 20:57:05 localhost postfix/smtp[1534363]: C74B180CB50F: to=<[email protected]>, relay=d96439b.ess.barracudanetworks.com[209.222.82.253]:25, delay=4.1, delays=0.09/0.01/0.47/3.5, dsn=2.0.0, status=sent (250 OK ([email protected]:250 Ok: queued as 933FB1180056))
Mar 7 20:57:05 localhost postfix/qmgr[1487578]: C74B180CB50F: removed
In the main.cf file, there is:
mydestination = $myhostname, localhost.$mydomain
Not sure what other settings are relevant.
Why would the emails be getting sent under two uid's? One is for the 'root' user, one for another user, but why are both being used? I've looked at the php files that send the emails, they are only sending one time. For testing, I used a vanilla html email format. Example:
$to = '[email protected]';
$subject = "A message for you";
$message = "Hello there!";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Test <[email protected]>';
if(mail($to, $subject, $message, implode("\r\n", $headers))) {
echo "E-Mail Sent";
} else {
echo "There was a problem";
}
The OS is AlmaLinux 9.3, basically a branch of RHEL.
EDIT:
In response to @dennis-nolte, "postconf -n" returns:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
meta_directory = /etc/postfix
milter_default_action = accept
mydestination = $myhostname, localhost.$mydomain
mynetworks = 127.0.0.0/8
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
sample_directory = /usr/share/doc/postfix/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtpd_milters = inet:localhost:8891
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_rbl_client zen.spamhaus.org, reject_rhsbl_reverse_client dbl.spamhaus.org, reject_rhsbl_helo dbl.spamhaus.org, reject_rhsbl_sender dbl.spamhaus.org
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
unknown_local_recipient_reject_code = 550
... and the /etc/aliases file contains a bunch of pseudo accounts listed as "root" and these at the end:
newsadm: news
newsadmin: news
usenet: news
ftpadm: ftp
ftpadmin: ftp
ftp-adm: ftp
ftp-admin: ftp
www: webmaster
webmaster: root
noc: root
security: root
hostmaster: root
info: postmaster
marketing: postmaster
sales: postmaster
support: postmaster
I confess I am clueless as to what to do with this info.
In response to @anx, how can I figure out who is generating the @localhost message-id? In the "postconf -n" response, there are a couple of references to "localhost" - inet_interfaces = localhost
and mydestination = $myhostname, localhost.$mydomain
- could one of those be the culprit?
Thanks for any help in tracking this down.
Your server appears unaware of its own name - but that is required for sending mail on the internet. Configure it according to the documentation of your distributions release.
Confirm the result by calling
hostname -s
: should output just the host name, thenhostname -f
: should output the fully-qualified domain name.The defaults for Postfix settings
myhostname
andmydomain
are typically appropriate as long as your hostname is, but do reviewmydestination
after the change.Please check for local redirects in f.e. /etc/aliases
Additionally there might be specific alias configuration in your main.cf which could result in this.
Note that you might have not reloaded/restarted postfix after configuration changes resulting in a different configuration beeing active instead of the one you expect.
postconf -n
might help you identify specifics of your configuration for this behaviour.Okay, it turns out that the problem had nothing to do with postfix, but was happening due to duplicate cronjobs (which I was unaware of), a root cronjob and a user cronjob (created by the same user that the emails are being sent by, though I don't think that matters).
In retrospect, I should have mentioned that a cronjob was triggering the email script, but I didn't think it mattered, since I didn't realize there was more than one.
So I eliminated the root cronjob, and the script is now only being triggered by the user cronjob, with good results and no duplication.
I hope this helps someone else avoid all the hours of googling and fiddling with postfix settings that I did!