# System Mail Usage



## Phishfry (May 21, 2017)

I am trying to figure out FreeBSD internal messaging via mail. What should I look up as mostly I am finding info like this:
https://www.freebsd.org/doc/handbook/mail-using.html

I want to know about the nuts and bolts of system events and mail interaction. What can you adjust.

What about clients: Should I keep a seperate mail program for system messages and my regular POP claws-mail from my ISP? I would think that system emails would require less of a client. No send mail or reply mail. Only read mail. Command line facility usable.


----------



## ShelLuser (May 21, 2017)

Phishfry said:


> I am trying to figure out FreeBSD internal messaging via mail. What should I look up as mostly I am finding info like this:
> https://www.freebsd.org/doc/handbook/mail-using.html
> 
> I want to know about the nuts and bolts of system events and mail interaction. What can you adjust.


Not sure I understand the problem here. The link you posted contains all you basically need to know. By default FreeBSD utilizes the Sendmail MTA (Mail Transfer Agent) making that program responsible for the handling of e-mail. See /etc/mail as well as the handbook chapter on Sendmail configuration files.

You're free to replace it with another MTA of your choosing, see the ports collection for that.

As to the nuts and bolts...  Well, I suppose /usr/sbin/sendmail is an interesting detail. The sendmail binary (not to be confused with the MTA) is basically one of the standards on sending e-mails. Most programs which can send e-mails utilize this command. On FreeBSD it points to mailwrapper(8) thus making it easier to switch between MTA's ("mail servers").

But that's about it.



Phishfry said:


> What about clients: Should I keep a seperate mail program for system messages and my regular POP claws-mail from my ISP? I would think that system emails would require less of a client.


"Should" is a big word here. What works for some doesn't have to work for others. But I do agree that the idea can make sense.

My server(s) handle all my incoming & outgoing e-mail but I always leave the system messages on the server itself. My Outlook client basically gets all the 'regular' e-mail (for my domains and all) and that's that. Only when I log onto a server through PuTTY do I gain access to the system messages, I use mail/mutt which I really favour as a command-line mail client ("MUA"; Mail User Agent).

(edit): The reasoning behind this is simple: I'll only be able to follow up on those system messages once I'm actually logged on. So it makes more sense to me to read those while being logged on instead of on my desktop.

Hope this can give you some ideas.


----------



## Phishfry (May 21, 2017)

I was assuming a message is mailed everytime a system event happens, Like lets say a full disk. Is that correct? What gets mailed from the system and how to configure that. Like "memory is low" via mail or other system happenings.
Is this wrong assumption? Does it merely mail /var/log/messages notices? I thought the system mails various problems to the administrator?


----------



## Phishfry (May 21, 2017)

So it looks like `perodic` calls `cron` which generates `mail`.
Does that sound right?
periodic.conf contains what happens.
I was tracking down "daily security scan" and "daily run output" as I wanted to see how they work.


----------



## ShelLuser (May 22, 2017)

Phishfry said:


> I was assuming a message is mailed everytime a system event happens, Like lets say a full disk. Is that correct?


Not really, because by default nothing is monitoring things like that. What is happening though is that once cron(8) executes a job then the output of that job will be mailed to the job owner. And there are a few jobs configured by default such as periodic(8) which also already performs a large series of tasks by default. See /etc/periodic for a global overview.

One of those tasks is to check your disks and e-mail you the output. But that's nothing more than the output of `df -lh`.



Phishfry said:


> What gets mailed from the system and how to configure that. Like "memory is low" via mail or other system happenings.


If you want to set up things like that then you should set up a system monitor. That has little to do with e-mail though. Not sure if the Ports system already has something like that (it wouldn't surprise me) but it would also be quite trivial to set something up yourself through scripting.



Phishfry said:


> So it looks like `perodic` calls `cron` which generates `mail`.
> Does that sound right?


Uhm, no. Not by a long shot. Check /etc/crontab as well as the periodic(8) manualpage.


----------



## aragats (May 22, 2017)

The following does not answer your questions directly, Phishfry , but rather gives some ideas.
In several boxes I've setup mail/ssmtp and configured /etc/mail/mailer.conf correspondingly. I'm using a gmail account for ssmtp, it relays messages to my regular email account. I've setup filters to process such messages.
Regarding the clients: I mostly use mail/mutt for all types of emails. In those boxes which don't have `ssmtp` I simply launch mutt pointing it to the mailbox file:
	
	



```
# mutt -f /var/mail/root
```
P.S. ssmtp has a bug: # and = cannot be used in passwords, I've submitted a bug report and a patch to bugzilla.


----------



## SirDice (May 22, 2017)

Phishfry said:


> So it looks like  perodic calls  cron which generates  mail.
> Does that sound right?


It's the other way around, periodic(8) gets started from cron(8). See /etc/crontab:

```
# Perform daily/weekly/monthly maintenance.                                                                                         
1       3       *       *       *       root    periodic daily                                                                      
15      4       *       *       6       root    periodic weekly
30      5       1       *       *       root    periodic monthly
```


----------

