1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Collect mails from all servers?

Discussion in 'Web & Network Services' started by feralape, Apr 13, 2012.

  1. feralape

    feralape New Member

    Messages:
    146
    Likes Received:
    0
    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:

    Code:
    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.
     
  2. wblock@

    wblock@ Administrator Staff Member Administrator Moderator Developer

    Messages:
    11,156
    Likes Received:
    5
    Configure the servers to use the ISP as a smarthost. Then they will be able to send to gmail.
     
  3. kpa

    kpa Member

    Messages:
    3,982
    Likes Received:
    2
    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
     
  4. feralape

    feralape New Member

    Messages:
    146
    Likes Received:
    0
  5. kpa

    kpa Member

    Messages:
    3,982
    Likes Received:
    2
  6. feralape

    feralape New Member

    Messages:
    146
    Likes Received:
    0
    thanks.

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

    This works:
    Code:
    echo "test" | mail -s "test" root
    This doesn't:
    Code:
    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:

    Code:
    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
     
  7. kpa

    kpa Member

    Messages:
    3,982
    Likes Received:
    2
    I think you need something like this in /usr/local/etc/ssmtp/revaliases:

    Code:
    myuser:myuseratgmail@gmail.com:smtp.gmail.com:587
    
    Or just:
    Code:
    myuser:myuseratgmail@gmail.com
    
     
  8. ecazamir

    ecazamir New Member

    Messages:
    215
    Likes Received:
    0
    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.
     
  9. feralape

    feralape New Member

    Messages:
    146
    Likes Received:
    0
    Thanks guys.

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

    Code:
    MAILTO=dumpmailaccount@gmail.com
    So far that seems to be collecting most of the mails.