# Can one use mail with gnupg/encryption



## a59303 (Jul 8, 2015)

Hello,

I had posted a couple of months ago Thread 51715 about getting syslog to mail me logs, outside of the local computer.  I would like to be able to encrypt those emails.  Using `mail` so far seems good and I want to know if I can use *GNUPG* with it.  If so how?

I have discovered that I need to have sendmail enabled as well as smtpd for `services`, or in rc.conf, to get the mail to go through.

Thanks,

a5'

- I have modified the goal to just get the _weekly run_ cron job sent to the email address if this is relevant. Also `uname -a` yields;

```
FreeBSD  my.website.com 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r284814: Thu Jun 25
23:00:47
UTC 2015     root@releng2.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/RPI-B arm
```


----------



## jrm@ (Jul 9, 2015)

You could encrypt the logs and attach them to the message.   Have a look at gpg's --batch option.


----------



## a59303 (Jul 9, 2015)

jrm, thanks for the reply.

So maybe I could go back to using syslog and issue the command in that file to encrypt the logs, but I think that I could pipe it to `mail` maybe and actually encrypt the mail as well.

Thanks, just thinking out loud,

a5'


----------



## a59303 (Jul 13, 2015)

Hi,

Found that, when using `crontab`,/etc/crontab, that I need to set the *MAILTO* variable.  I am hoping that I can set this to a foreign (Not on local machine or network) email address due to `sendmail` and *SMTP* being enabled.  I am quite happy with the information that the simple _periodic_ output initiated by `cron`.  Because of this I would like to avoid using /etc/syslog.conf directly.  Although I think I will just have to provide the command to `cron` in /etc/crontab to encrypt... need to review that.

Thanks,

a5'


----------



## jrm@ (Jul 13, 2015)

You can have mail for local users sent to foreign addresses with lines like the one below in /etc/mail/aliases:

```
localuser: me@myotherdomain.org
```

Then run `cap_mkdb /etc/mail/aliases`


----------



## a59303 (Jul 13, 2015)

Thank You, I was wondering about that.  I think that I would like to try something like below, taken from crontab5();

```
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job | gpg -batch -e | mail me@alternative.com
```

Although I fear that makes it likely something will go wrong because I really don't understand it that well.

- a5'


----------



## kpa (Jul 14, 2015)

Use an explicit recipient on the gpg(1) command line (-r recipient) unless you have a default recipient set in preferences for the user. Also use the ascii armor format for transport, without the -a you'll get binary output that doesn't transfer well via email. Lastly, use a full path to the gpg binary, PATH is very limited when you run commands from cron(8).

`/usr/local/bin/gpg -batch -e -a -r me@alternative.com`


----------



## a59303 (Jul 14, 2015)

> Use an explicit recipient on the gpg(1) command line (-r recipient) unless you have a default recipient set in preferences for the user. Also use the ascii armor format for transport, without the -a you'll get binary output that doesn't transfer well via email. Lastly, use a full path to the gpg binary, PATH is very limited when you run commands from cron(8).
> 
> /usr/local/bin/gpg -batch -e -a -r me@alternative.com




That's very helpful, I will to check out these two leads when I get a chance.

Thanks,
a5'


----------



## a59303 (Jul 14, 2015)

I just saw this on the gpg page:
https://www.freebsd.org/cgi/man.cgi...ormat=html&sektion=1#HOW_TO_SPECIFY_A_USER_ID


> *By exact match on an email address*.
> This is indicated by enclosing the email address in the usual
> way with left and right angles.
> 
> <heinrichh@uni-duesseldorf.de>



Is this important to mail with gpg?  What I was trying to find is if gpg uses mail or some other facility to send mail.  This seems to clarify the issue; So,

`/usr/local/bin/gpg -batch -e -a -r me@alternative.com`

becomes

`/usr/local/bin/gpg -batch -e -a -r <me@alternative.com>`


Thanks,

a5'


----------

