# Collect mails from all servers?



## Deleted member 2077 (Apr 13, 2012)

Here is the situation, I have a handful of FreeBSD servers, most are behind firewalls/nat. I need to capture emails on the servers to monitor for problems.

I'm forwarding all root mail to -> my user@localhost (via /etc/mail/aliases).  This works.

Now I would like to forward user@localhost to user@gmail.  Basically dump everything there and then I'll sort it out later  (I actually pull it down to another server and run procmail on it, but this step is working and not important).

Is there an easy way to do this?  Like I said, it's quite a few servers and I'll be adding more, so don't want to have to  manually fiddle the knobs on each.  A generic solution that works for hosts without real domain names would be best.

I tried adding [email='user@gmail.com]'user@gmail.com[/email]' to the ~user/.forward but google is rejecting it:


```
Apr 12 22:23:07 fire3 sm-mta[84432]: q3D3N7SY084432: from=<myuser@fire3>, size=344, class=0, nrcpts=1, msgid=<201204130
323.q3D3N7N7084431@fire3>, proto=ESMTP, daemon=Daemon0, relay=localhost [127.0.0.1]
Apr 12 22:23:07 fire3 sendmail[84431]: q3D3N7N7084431: to=root@localhost, ctladdr=myuser (1001/1001), delay=00:00:00, x
delay=00:00:00, mailer=relay, pri=30051, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (q3D3N7SY084432 Message accepted for delivery)
Apr 12 22:23:19 fire3 sm-mta[84433]: q3D3N7SY084432: to=myuser@gmail.com, ctladdr=<myuser@fire3> (1001/1001), dela
y=00:00:12, xdelay=00:00:12, mailer=esmtp, pri=30566, relay=alt4.gmail-smtp-in.l.google.com. [173.194.65.26], dsn=4.0.0,
 stat=Deferred: Connection refused by alt4.gmail-smtp-in.l.google.com.
Apr 12 22:33:29 fire3 sm-mta[84463]: q3D3N7SY084432: to=myuser@gmail.com, ctladdr=<myuser@fire3> (1001/1001), dela
y=00:10:22, xdelay=00:00:13, mailer=esmtp, pri=120566, relay=alt4.gmail-smtp-in.l.google.com. [173.194.65.27], dsn=4.0.0
, stat=Deferred: Connection refused by alt4.gmail-smtp-in.l.google.com.
```


----------



## wblock@ (Apr 13, 2012)

Configure the servers to use the ISP as a smarthost.  Then they will be able to send to gmail.


----------



## kpa (Apr 13, 2012)

You'll need to do couple of things:

Enable SMART_HOST with smtp.gmail.com as the host and enable TLS/SSL with username/password for outgoing mails, for example:

http://rajasuperman.blogspot.com/2006/09/gmail-as-smarthost-for-fre_115764792412436946.html

The page says that sendmail(8) needs to be recompiled to support SSL/TLS but that's no longer true.


Rewrite the sender address (gmail won't accept root@someweirddomain) to myusername@gmail.com using /etc/mail/genericstable, see the sendmail README at /usr/share/sendmail/cf/README


----------



## Deleted member 2077 (Apr 13, 2012)

*W*ow, thanks guys for the quick response and detailed write ups.

What is your take on this?  

http://analysisandreview.com/security/replace-sendmail-with-ssmpt-to-send-email-via-gmail/

Seems like it's a bit easier to set up.


----------



## kpa (Apr 13, 2012)

Yes, that should work as well. I can't remember exactly but I think you'll be limited to forwarding local (sent from the machine itself) mail only with that setup but it sounds to me that's not going to be a problem?

Edit: There's a chapter in the handbook about outgoing only MTA using mail/ssmtp:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/outgoing-only.html


----------



## Deleted member 2077 (Apr 13, 2012)

thanks.

ssmtp is working for root, but not for 'myuser'.

This works:

```
echo "test" | mail -s "test" root
```

This doesn't:

```
echo "test" | mail -s "test" myuser
```

gmail gets it, but has to 'To:' address as 'myuser@myhost' which gets rejected since it doesn't exist.
How do I rewrite it so 'myuser@myhost' goes [email='myuser@gmail.com]'myuser@gmail.com[/email]'?

root@myhost goes to [email='myuser@gmail.com]'myuser@gmail.com[/email]' when I set root=myuser@gmail.com in ssmtp.conf

the logs show this:


```
Apr 13 00:21:17 fire3 sSMTP[21436]: 235 2.7.0 Accepted
Apr 13 00:21:17 fire3 sSMTP[21436]: MAIL FROM:<myuser@gmail.com>
Apr 13 00:21:17 fire3 sSMTP[21436]: 250 2.1.0 OK hq3sm4718420igc.0
Apr 13 00:21:17 fire3 sSMTP[21436]: RCPT TO:<myuser@fire3>
Apr 13 00:21:17 fire3 sSMTP[21436]: 250 2.1.5 OK hq3sm4718420igc.0
Apr 13 00:21:17 fire3 sSMTP[21436]: DATA
Apr 13 00:21:18 fire3 sSMTP[21436]: 354  Go ahead hq3sm4718420igc.0
Apr 13 00:21:18 fire3 sSMTP[21436]: Received: by myhost (sSMTP sendmail emulation); Fri, 13 Apr 2012 00:21:17 -0500
Apr 13 00:21:18 fire3 sSMTP[21436]: From: "User &" <myuser@gmail.com>
Apr 13 00:21:18 fire3 sSMTP[21436]: Date: Fri, 13 Apr 2012 00:21:17 -0500
Apr 13 00:21:18 fire3 sSMTP[21436]: To: myuser
Apr 13 00:21:18 fire3 sSMTP[21436]: Subject: test 
Apr 13 00:21:18 fire3 sSMTP[21436]:
Apr 13 00:21:18 fire3 sSMTP[21436]: test
Apr 13 00:21:19 fire3 sSMTP[21436]: .
Apr 13 00:21:19 fire3 sSMTP[21436]: 250 2.0.0 OK 1334294479 hq3sm4718420igc.0
Apr 13 00:21:19 fire3 sSMTP[21436]: QUIT
Apr 13 00:21:19 fire3 sSMTP[21436]: 221 2.0.0 closing connection hq3sm4718420igc.0
Apr 13 00:21:19 fire3 sSMTP[21436]: Sent mail for myuser@gmail.com (221 2.0.0 closing connection hq3sm4718420igc.0) u
```


----------



## kpa (Apr 13, 2012)

I think you need something like this in /usr/local/etc/ssmtp/revaliases:


```
myuser:myuseratgmail@gmail.com:smtp.gmail.com:587
```

Or just:

```
myuser:myuseratgmail@gmail.com
```


----------



## ecazamir (Apr 17, 2012)

I like aliases. Edit /etc/mail/aliases, put a line "root: youraccount@gmail.com, root", then execute newaliases. 
This works for postfix, it should work for sendmail and any other MTA.


----------



## Deleted member 2077 (Apr 19, 2012)

Thanks guys.

I went with SSMTP, once that was set up I just manually set this in the crontabs for most users:


```
MAILTO=dumpmailaccount@gmail.com
```

*S*o far that seems to be collecting most of the mails.


----------

