My Alma9 server is simplistic, just a vehicle to hold my web pages and other simple stuff. The only users are my unwashed self and root.
This server does not have a domain name, so emails from root through cron and logwatch use the information in /etc/aliases for sending. But because mail builds the replyto name from the info in
/etd/postfix/main.cf
and the real hostname doesn’t have a domain, mails get rejected by the MX that I send through.
If I play around on the CL I can use the -r option to spoof the reply-to address and then the mail will go out OK. However I don’t see a way to apply that type of option in general to the root user.
Is there some way in the main.cf file to specify a generic REPLYTO, or a way to make an environment var for root that will work for these auto mail things like logwatch and cron jobs w/o a shell var? Or is there a way to apply the -r option via the aliases file?
I know about setting the MAILTO= in the cron file but again they get rejected because of the reply to doesn’t have a real domain.
I’ve come up dry on the web, any suggestions/options appreciated.
I have a SLURM cluster. The jobs can send mail to users via SLURM controller. The sender would be: slurm@slurmctl.localdomain. Obviously, the MX (outside) does not like that. We did end up running Ansible tasks:
- ansible.builtin.include_role:
name: rhel-system-roles.postfix
- name: Add to generic Postfix map
ansible.builtin.blockinfile:
path: /etc/postfix/generic
block: |
{{ item.key }} {{ item.value }}
with_dict: "{{ postfix_generic }}"
when:
- postfix_generic is defined
- postfix_generic|length > 0
register: postfix_generic_map
- name: Rehash generic Postfix map
ansible.builtin.command: "postmap /etc/postfix/generic"
when: postfix_generic_map.changed
with variables:
postfix_conf:
smtp_generic_maps: "hash:/etc/postfix/generic"
relayhost: "[smtp.mydomain]"
postfix_backup_multiple: true
postfix_generic:
"slurm@slurmctl.localdomain": "noreply@mydomain"
I don’t know postfix, but the above seems to work for us; the noreply@mydomain is a valid sender. Whether root needs different/special treatment is beyond me.
Thanks for the suggestions and the scripting, Jukka! I don’t know anything about ansible, I’ll have to do some homework on that and see if I can make it go.
The /etc/postfix/generic exists by default and has commented examples in it. You can add one line, and then run postmap /etc/postfix/generic update corresponding /etc/postfix/generic.db
I don’t actually how the rhel-system-roles.postfix (from package rhel-system-roles) updates the config of postfix regarding the “SMTP generic maps” and “relayhost”, but you probably do know how to do those “manually” (without Ansible).
T hanks again for your help. I had not noticed the default generic. Yes, I’ll dig into that and can probably make it go. I’ll report back if I get it figured out in detail.
Good suggestions but I have found a simple solution for my needs.
To recap - I need to be able to have root-activated emails go out from a server w/o a real domain.
The solution for me was to modify some setting in
/etc/postfix/main.cf
In that file there are three settings of interest to this issue, myhostname, mydomain, and myorigin. Assume that the local host with no qualified domain is named LocalH and the external domain that is in existence is called ExternH, then the settings I ended up with look like:
myhostname = LocalH.com
mydomain = LocalH.com
myorigin = ExternH.com
where you would insert .com or .org or whatever is proper for your external FQD. With these settings any outgoing mail takes the myorigin data as both the ReplyTo address and the From address for message and it also pre-pends the current user so the actual From/ReplyTo looks like
User@ExternH.com
External MX’s seem to like this and see it as a real domain and pass the message.
The only catch is that if you have a server with multiple users, which I do not, is that everyone is getting that From/ReplyTo address.
1 Like
Nice. I did found an example for how to set those variables with Ansible Automating Postfix installation and configuration with RHEL System Roles
One would need packages ansible-core and rhel-system-roles for that.
Good find. Ansible looks to be a really good tool. Note that I made a small modification to my post in that the settings affect both the From and the ReplyTo signatures.