Posted By

uptimejeff on 10/15/10


Tagged

mail server osx alias postfix group osxserver 107 lion 106


Versions (?)

OSX Server - Group EMail Enabler v0.2


 / Published in: Bash
 

If you have any contributions, please comment here.

  1. #!/bin/bash
  2.  
  3. # Group EMail Enabler v0.2
  4. # Jeff Johnson <[email protected]>
  5.  
  6. # Tested with OS X Server 10.6 and 10.7
  7. # Should also work with 10.5
  8.  
  9. # This script allows you to manage email groups using Work Group Manager.
  10. # If you create an executive group in WGM, you then have a executive@ email address
  11. # This is automatically maintained as you adjust the members
  12.  
  13. # The script searches your LDAP groups for the word 'mail' in the comment field
  14. # You must add mail to the comment field for any group which should have an email address.
  15. # The email address for that group will be the shortname of that group.
  16. # If you miss this step (add 'mail' to the comment field), this script does nothing.
  17.  
  18. # Known issues
  19. # 1. Only supports groups in LDAP, users can be in LDAP or Local
  20. # 2. Does not support other groups within your email group (no nested groups)
  21. # 3. Almost no error checking, so best to run it manually a few times to check results.
  22.  
  23. # Installation Instructions
  24. # 1. Save this file as
  25. # /usr/sbin/group_email.sh
  26. # 2. Then adjust permissions
  27. # sudo chmod +x /usr/sbin/group_email.sh
  28. # 3. Modifiy alias_maps in /etc/postfix/main.cf
  29. # You need to add this line to what you already have
  30. # hash:/etc/postfix/group_aliases
  31. # Example, you have:
  32. # alias_maps = hash:/etc/aliases
  33. # Change to:
  34. # alias_maps = hash:/etc/aliases, hash:/etc/postfix/group_aliases
  35. # 4. To run automatically every 5 minutes, I prefer a simple addition to /etc/crontab
  36. # you may need to create /etc/crontab if it doesn't exist
  37. # Add the following to /etc/crontab
  38. # */5 * * * * root /usr/sbin/group_email.sh >> /dev/null 2>&1
  39. #
  40. # If you followed these instructions, within 5 minutes you will see an alias file at
  41. # /etc/postfix/groupaliases
  42. # you can inspect the file to confirm the results.
  43.  
  44.  
  45. cd /etc/postfix
  46.  
  47. # clear current aliases
  48. echo "" > group_aliases.tmp
  49.  
  50. # Get list of groups with 'mail' in the comment field
  51. gr=`dscl /LDAPv3/127.0.0.1 -list /Groups Comment | grep mail | awk '{print $1}'`
  52.  
  53. for group in $gr
  54. do
  55. echo $group: `dscl /LDAPv3/127.0.0.1 -read /Groups/$group dsAttrTypeNative:memberUid | cut -d : -f 3 | grep -v "No such key"` >> group_aliases.tmp
  56. done
  57.  
  58. cmp -s group_aliases.tmp group_aliases > /dev/null
  59. if [ $? -eq 1 ]; then
  60. echo different
  61. cp group_aliases.tmp group_aliases
  62. /usr/sbin/postalias /etc/postfix/group_aliases
  63. /usr/bin/newaliases
  64. else
  65. echo same
  66. fi
  67.  
  68. exit

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Boddie on October 16, 2010

To work with mail anywhere in the Comment field Change line 38 to:

gr=dscl /LDAPv3/127.0.0.1 -list /Groups Comment | grep mail | awk '{print $1}'

Boddie

Posted By: uptimejeff on October 21, 2010

Edited.... Thanks Boddie

Posted By: iindie on January 7, 2011

hello everyone after some searching i got the script to work with SLS. please feel free to re edit if you chose this script works with local nodes but i guess it should not be too much of a problem getting it back to full OD consistency.

!/bin/bash

Group Email Enabler is a simple script which fixes a shortcoming in OS X Server 10.6

by allowing each WGM group to automatically become an email list for it's members.

#

Jeff Johnson [email protected]

#

To install

1. save this file as

/usr/sbin/group_email.sh

2. sudo chmod +x /usr/sbin/group_email.sh

3. touch /private/var/log/group_email.log

4. adjust /etc/postfix/main.cf, add the following to "alias_maps="

hash:/etc/postfix/group_aliases

5. add the following to /etc/crontab (you may need to create /etc/crontab)

*/15 * * * * root /usr/sbin/group_email.sh >> /private/var/log/group_email.log

To use

When the script runs, it searches for any WGM group in /LDAPv3/127.0.0.1 the word "mail"

within the comment field. Postfix aliases with group members are then created.

#

If you create a group called 'employees' and put all staff in that group, you will

then have an email setup of [email protected]

#

Be sure all mail groups contain at least one member

Would like to add/modify

1. needs error trapping. a group without members returns an error.

2. support for non-local LDAP

clear current aliases

echo "" > /etc/postfix/group_aliases

Get list of groups with 'mail' in the comment field

gr=dscl . -list /Groups Comment | grep mail | awk '{print $1}'

for group in $gr do echo $group: dscl . -read /Groups/$group 'GroupMembership' | cut -d : -f 2 | grep -v "No such key" >> /etc/postfix/group_aliases done

/usr/sbin/postalias /etc/postfix/group_aliases /usr/bin/newaliases exit 0

You need to login to post a comment.