Setting up sendmail to work as a client only? - email

We are running sendmail-8.13.4 on AIX.
I need to update the configuration and make sendmail act as a relay client only, meaning it will only be used to send mail out of the host and NOT accept mail.
Here is my client.mc config:
include(`/usr/samples/tcpip/sendmail/m4/cf.m4')
VERSIONID(`sendmail config for aix7')
OSTYPE(`aixsample')dnl
MASQUERADE_AS(`myserver.com')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`accept_unresolvable_domains')
FEATURE(`accept_unqualified_senders')
FEATURE(always_add_domain)dnl
FEATURE(`nullclient',`mail-relay.xxxx.myserver.com')dnl
define(`STATUS_FILE', `/etc/mail/statistics')dnl
define(`MAIL_HUB', `myserver.com.')dnl
define(`LOCAL_RELAY', `myserver.com.')dnl
We have an MS Exchange server, so we are basically using sendmail on a particular AIX host to forward all email to the exchange server and let Exchange handle everything.
The above configuration works fine for sending email to recipients
mail user#myserver.com
What I also need to do is be able to send the email with only specifying the alias part and not the domain, so if I do:
mail user (omitting the #myserver.com recipient domain part)
I want sendmail to append the #myserver.com in this situation where a domain is not given. Is this possible without maintaining some sort of alias/list file for every possible userid > userid#mydomain.com?
Thanks.

You can use approach mentioned in sendmail FAQ 4.22 - make sendmail accept smtp connections only on (local) loopback ip interface.
Sendmail FAQ 4.22 : Why can't I receive external mail?
It may be achieved by the following lines in sendmail.mc file used to generated sendmail.cf file:
dnl Do no listen on msa(587) port
FEATURE(`no_default_msa')dnl
dnl Listen on IPv6 loopback address
dnl DAEMON_OPTIONS(`Family=inet6, Name=MTA-v6, Port=smtp, Addr=::1')dnl
dnl Listen on IPv4 loopback address
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl

Related

Postfix attempting to bind to port 25, used for outgoing mail only (maybe not necessary?)

Not sure if this belongs on Stack Overflow or somewhere else but I'll try here first.
I have multiple servers, each with the same setup where nearly everything running on the server is in a docker container. I have two goals I would like to achieve. First, the host machine is setup to send emails for users with uid < 1000 to my external email address. Second, on one server, I have a docker-mailserver container running to handle random, seldom used emails (for log files, etc.).
It seems I can have either the host machine running postfix OR the docker-mailserver running (and bound to port 25). Currently, I have the docker container, running the mail server, full operational and everything can send and receive just fine.
However, now I am unable to start postfix on the host machine so that I can receive emails sent to the root user (things like cron output) since port 25 is --rightfully-- in use by the actual mail server receiving email.
Questions:
1) How can I tell postfix on the host to not bind to port 25? If port 25 is only used for receiving mail, why would my outgoing-only postfix config need to use port 25?
2) I am perfectly comfortable not receiving emails for the root user, if whatever would normally be sent to the root user is logged elsewhere (perhaps, syslog?). Are the emails to root only maintained as emails or are they somewhere else, negating the need for postfix on the host for forwarding to a real account?
Thanks in advance.
Specifically answering your questions first:
You should be able to have postfix listen on any port you specify by editing the main.cf configuration file and changing the smtp listener to a numbered port of your choice. Of course, if it isn't a "known" port, I'm not sure what/who will ever connect to it, but maybe you don't care in this situation as you are only using postfix as a relay?
It may depend some on the Linux distribution or setup of your host, but most systems will leave email in the local delivery "mail spool" if there is no system/daemon set up to move it anywhere else. Back when that was the normal way to handle multi-user mail on UNIX systems, a login user used a mail reader client to read through email in your local "spool", and of course if you don't have that, you can simply vi your mail file and read the raw contents if necessary. These mail files are normally located in /var/spool/mail on most systems.
Stepping away from your questions, I would guess you don't necessarily need postfix running on your host, especially as your containerized mailserver is handling the port 25 SMTP traffic for the host. Local email will stay local, I assume, without postfix, and be available through local means; and you might even find a simpler solution to external forwarding (e.g. a script that can parse mail spools and just connect to an SMTP relay and send it to an external address) if you want that.

Postfix: loops back to myself error

I've been trying to install a Postfix server for handling mail for my domain. I found some nice tutorial and I was able to create email address and server responds correctly with telnet (imap and pop3 included, I also charge the config in Gmail and works correctly).
To handle POP3 and IMAP I have installed Courier
The problem comes when I try to send e-mails to myself (with external email address), I receive the following error code:
Action: failed
Status: 5.4.6
Diagnostic-Code: X-Postfix; mail for (servername) loops back to
myself
I reviewed my postfix mail.conf config, as in many webs they said that it could be because mydestination was not corectly configured. I have included the domain configuration and I still get the same error. (/etc/postfix/main.cf)
mydestination = mail.mydomain.com, domain.com, localhost
This is in a VPS, so the hostname is different to the domain name, I'm not sure if this can have any influence on the handling mail error.
Could someone help me to find where can the error be?
Thanks for your attention and your answers
You're probably sending mail to a recipient, with an email address in a zone which has an MX record, with its value a hostname, which resolves to the ip address of your mailserver, while this your server hasn't been told in its main.cf config file (behind mydestination), that it is referring to itself.
Therefore, your server is wondering why an attempt to send mail to - as it believes - another server results in finding that the ip address of that another server is its own ip address.
Update mydestination accordingly.
It helps to use the same hostname for MX record, for all zones your mailserver handles incoming mail for, as that keeps your mydestination manageable.

Postfix to send all mail to /dev/null except one address (alias)

My postfix server is working on a particular domain name through a relay, so it's like that:
Client send to abs#subdomain.domain.com -> domain.com production mail server -> internal mail server on subdomain.
All messages for subdomain.domain.com are being forwarded. But the thing is, the application that I'm supporting uses mailing system for some internal stuff and many addresses that are being CC when client is sending e-mail doesn't exist on subdomain mail server, they serve another purpose. When app on subdomain receives e-mail, it parses headers and uses all CC addresses in it's algorithms.
Here comes the problem. When client sends an e-mail, he'll receive as many error responses as there are fake addresses in CC.
There is only one real address that is listed in /etc/aliases and it's just piping incoming mails to stdin for some script.
Question. How do I prevent sending error responces to the client and just /dev/null all fake addresses? I need only 1 address, that is listed in aliases.
Thanks in advance.
Ok, I figured it out.
This can be achieved through virtual_alias_maps.
Add an virtual alias for domain and for address. Redirect domain to /dev/null and address to local alias.
virtual_alias_maps file:
target_addr#subdomain target#localhost
#subdomain devnull#localhost
/etc/aliases:
target: "| /path/to/script"
devnull: /dev/null

Postfix - restricting port 25 to receive mails from mail servers only

I have configured my postfix so as users under my server shall send mails through port 587 and port 25 will only be used to receive mails from mail servers.
I am successful to the extent that on connecting to port 25 mails are not allowed outside the mail server and it is being rejected as relay-access denied. whereas on port 587 the clients are able to sent mail to outside mail servers.
To achieve this I have set in my main.cf
smtpd_recipient_restriction=permit_mynetworks, reject_unauth_destination
that is I removed permit_sasl_authenticated.
if I add this condition, the mails are allowed to be sent outside the network and if I am removing the condition, any one can connect to port 25 and since there is no authentication can sent any number of mails to local recipients.
what is way that I can use sasl authenticaton on port 25, yet prevent it from relaying mails outside my nework.
I'm by no means proficient when it comes to administering postfix but I do know that you can always overwrite the restrictions on a per daemon level.
Take a look at postfix's master.cf, specifically the -o smtpd_xxx entries and google for an example.
Postfix allows relaying based on two criteria:
authentication (you removed that!)
network (this is controlled by $mynetworks)
I recommend you set the mynetworks variable to a single IP and localhost, something like:
mynetworks = ip.of_ser.ver, 127.0.0.1

Send email to SMTP server on non-standard port

How can I email to a domain whose SMTP server does not listen on the standard port 25? I need to email to it through webmail, like GMail.
I thought this would work:
user#domain.com:port
You can't do it with gmail. You need to configure a mail server to do this, and it's hard. The only other option is using a firewall to redirect traffic from 25 to your port.
(And this probably belongs on serverfault).