Lab #16: Sendmail
Date: April 9, 2008
Due Date: April 21, 2008

In this lab, we'll set up an e-mail client/server system. If you have any problems with sendmail, check for log entries in /var/log/maillog and bounced messages in /var/spool/mail/root.

Sendmail server

  1. Turn off sendmail.
    su
    service sendmail stop
    
  2. Install sendmail configuration and documentation. The base sendmail package is already installed.
    yum install sendmail-cf sendmail-doc
    
  3. Find the sendmail configuration directory and cd to that directory.
    rpm -ql sendmail-cf
    
  4. Set up a new cf directory.
    mv cf cf.examples
    mkdir cf
    cp -p cf.examples/Build cf
    cp -p cf.examples/Makefile cf
    
  5. Create a new m4 configuration file for your mail server. You may want to base it off of one of the example files in cf.examples. The README file documents all of the mc file options.
    cd cf
    vim cit470.mc
    
  6. Build a cf file from the mc file.
    ./Build cit470.cf
    
  7. Read the newly produced cf file. Notice how much code was generated from your short m4 configuration.
    less cit470.cf
    
  8. Add your fully qualified domain name to /etc/hosts. Be sure that the fully qualified name cit470.nku.edu is the first name listed for your IP address. If you don't do this, sendmail -bt in the next step will hang.
    vim /etc/hosts
    
  9. Use sendmail's address test mode to test your new configuration file. Verify that it correctly transforms local addresses (for localhost, your unqualified hostname, and your fully qualified machine name) and remote addresses. The ? command provides help for address test mode. If it doesn't indicate that local addresses should be delivered with mailer local and the correct username and that remote addresses should be sent to the appropriate remote mail server, edit your mc or hosts file to fix the problem.
    sendmail -C cit470.cf -bt
    > ?
    > /parse student@localhost
    > /parse student@cit470
    > /parse student@cit470.nku.edu
    > /parse student@nku.edu
    > /quit
    
  10. Copy your configuration file into the standard location.
    cp cit470.cf /etc/mail
    cd /etc/mail
    mv sendmail.cf sendmail.cf.dist
    mv cit470.cf sendmail.cf
    
  11. Start sendmail
    service sendmail start
    

Using mail

  1. Send mail to your student user using sendmail. Watch the SMTP transaction that verbose mode shows you. Also note how the address you supply is transformed.
    sendmail -v student
    Subject: test
    
    This is a test
    .
    
  2. Read the student mail spool to see the received message. Note all of the headers that were added. How many received headers were produced and why?
    less /var/spool/mail/student
    
  3. Send mail to the same user with a different address format. Does this change how sendmail rewrites the address? Does it match what you saw in address test mode?
    sendmail -v student@myservername
    Subject: u@h format test
    
    This is a yet another test message.
    .
    
  4. Read the student mail spool to see the new message. How are the headers different with this message? How does the mbox spool format separate messages?
    less /var/spool/mail/student
    
  5. Send mail to your NKU e-mail account. How is the SMTP dialog different from the case of local e-mail? Go to your NKU e-mail account and read the message.
    sendmail -v student@nku.edu
    Subject: Remote server mail test
    
    Test ///.
    .
    

sendmail client

Use the virtual machine as the client host.

  1. Create a client mc file. This should use the nullclient feature we discussed in class and should send all mail to the server created above.
    cd cf
    vim client.mc
    
  2. Build a cf file from the mc file.
    ./Build client.cf
    
  3. Read the newly produced cf file.
    less client.cf
    
  4. Use sendmail's address test mode to test your client configuration file. It should send all mail to your server. No mail should be delivered locally.
    sendmail -C client.cf -bt
    > ?
    > /parse student@localhost
    > /parse student@cit470
    > /parse student@cit470.nku.edu
    > /parse student@nku.edu
    > /quit
    
  5. Copy your configuration file to your client.
    sftp root@MY_CLIENT_IP
    
  6. On the client, copy client.cf to /etc/mail/sendmail.cf.
    su
    cd /etc/mail
    mv sendmail.cf sendmail.cf.dist
    cp client.cf sendmail.cf
    
  7. On the client, add the fully qualified domain names of client and server to /etc/hosts. Be sure that the fully qualified name is the first name listed for your IP address.
    vim /etc/hosts
    
  8. Restart sendmail on the client.
    service sendmail restart
    
  9. On the client, send mail to your local student user using sendmail. How is the SMTP dialog different from sending mail on the server?
    sendmail -v student
    Subject: Client: test
    
    Client test I.
    .
    
  10. You'll see that mail delivery fails because the client can't communicate with sendmail on the server. Check the mail queue to verify that your message wasn't lost due to the failure.
    mailq
    
  11. To fix this problem, open the SMTP port on the server firewall so that you will be able to use your client with the server.
    grep smtp /etc/services
    vim /etc/sysconfig/iptables
    service iptables restart
    
  12. Process the mail queue on the client so that your previous e-mail message will be delivered.
    sendmail -v -q
    
  13. On the server, read the student mail spool to see the new message. How are the headers different from a message send directly on the server?
    less /var/spool/mail/student
    
  14. On the client, send mail to your NKU e-mail account. Watch the verbose output carefully.
    sendmail -v student@nku.edu
    Subject: Client: Remote server mail test
    
    Client test ][.
    .
    
  15. The server refused to relay our previous message, so we need to reconfigure sendmail to support relaying and add our client to the list of allowed relay hosts on the server, then try resending the message. You may need to edit files beyond those mentioned below.
    cd cf
    vim cit470.mc
    ./Build cit470.cf
    cp cit470.cf /etc/mail/sendmail.cf
    service sendmail restart
    
Submission: Turn in the answers to the lab questions as a file named lab.txt and also turn in your final cit470.mc and client.mc files.
 

©2008 James Walden, Ph.D.