I currently use Postfix on an Ubuntu machine that uses Nagios for monitoring.

I'd like to change the email address that Postfix uses to send out.

Postfix just relays all its email through our Exchange Server.

Here is my current config bits

myhostname = mywindowsdomain.co.uk  
mydestination = $myhostname    localhost 
relayhost = IP of Exchange server 
mynetworks = 
inet_protocols = ipv4 
inet_interfaces = all

Now this works and emails out through my exchange server.

However it comes from the username of the user on the machine.

eg user1@mywindowsdomain.co.uk

I'd like it to come from the machine hostname that postfix is installed on.

How do I do this? Everything I try refuses to change the email that it's sent out as username@mywindowsdomain.co.uk rather than hostname@mywindowsdomain.co.uk


Did you read http://www.postfix.org/ADDRESS_REWRITING_README.html#generic?

As alternative you might change the notification command in nagios from for example:

command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHostname: $HOSTNAME$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $SHORTDATETIME$\n\nAdditional Info: $SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$


command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHostname: $HOSTNAME$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $SHORTDATETIME$\n\nAdditional Info: $SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -- -f hostname@domainname.com

Note the -- -f hostname@domainname where you instruct the mail command to pass the -f hostname@domainname to the MTA mail submit command (sendmail).

See man sendmail and search for flag -f

If your mail command actually refers to mailx you should use the -r hostname@domainname.com instead of -- -f hostname@domainname because mailx does not support the -- sendmail options feature.

  • Hi Thankyou for this. I did try the -f option previously and that does sort the address that it comes from out but doesnt sort the display name out. The display name still comes as Nagios with the correct email address. How would one change the display name? It just get sconfusing becuase i have 2 seperate nagios servers in 2 seperate locations and both come from a display name called Nagios so i have no way of quickly glancing to see which it comes from. Now if i could get 1 to come from Site1 Nagios and the other from Site2 Nagios then happy days. – user114913 May 11 '15 at 11:41
  • 1
    Look at man sendmail for the -F flag and see if that will do what you desire. – Lambert May 11 '15 at 11:46

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.