My First Sendmail
From: System Administrator
Date: Sat Apr 19, 2003 7:46:35 AM US/Eastern
To: [email protected]
Subject: Test to [email protected]
using the mail command in terminal window.
Note to self: mv command did not work until Developer Tools were installed...
Matthew Butch's Website
Home | Politics | Macintosh | Guns | About |
 
Receiving Daily System Reports in MacOS X
By Matthew Butch-[email protected]
 
NOTE: This instructions are for 10.2(aka Jaguar) and later ONLY
Introduction
BSD, the UNIX variant OSX is based on, preforms certain cleanup services in the backround every day. A report of what is done is sent to the root user on the system. The following instructions allow any native OSX mail client(including Mail.app, the GUI application made by Apple included with OS X) to receive them.
Throughout this document, anything in bold is a command to be entered in the terminal.)
Here is a copy of the reports for those who want to decide whether it is worth it to set this up: crondaily.txt, cronmonthly.txt
NOTE: You'll need to know a little bit about Unix to do this. It is also for 10.2 and later ONLY. 10.1 and ealier is a little different. If your a newbie I can help you get through it. Just email me:[email protected].
 
I. Enabling root
The root user must be enabled to receive reports, since that is where it is sent. The root user is called a superuser, and is able to do anything and everything he wants. Apple has disabled it by default, since it is possible to severely corrupt and destroy the entire system. The user that you enter as your name(mjbutch in my case) is an administrator, a more powerful user than others, but not as powerful as root.
To enable root, do ONE of the following: | |
a. Start the NetInfo Manager app in the Application Folder on your MacOS X hard drive. Select the Domain Menu, move down to Security menu item, and choose the Authenticate submenu item. Enter your user password. Next, go to the same menu and menu item, and choose Enable Root User. Enter the same password as your user password | |
b. Enter on the command line:
| |
c. Restart using the MacOS X CD. Under one of the menu's is an Enable root user similar to choice a above |
The root user should be enabled.
 
II. Having the report sent to your user
Normally, the report(and other mail to root) is sent to /dev/null which is a "black hole". Anything sent there is destroyed. This is set by the .forward file in the root user's directory. You'll want this to be sent to your personal user's account.
First, open up Terminal.app(in the Application folder), now enter
cd /var/root |
sudo pico .forward |
Mail should now be sent to forward to your user account.
 
III. Fixing and setting up sendmail
A. Setting up sendmail to launch at startup
Because of the way Jagauar is set up, sendmail must be running at all times. Don't worry, it takes up almost no processor usage nor memory space.
To do this we have to edit the hostconfig file. Type in the Terminal:
sudo pico /etc/hostconfig |
Now, find the MAILSERVER=-NO- line and change the -NO- to -YES- . OSX will launch sendmail at startup.
 
B. Fixing the config file
Sendmail is misconfigured in the MacOS X release. Sendmail is what sends mail from one account to another on the local machine, and to other systems on the internet. It is needed to allow the system report to be sent.
What needs to be done is to recompile the configuration file for sendmail.
Open the Terminal and enter the following there:
cd /usr/share/sendmail/conf/cf/ |
Next, type:
cp generic-darwin.mc osx.mc |
Now, we have to edit this file to change the default behavior of sendmail. The first change is to make sendmail ignore the permissions of the root drive. sendmail is really restrictive of the way permissions are, but we can override this behavior. To edit the sendmail configuration file enter:
sudo pico osx.mc |
That should open up a text editor called pico. Find the line that says "define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')". After it add
define(`confDONT_BLAME_SENDMAIL', `GroupWritableDirPathSafe') |
Now sendmail won't complain about the standard permissions of OSX.
Next, we have to set tell sendmail to ignore domains that can't be resolved. Look for the line "FEATURE(`access_db')dnl" and add the following line afterwards:
FEATURE(accept_unresolvable_domains) |
Okay, now, we need to save this file and exit. press control-x, press y to save it, and hit return to save it as osx.mc.
Now, we have to "compile" the osx.mc to a format that sendmail can understand. To do this type:
m4 ../m4/cf.m4 osx.mc > /tmp/sendmail.cf |
That created the file in a temporary location. Now, before we move it into its proper location, lets save the old one in case the new one is corrupted or wrong. So, type
mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old |
Finally, move the new one into place
mv /tmp/sendmail.cf /etc/mail/sendmail.cf |
The last thing to do is to tell sendmail to restart so it can read the new config file:
/System/Library/StartupItems/Sendmail/Sendmail restart |
C. Fixing the NetInfo
Finally, we have to remove a configuration preference in NetInfo Manager. Open up NetInfo Manager, click on the lock in the lower left corner. Enter your password. Now, click on the "locations" line in the cecond column. "sendmail" should appear in the third column. Click on that, then click the "Delete" button. Hit return or click on "Delete" to confirm deletion. Quit NetInfo Manager.
Sendmail should work now. test it out by entering
mail root |
 
