Join the community today
Become a Member

Email Postfix - Is it possible to automatically append sender name to all sent mails?

Discussion in 'System Administration' started by BobbyWibowo, Feb 23, 2016.

  1. BobbyWibowo

    BobbyWibowo Active Member

    197
    42
    28
    Jul 30, 2015
    Indonesia
    Ratings:
    +71
    Local Time:
    9:24 PM
    1.17.x
    10.3.x
    I've been looking through Google Search results for a while, but I couldn't find any appropriate method for my system.
    So anyway, what I wanted to do was to append sender name to all sent mails from my system. At the moment, I've been using the generic file of postfix to change the Form header of mails from root@endlesshorizon.net to webmaster@endlesshorizon.net, but I can't figure out how to append sender name.
    Currently, all sent mails (excluding the ones from XenForo and custom mail command) will be like this:
    sender_name_missing.png
    But, what I want is this:
    sender_name_exist.png
    I did that one with custom mail command, so I manually added a custom Form header. But for automated messages from yum-cron, etc., I don't know whether it's possible to change the Form header through postfix configuration instead.

     
  2. eva2000

    eva2000 Administrator Staff Member

    54,361
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    12:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Maybe @Tracy Perry who has more experience with postfix can shed some light ?
     
  3. eva2000

    eva2000 Administrator Staff Member

    54,361
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    12:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    @BobbyWibowo ok one way you can do this assuming you used smtp_generic_maps to set the from email address is to edit /etc/passwd entry for root user's 5th column (Understanding /etc/passwd File Format)

    upload_2016-2-24_1-16-12.png

    from
    Code:
    root:x:0:0:root:/root:/bin/bas
    to whatever you want the send name to be i.e. myroot is custom sender from name
    Code:
    root:x:0:0:myroot:/root:/bin/bas
    this example used a postfix generic map for
    Code:
    root yourusername@yourdomain.com
    and ended up like
    upload_2016-2-24_1-13-51.png
     
  4. BobbyWibowo

    BobbyWibowo Active Member

    197
    42
    28
    Jul 30, 2015
    Indonesia
    Ratings:
    +71
    Local Time:
    9:24 PM
    1.17.x
    10.3.x
    I've had root's user ID on /etc/passwd as Endless Horizon, strangely emails from YUM crons were still not getting the sender name.
     
  5. eva2000

    eva2000 Administrator Staff Member

    54,361
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    12:24 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    using CentOS 6 or 7 ? for CentOS 7 has another option in /etc/yum/yum-cron.conf
    messages either go to stdio or email, default is stdio so for emails set emit_via = email
    Code:
    # How to send messages.  Valid options are stdio and email.  If
    # emit_via includes stdio, messages will be sent to stdout; this is useful
    # to have cron send the messages.  If emit_via includes email, this
    # program will send email itself according to the configured options.
    # If emit_via is None or left blank, no messages will be sent.
    emit_via = stdio
    and already has an email from field
    Code:
    [email]
    # The address to send email messages from.
    email_from = root@localhost
    
    # List of addresses to send messages to.
    email_to = root
    
    # Name of the host to connect to to send email messages.
    email_host = localhost
    on CentOS 6 version of yum-cron no such native email from option but you can probably hack the file at /etc/cron.daily/0yum.cron near the end
    Code:
    if [ ! -z "$MAILTO" ] && [ -x /bin/mail ]; then
    # if MAILTO is set, use mail command (ie better than standard mail with cron output)
      [ -s "$YUMTMP" ] && mail -s "System update: $SYSTEMNAME" $MAILTO < $YUMTMP
    else
    # default behavior is to use cron's internal mailing of output from cron-script
      cat $YUMTMP
    fi 
    the section
    Code:
    mail -s "System update: $SYSTEMNAME" $MAILTO
    can add -r EMAILFROMADDR, so if you wanted to send from same address as to address already filled out
    Code:
    mail -r $MAILTO -s "System update: $SYSTEMNAME" $MAILTO