# Email from user being mistakenly forwarded to root



## shepper (Mar 12, 2013)

Although it could be viewed as an act of self-flagellation, on a new 9.1 install I decided to forego claws-mail and installed mutt with Sendmail, msmtp and fetchmail.

After letting my head clear, I can send mail from mutt via msmtp to smtpauth.earthlink, port 587, and fetchmail from mail.earthlink.net.

The one remaining issue is that my user emails, over 500 of them, are also being forwarded to root.  When I look at /var/mail/user and /var/mail/root, root has system monitoring reports and the user file contains my 500+ emails.

Ideally, I would like to have root just receive the system reports although I would also be OK with forwarding those reports to myself.

From what I have read, I need to set up /etc/mail/aliases which can be picky - I found a long thread that concluded that user names cannot be capitalized.

[cmd=]cat /etc/mail/aliases[/cmd]


```
# $FreeBSD: release/9.1.0/etc/mail/aliases 218119 2011-01-31 07:47:28Z max
im $
#       @(#)aliases     5.3 (Berkeley) 5/24/90
#
#  Aliases in this file will NOT be expanded in the header from
#  Mail, but WILL be visible over networks.
#
#       >>>>>>>>>>      The program "newaliases" must be run after
#       >> NOTE >>      this file is updated for any changes to
#       >>>>>>>>>>      show through to sendmail.
#
#
# See also RFC 2142, `MAILBOX NAMES FOR COMMON SERVICES, ROLES
# AND FUNCTIONS', May 1997
#       http://tools.ietf.org/html/rfc2142

# Pretty much everything else in this file points to "root", so
# you would do well in either reading root's mailbox or forwarding
# root's email from here.

root:   jsh

# Basic system aliases -- these MUST be present
MAILER-DAEMON: postmaster
postmaster: root

# General redirections for pseudo accounts
_dhcp:  root
_pflogd: root
bin:    root
bind:   root
daemon: root
games:  root
hast:   root
kmem:   root
mailnull: postmaster
man:    root
news:   root
nobody: root
operator: root
pop:    root
proxy:  root
smmsp:  postmaster
sshd:   root
system: root
toor:   root
tty:    root
usenet: news
uucp:   root

# Well-known aliases -- these should be filled in!
# manager:
# dumper:

# BUSINESS-RELATED MAILBOX NAMES
# info:
# marketing:
# sales:
# support:

# NETWORK OPERATIONS MAILBOX NAMES
abuse:  root
# noc:          root
security:       root

# SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES
ftp:            root
ftp-bugs:       ftp
# hostmaster:   root
# webmaster:    root
# www:          webmaster

# NOTE: /var/msgs and /var/msgs/bounds must be owned by sendmail's
#       DefaultUser (defaults to mailnull) for the msgs alias to work.
#
# msgs: "| /usr/bin/msgs -s"

# bit-bucket: /dev/null
# dev-null: bit-bucket
shepper:        jsh
```

The second option, if sorting mail to the appropriate reciepient fails, looks to be setting up a .forward file in the root directory.  This looks fairly easy, but computers are supposed to be good at sorting and making life easy for humans.:\

I appreciate any guidance in sorting this out.

Edit 3:  Although I started this as an educational rite of passage, in the background I had some ports building 2 of which core dump when starting.  One was the xombrero browser, the other is the dia flow charting program.  I decided that trying to learn how to set up a simple email server in the base install in the midst of failing builds was bad timing - it would not be the first time I spent hours thinking I incorrectly configured something that didn't work right to begin with.


----------



## usdmatt (Mar 13, 2013)

I don't really know anything about the other software you're using but I going to assume that mail delivery is being handled by Sendmail and it's fairly default in configuration.

First of all, default configuration. On a new install I usually do the following to set up Sendmail


```
# cd /etc/mail
# make
# ee {hostname}.mc (if required to set smarthost/dnsbl/smtp-auth/banner/timeouts/etc)
# make install restart
```

By default Sendmail will try and handle mail for @hostname. If you want it to handle other domains, they need to be added to /etc/mail/local-host-names.

By the look of it, you've already edited /etc/mail/aliases to deliver all root mail to jsh.
You need to run the `# newaliases` command after editing that file to rebuild the aliases database.

At this point, running `# sendmail -bv root@{some accepted domain}` or just `# sendmail -bv root` should tell you that it's deliverable locally to user jsh. Emails coming into Sendmail addressed to that address should end up in /var/mail/jsh.

If mail is not ending up where you expected, show the output of `# sendmail -bv address.you.are.testing` and the relevant lines from /var/log/maillog showing how Sendmail handled the email.


----------



## shepper (Mar 13, 2013)

@usdmatt

Thanks for the reply.

Messages were being delivered to me as jsh but for some reason jsh mails were also being delivered to root.

I am now trying this in OpenBSD where the forums convinced me to try OpenSMTPD.  Still, being able to set up Sendmail would be good to learn as it is the default in FreeBSD, NetBSD and OpenBSD and being facile with Sendmail looks to be the first step to my own email server.  I may come back to this in the future.


----------