IV. Enabling the mail client to read local mail
A. Installing imap
Note for Mail.app users: In previous versions of OSX and Mail.app, one could get local mail directly. However, Apple in its strange wisdom decided to remove that functionality. So now everybody has to install and imap server. It doesn't take up much memory, hard drive space, or processor usage at all.
1. Downloading
To get the client to read the local mail, an imap server must be setup(thanks to Robert for this hint). Download the most recent version from uwash, or directly here.
Now, Stuffit should uncompress the downloaded file, but make sure you use 6.0.1, as 5.5 will cause problems because it doesn't put the correct line endings in.
2. Building IMAP server
Open Terminal and cd to the directory that was unstuffed. Now enter
cd src/osdep/unix |
pico env_unix.c |
Next, hit ctrl-x, enter y to write out, and save it as the name that pico gives you. Now go back to the directory of imap(try cd ../../..). Enter
make osx SSLTYPE=none |
This starts the compiling of the imap server. It'll take a while, so go get something to drink:). For interested people, the reason SSLTYPE is set to none is because the recent code of imap changed. They now default to SSLTYPE of nopwd, meaning the SSL part will connect without a password. However, on OSX, the necessary headers are not included, even though the SSL framework is. Compiling with the default SSLTYPE gives errors because of this. We could download them, but that, just like SSL, aren't necessary for our purposes. The none type tells the make program to ignore the SSL files, and these headers aren't needed. If you are going to be using imap for uses other than just system reports, I suggest support and building in SSL into imap. The instructions can be found in docs/SSLBUILD.
3. Installing the IMAP server
After it is done, you will need to install the build files into the appropriate directory. First check if the /usr/local/sbin directory exists by entering
cd /usr/local/sbin |
If it says File or Directory not found, enter
sudo mkdir /usr/local/sbin |
Now, enter the following commands to copy the daemons to their proper places:
sudo cp imapd/imapd /usr/local/sbin/imapd |
4. Setting OSX up to recognize the IMAP server
Next we have to tell the system to recognize and run these services. The first place to do that is the inetd config file, which tells which internet systems to load and run. Open up that file by entering
sudo pico /etc/inetd.conf |
imap stream tcp nowait root /usr/local/sbin/imapd imapd |
5. Launching and Runner the IMAP server
In order for the imap server to start, you must either restart the machine or send the HUP signal to the inetd process. Logging out won't do. I have't tried this, but the HUP signal should work. To send the HUP signal, enter
ps auwx | grep inetd |
Note the number to the left of the word root. That's the process ID. Enter that number in place of pid in this command:
sudo kill -HUP pid |
B. Setting up your mail client
1. Setting up Mail.app
Open up Mail, and choose Preferences... from the Mail menu. Click Accounts if you're not already there. Click on Create Account, and choose IMAP for the Account type. Enter Local as the Description, and enter your name and email in the respective locations(though these are not really needed. Enter localhost for Incoming mail server Hostn, and your username and password, which is the same as the MacOS X ones. Next, click Advanced, then enter Library/Mail/imapstore in the box labeled IMAP Path Prefix box. Finally, click OK.
2. Setting up other mail clients
This will vary from client to client. The procedure should be similar however. You might want to read the manual or help files for you client for information on how exactly to set it up like here. Basically, create a new IMAP account. For the any addresses, enter 127.0.0.1. Enter the User Name and Password that you set up MacOS X with for the resepective settings in the setup window.
 
V. Testing
To test the system, open up the terminal. Enter
mail root |
Enter some words, followed by a dot in a line by itself. Now open up Mail, and check your mail. It should work. If it doesn't, open up the Console application in the Application folder. See if any error messages relating to mail comes up. You can also open the mail specific log. To do that, go to the Console, choose Open Log from the Console menu, type /var/log in the go to box, then choose mail.log. If you can't figure it out send me some email and I'd be glad to help you out.
 
VI. Fixing Mail.app with Unix mail
Mail seems to have a problem getting Unix mail. It will get it one time, and then fail to get any more after that. Other mail seems to be fine after this, but it won't get Unix mail. I have tracked this problem down to a file in ~/Library/Mail named UNIX/@. Deleting this file will allow Mail.app to get Unix mail for one time, whereas it creates that file again and refuses to get Unix mail anymore. I've created an AppleScript to move this file to the Trash. It should be run right before you wish to check on Unix Mail. Download it here: ResetMail 1.0.0
 
VII. Conclusion
Congratulations. You now should get daily system logs in the Local account in Mail. As I said above: If you need any help, send me some email and I'd be glad to help you out.
 
Revision O- Added instructions on removing NetInfo configuration preference.
Revision N- Updated for new imap build and SSL problems.
Revision M- Updated for Mac OS X 10.2
Revision L- Added note about permissions of sendmail, changed a few lines, added a sample cron report, fixed instructions on console, and improved on the formatting of the page.
Revision K- Added note about problems with Mail.app and Unix mail.
Thanks to the following people for their help:
Robert Mohns | Helped with sendmail and pine, and with Unix in general |
Darkshadow | Gave directions for bypassing imap and using Mail.app directly |
Roger Morris | Gave location to have imap point too(mail subdirectory) |
Dennis Munsie | Pointed out that restart inetd is all that is needed, and that using su instead of multiple su can be used |
Fredrik Jonsson | Gave info on using Mail directly instead of imap |
jraser | Pointed out a spelling mistake |
Kyle R. Green | Pointed out correct directory for imapd, pointed out error in copy, noted that only imap, and not pop is needed |
Uli Zappe | Gave directions for using Mail.app directly, pointed out some steps involving sendmail that weren't needed |
Frank Coe | For the tip about Stuffit 5.5 |
Forrest Walter | For suggesting putting up the cron report, among other corrections |
Michel Pasquier | For pointing on an error in opening mail.log |
James Duncan Davidson | For his excellent tutorial on sendmail and OSX at O'rielly's Mac Dev Page |
Gregory Neil Shapiro | For instructing me on the NetInfo problem. |
Daniel J. Luke | For finding the NetInfo problem originally. |