19.3 Mail Aliases

     

Mail aliases allow our users to use an email address that looks like their real name , for example, charles.keenan@hp.com . Forget the hp.com part for the moment. The fact that you can send a user called charles.keenan an email is because sendmail , as an MTA, does not have a care in the world about the username (okay, you could have a local alias for charles.keenan@hp.com, but it is highly unlikely ). sendmail is simply going to decipher the hostname component of the address; it identifies the @ symbol and knows to route email using the SMTP protocol to the host on the right side of the @ symbol. When it arrives at that host, sendmail needs to deliver the email to a user called charles.keenan . That's where aliases come in. The aliases database ( /etc/mail/aliases.db ) is compiled from the text file /etc/mail/aliases using the newaliases (or sendmail “bi ) command. The aliases.db file is read by sendmail at startup time. To add a new alias, we add it to the aliases text file and rerun newaliases , hence, rebuilding the aliases.db file and signaling to the sendmail daemon the newly available aliases. In this example, I am adding three aliases for three real UNIX users:

 

 root@hpeos003[mail]  pwd  /etc/mail root@hpeos003[mail]  vi aliases  ... # Local aliases  charles.keenan   :       charlesk   fred.flinstone  :       fred   barney.rubble   :       barney  root@hpeos003[mail]  newaliases  /etc/mail/aliases: 10 aliases, longest 9 bytes, 147 bytes total root@hpeos003[mail]  praliases  postmaster:root operator:root daemon:root ftp-bugs:root charles.keenan:charlesk @:@ mailer-daemon:root nobody:/dev/null uucp:root fred.flinstone:fred barney.rubble:barney root@hpeos003[mail] 

In this way, if someone sends an email to fred.flintstone , it should be delivered to the UNIX user called fred :

 

 root@hpeos003[mail]  mail fred.flinstone@hpeos003  hello fred, fancy a beer??? Charles K root@hpeos003[mail] root@hpeos003[mail] ... fred@hpeos003[fred]  id  uid=105(fred) gid=20(users) fred@hpeos003[fred]  mail  From root@hpeos003.hq.maabof.com Thu Oct 23 09:34:06 BST 2003 Received: (from root@localhost)         by hpeos003.hq.maabof.com (8.11.1 (Revision 1.5) /8.9.3) id h9N8Y6r02834   for fred.flinstone@hpeos003   ; Thu, 23 Oct 2003 09:34:06 +0100 (BST) Date: Thu, 23 Oct 2003 09:34:06 +0100 (BST) From: root@hpeos003.hq.maabof.com Message-Id: <200310230834.h9N8Y6r02834@hpeos003.hq.maabof.com> hello fred, fancy a beer??? Charles K ?  d  fred@hpeos003[fred] 

These aliases are for the delivery of mail to a user. We can also add an :include statement, which will send the email to the list of usernames in the file specified with the :include statement:

 

 root@hpeos003[lists]  vi /etc/mail/aliases  ... # Local aliases charles.keenan  :       charlesk fred.flinstone  :       fred barney.rubble   :       barney  admins          :       ":include:/etc/mail/lists/admins"  root@hpeos003[lists]  newaliases  /etc/mail/aliases: 12 aliases, longest 33 bytes, 216 bytes total root@hpeos003[lists]  praliases  postmaster:root operator:root daemon:root ftp-bugs:root charles.keenan:charlesk admins:":include:/etc/mail/lists/admins" joinlist:/etc/mail/bin/mailers @:@ mailer-daemon:root nobody:/dev/null uucp:root fred.flinstone:fred barney.rubble:barney root@hpeos003[lists]  cat /etc/mail/lists/admins  root charlesk fred wilma root@hpeos003[lists] 

In this case, an email to admins@hpeos003 would be distributed to all the email addresses listed in the file /etc/mail/lists/admins . In some instances, sendmail may reject the request if we are trying to relay an email via our host (a common trick for spammers).

In a similar way, we can set up an alias that actually runs a program or shell script. In this example, I am going to run a program called /etc/mail/bin/mailers whenever I receive an email for the user known as joinlist :

 

 root@hpeos003[mail]  vi /etc/mail/aliases  ... # Local aliases charles.keenan  :       charlesk fred.flinstone  :       fred barney.rubble   :       barney admins          :       ":include:/etc/mail/lists/admins"  joinlist        :       /etc/mail/bin/mailers  root@hpeos003[mail]  newaliases  /etc/mail/aliases: 11 aliases, longest 22 bytes, 177 bytes total root@hpeos003[mail] 

Writing such a program/script may take some time, because you need to understand the format of the SMTP header and envelope; just send yourself an email and you can read the header and envelope via the mail command. Here is my simple example of the /etc/mail/bin/mailers script, which will send you back an email stating that you have been added to a mailing list.

 root@hpeos003[mail]  cat /etc/mail/bin/mailers  #!/sbin/sh while read Line do         for token in $Line         do                 case $token in                 'From:')        set $Line                         shift                         FROM=$(print )                         ;;                 'Subject:')     set $Line                                 shift                                 SUBJECT=$(print $*)                                 ;;                 esac         done done if [[ -n "$FROM" ]] then         if [[ -n "$SUBJECT" ]]         then                 USERNAME=$(awk -F@ '{print }')                 mailx -s "Re: $SUBJECT" $FROM <<-EOF                 Thank you $USERNAME,                 You have been added you to the "$SUBJECT" mailing list."                 EOF         else                 USERNAME=$(echo $FROM  awk -F@ '{print }')                 mailx -s "Re: $SUBJECT" $FROM <<-EOF                 Thank you $USERNAME,                 You didn't include a subject heading, hence we don't                 know which mailing list you want to join.  Try again.                 EOF         fi fi exit 0 root@hpeos003[mail] 

In this very simple example, if a user sends an email to joinlist with something in the Subject heading, I will email them back that they have been added to that mailing list (I ignore the body of the email because the mailing list must be identifiable in the Subject heading):

 

 fred@hpeos003[fred]  mailx -s "security updates" joinlist@hpeos003   please add me to the above mailing list  EOT fred@hpeos003[fred] 

Now, fred should get a response saying that he has been added to the appropriate mailing list:

 

 fred@hpeos003[fred]  mail  From daemon@hpeos003.hq.maabof.com Thu Oct 23 11:39:33 BST 2003 Received: (from daemon@localhost)         by hpeos003.hq.maabof.com (8.11.1 (Revision 1.5) /8.9.3) id h9NAdXS03563         for fred@hpeos003.hq.maabof.com; Thu, 23 Oct 2003 11:39:33 +0100 (BST) Date: Thu, 23 Oct 2003 11:39:33 +0100 (BST) From: daemon@hpeos003.hq.maabof.com Message-Id: <200310231039.h9NAdXS03563@hpeos003.hq.maabof.com> To: fred@hpeos003.hq.maabof.com Subject: Re: security updates Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit  Thank you fred,   You have been added you to the "security updates" mailing list."  ? q fred@hpeos003[fred] 

Obviously, this is a simple example, but you get the idea.



HP-UX CSE(c) Official Study Guide and Desk Reference
HP-UX CSE(c) Official Study Guide and Desk Reference
ISBN: N/A
EAN: N/A
Year: 2006
Pages: 434

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net