0

UPDATE: I solved this by setting myorigin to $myhostname ("prime.example.com"). Now system mail goes to "user@prime.example.com", which is what I wanted. My app explicitly says it wants to send from "user@example.com", and that works too. I'm not entirely sure this is the proper way of doing things, so I remain open to further suggestions.

I want locally generated mail currently sent via smtp to instead be delivered locally. Right now they go to user@domain instead of user@hostname. I'm using Postfix 2.11 on Ubuntu Server 14.04.

Domain: example.com

Hostname: prime.example.com

/etc/hosts:

127.0.1.1 prime.example.com prime
127.0.0.1 localhost

/etc/postfix/main.cf excerpt:

myhostname = prime.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname ("example.com")
mydestination = prime.example.com, localhost.example.com localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 127.0.0.1
inet_protocols = all

MX records for example.com point elsewhere; the server is used to send e-mail, not receive.

I can send email locally (showing from: user@prime.example.com) from the command line by:

echo "This is the body of the email" | mail -s "This is the subject line" root

I can also send email via smtp for the domain (showing from: user@example.com) from cli by:

echo "This is the body of the email" | mail -s "This is the subject line" -a "From: user@example.com" <to-address>

However, when a simple cron job runs, mail is being sent via smtp to user@example.com, not locally to user@prime.example.com as I want.

I thought mydestination was supposed to prevent sending mail non-locally, so either I'm mistaken or I have a configuration problem somewhere. Any tips would be much appreciated.

  • Why don't you set the correct recipient, or set an appropriate alias? – sebix Mar 6 '15 at 19:12
0

You should add example.com to mydestination if you want all mail to example.com to be handled locally. Otherwise the server looks for MX records of example.com and sends the mail via smtp accordingly.

If you would like programs to send local notifications to prime.example.com, you should instead change /etc/mailname to meet your mydestination, as described in man mailname:

DESCRIPTION

   The  file /etc/mailname is a plain ASCII configuration file, which on a
   Debian system contains the visible mail name of the system.  It is used
   by many different programs, usually programs that wish to send or relay
   mail, and need to know the name of the system.
  • I don't want all mail to be handled locally. The server is hosting an app that needs to send mail only (not receive, hence why MX records point elsewhere). Mail sent from the app should be delivered via smtp; I just don't want mail generated during cron runs, etc. being sent out; I want those to be delivered locally. – user101570 Mar 6 '15 at 18:56
  • Thanks Esa. What I did was set mydestination = $myhostname so that all system mail is delivered locally (to user@prime.example.com). My app is able to send from user@example.com. So I now have things the way I want them. Does this look OK? – user101570 Mar 6 '15 at 20:39
  • That should do it. Notice, that the default for mydestination is $myhostname, localhost.$mydomain, localhost. – Esa Jokinen Mar 6 '15 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.