[CentOS] Setting From address for cronjob mails (because Gmail rejects)

Fri Jan 20 08:47:27 UTC 2012
Alexander Dalloz <ad+lists at uni-x.org>

Am 20.01.2012 09:38, schrieb Alexander Farber:
> Hello,
> 
> I have two identical CentOS 6.2 machines with
> stock Postfix package and unchanged config:
> 
> # rpm -qa|grep post
> postfix-2.6.6-2.2.el6_1.x86_64
> 
> # postconf -n
> alias_database = hash:/etc/aliases
> alias_maps = hash:/etc/aliases
> command_directory = /usr/sbin
> config_directory = /etc/postfix
> daemon_directory = /usr/libexec/postfix
> data_directory = /var/lib/postfix
> debug_peer_level = 2
> html_directory = no
> inet_interfaces = localhost
> inet_protocols = all
> mail_owner = postfix
> mailq_path = /usr/bin/mailq.postfix
> manpage_directory = /usr/share/man
> mydestination = $myhostname, localhost.$mydomain, localhost
> newaliases_path = /usr/bin/newaliases.postfix
> queue_directory = /var/spool/postfix
> readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
> sample_directory = /usr/share/doc/postfix-2.6.6/samples
> sendmail_path = /usr/sbin/sendmail.postfix
> setgid_group = postdrop
> unknown_local_recipient_reject_code = 550
> 
> On both machines I have appended
> 
>      afarber:     Alexander.Farber at gmail.com
>      root:           Alexander.Farber at gmail.com
> 
> to the /etc/aliases and run "newaliases".
> 
> Both machines have several cronjobs and logwatch.
> 
> One machine is a database server,
> I receive its cronjob mails just fine.
> 
> The other machine (preferans.de) is running Drupal 7.
> I've configured it's MX records to point to Google Apps,
> so that I can receive mails addressed to that domain
> and this works well.
> 
> Also I've set Drupal's From address to
> webmaster at prеferans.de  and so sending mails
> by Drupal (for its user registration) works too.
> 
> But sending mails to my Gmail address by cronjobs
> doesn't work. I suspect this happens, because
> Google is too clever and it thinks
> that mails coming from "preferans.de"
> shouldn't have the From header set to
> "afarber at static.169.40.9.176.clients.your-server.de"
> 
> Jan 20 09:34:10 static sendmail[10577]: q0K8Y7mj010577: from=afarber,
> size=201, class=0, nrcpts=1,
> msgid=<201201200834.q0K8Y7mj010577 at static.169.40.9.176.clients.your-server.de>,
> relay=afarber at localhost
> Jan 20 09:34:10 static postfix/smtpd[10578]: connect from
> localhost.localdomain[127.0.0.1]
> Jan 20 09:34:10 static postfix/smtpd[10578]: 9B84B31EA0A1:
> client=localhost.localdomain[127.0.0.1]
> Jan 20 09:34:10 static postfix/cleanup[10581]: 9B84B31EA0A1:
> message-id=<201201200834.q0K8Y7mj010577 at static.169.40.9.176.clients.your-server.de>
> Jan 20 09:34:10 static sendmail[10577]: q0K8Y7mj010577: to=afarber,
> ctladdr=afarber (500/500), delay=00:00:03, xdelay=00:00:00,
> mailer=relay, pri=30201, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0,
> stat=Sent (Ok: queued as 9B84B31EA0A1)
> Jan 20 09:34:10 static postfix/qmgr[10025]: 9B84B31EA0A1:
> from=<afarber at static.169.40.9.176.clients.your-server.de>, size=823,
> nrcpt=1 (queue active)
> Jan 20 09:34:10 static postfix/smtp[10582]: connect to
> static.169.40.9.176.clients.your-server.de[176.9.40.169]:25:
> Connection refused
> Jan 20 09:34:10 static postfix/smtp[10582]: 9B84B31EA0A1:
> to=<afarber at static.169.40.9.176.clients.your-server.de>, relay=none,
> delay=0.14, delays=0.12/0.01/0.01/0, dsn=4.4.1, status=deferred
> (connect to static.169.40.9.176.clients.your-server.de[176.9.40.169]:25:
> Connection refused)
> 
> So does anybody please have an
> advice on how to fix my cronjob mails?
> 
> Regards
> Alex

Hi Alex,

the log shows a broken setup. The system is both using Sendmail *and*
Postfix. Most probably the fix is to run alternatives --config mta and
to select Postfix, to make sure all the symlinks are set properly. You
may even yum remove sendmail afterwards.

Relaying through Google, make sure that $myhostname is valid. Actually
it translates to your invalid hostname localhost with domain part
localdomain. Fix that!

Regards

Alexander