# Receive root's mail with ssmtp only (no postfix)?

## rsa4046

I maintain a server at work with minimal mail handling capability, i.e., incoming mail is accessed from department IMAP servers using mutt, and outgoing mail is dispatched to company SMTP servers using ssmtp. I don't want to change any of that, it works fine. What I do want to do is receive mail intended for root (from cron/at jobs and the like) by forwarding them to myself at an external email address (at the moment such msgs collect in /root/dead.letter). I thought I would be able to do this simply by editing /etc/ssmtp/revaliases

```
#/etc/ssmtp/revaliases

root:me@mycompany.com:smtpserver.mycompany.com:465

```

and /etc/ssmtp/ssmtp.conf

```
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.

# The person who gets all mail for userids < 1000

# Make this empty to disable rewriting.

root=me@mycompany.com

# The place where the mail goes. The actual machine name is required

# no MX records are consulted. Commonly mailhosts are named mail.domain.com

# The example will fit if you are in domain.com and your mailhub is so named.

mailhub=smtpserver.mycompany.com:465
```

Unfortunately, this setup doesn't seem to work at all: the output from root's at jobs is still just appended to the /root/dead.letter. Has anyone gotten this to work with ssmtp? I know there are many guides for setting up mail servers, but I don't want to do anything that sophisticated, just forward root's mail to an external mailbox. Thanks!

Edit: I also have mail-client/mailx installed

----------

## Anarcho

Do you see something in the logs when it doesn't send out the mail but appends it to dead.letter?

----------

## rsa4046

Hi Anarcho

Thanks for the speedy reply. The logs do show a problem upon the completion of the last at job:

```
Dec 18 13:25:44 stranski sSMTP[7919]: Creating SSL connection to host

Dec 18 13:25:44 stranski sSMTP[7919]: SSL connection using RC4-MD5

Dec 18 13:25:44 stranski sSMTP[7919]: RCPT TO:<bluedog@stranski> (450 4.1.2 <bluedog@stranski>: Recipient address rejected: Domain not found)
```

where bluedog@stranski is only my local login username on this server, and not the user@address I've indicated in the config files (i.e., me@mycompany.com). It seems I've done something wrong ... but I'm not sure where?

----------

## theBlackDragon

I realize this is a relatively old topic but the answer is nowhere to be found in the forums nor does it seem to be very easy to find with our good friend Google (unless you know what to Google for, but then you already have the answer...)

ssmtp doesn't support /etc/mail/aliases like sendmail does and revaliases does what it says it does, it aliases the FROM address, not the TO addres like we want.

The solution is to use /etc/mail.rc and specify the aliases there (part of mail-client/mailx) like this:

```
alias root root<admin@remotemail.org>
```

I hope this saves someone some time googling.

----------

## Ilya.A

theBlackDragon, thank you very much!

----------

## mimosinnet

 *theBlackDragon wrote:*   

> ssmtp doesn't support /etc/mail/aliases like sendmail does and revaliases does what it says it does, it aliases the FROM address, not the TO addres like we want.

 

Thanks for reviving old threads! I have just been playing with ssmtp, and without mailx or any other aliasing in /etc/mail/aliases, I am able to send mail (file test.txt) to my external mailbox with:

```
ssmtp root < test.txt
```

I had to pay more attention at your sentence and made some tests. I have finally understood that, in the envelope, 'root' is the "From" address of the envelope (the sender that gets aliased by what is defined in revaliases, "yourmail@gmail.com") while the "To" is the address defined by the keyword root in ssmtp.conf. 

In the message (I am using gmail), the "From" is forged by ssmtp (root yourmail@gmail.com) or overridden if you use the option FromLineOverride=YES (in this case, you get the envelope "From", "yourmail@gmail.com"). The "To" is always what is written in the message.

In summary:

Envelope:

- From: 'root' (yourmail@gmail.com)

- To: yourmail@gmail.com

Message:

- From: 'root yourmail@gmail.com' (or 'yourmail@gmail.com if you use the option FromLineOverride=YES)

- To: what the message says it is directed to

Thanks a lot for your message! It has really help me to practically understand how e-mail works. 

Cheers!

----

Old knowledge unveils what is taken for granted in our present world.

----------

## Ilya.A

I use ssmtp with vixie cron and I still have a problem.

Mails from cron have "To:" in message and my mail host doesn't allow unknown address in this field (I have "root" here).

It works if I use "mail" command from command line - "To:" contains "root <real@address>" or if use pure "ssmtp" command - there is no "To:" field at all.

I hoped that cron will use "mail" command using "/etc/mail.rc" and will have in "To:" field "root <read@address>", but it have just "root".

Is there some way to remove or rewrite "To:" field in cron mails?

Or I just have to use some more smart MTA, i. e. postfix?

----------

## Bones McCracker

You can use formail to rewrite headers.  You just pipe the message through formail with the appropriate options.

http://linuxcommand.org/man_pages/formail1.html

formail comes with procmail (a general purpose mail filter).  You can pipe things to it from within procmail or use it externally from procmail.  procmail itself offers the ability to do just about anything to an inbound or outbound mail message.

----------

## mimosinnet

 *Ilya.A wrote:*   

> Mails from cron have "To:" in message and my mail host doesn't allow unknown address in this field (I have "root" here).
> 
> It works if I use "mail" command from command line - "To:" contains "root <real@address>" or if use pure "ssmtp" command - there is no "To:" field at all.

 

I am using ssmtp and fcron. I have added this line to root's fcrontab to test:

```
@mailto(root),forcemail 30s date
```

This is what I get in my gmail account:

```
Return-Path: <mimosinnet_at_gmail.com>

Received: from mimosinnet (x.x.x.x.dyn.user.ono.com. [x.x.x.x)

        by mx.google.com with ESMTPS id n8sm7344179wix.10.2012.04.19.04.25.38

        (version=TLSv1/SSLv3 cipher=OTHER);

        Thu, 19 Apr 2012 04:25:39 -0700 (PDT)

Message-ID: <4f8ff633.0850b40a.05ae.fffff9ce@mx.google.com>

Received: by mimosinnet (sSMTP sendmail emulation); Thu, 19 Apr 2012 13:25:37 +0200

From: "root" <mimosinnet@gmail.com>

Date: Thu, 19 Apr 2012 13:25:37 +0200

To: root@mimosinnet

Subject: fcron <root@mimosinnet> date

dj abr 19 13:25:35 CEST 2012
```

I would say that fcron sends the mail to my gmail account. Is this what you are after?

Cheers!

----------

