1

UPDATE: I solved this by setting myorigin to $myhostname ("prime.example.com"). Now system mail goes to "[email protected]", which is what I wanted. My app explicitly says it wants to send from "[email protected]", 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: [email protected]) 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: [email protected]) from cli by:

echo "This is the body of the email" | mail -s "This is the subject line" -a "From: [email protected]" <to-address>

However, when a simple cron job runs, mail is being sent via smtp to [email protected], not locally to [email protected] 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.

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

1 Answer 1

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.
3
  • 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, 2015 at 18:56
  • Thanks Esa. What I did was set mydestination = $myhostname so that all system mail is delivered locally (to [email protected]). My app is able to send from [email protected]. So I now have things the way I want them. Does this look OK?
    – user101570
    Mar 6, 2015 at 20:39
  • That should do it. Notice, that the default for mydestination is $myhostname, localhost.$mydomain, localhost. Mar 6, 2015 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .