Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to enable group email accounts

Hi all,


I have spent a while fiddling with (and breaking) my OSX Lion 10.7.4 Server install trying to get group emails working. I would just like to share how I did it.


Follow the below how to.


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


The only additional thing I had to do with Lion Server 10.7.4 was add hash:/etc/postfix/group_aliases to the alias_maps AND alias_database in /etc/postfix/main.cf then run "newaliases" and "postfix reload"


Hopefully this helps the next person to get it all running quicker than I did 🙂


Cheers

Ryan

Xserve, Mac OS X (10.7.4)

Posted on Aug 20, 2012 12:19 AM

Reply
10 replies

Aug 22, 2012 4:14 AM in response to Getting Technical

Cheers Ryan, I must have soemthing wrong as I'm just getting command not found.. When I try to run group_email.sh manually I'm getting these errors as well:


/usr/sbin/group_email.sh: line 1: {rtf1ansiansicpg1252cocoartf1187: command not found

/usr/sbin/group_email.sh: line 2: syntax error near unexpected token `}'

/usr/sbin/group_email.sh: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'


Did you create the crontab file in /etc?

Aug 22, 2012 6:08 AM in response to Getting Technical

Hi Ryan, yeah 10.7.4 Lion Server - mail is swtiched on although we haven'y migrated to it yet (i do have the accounts setup though)


Script:


#!/bin/bash


# Group EMail Enabler v0.2

# Jeff Johnson <jdj@mac.com>


# Tested with OS X Server 10.6 and 10.7

# Should also work with 10.5


# This script allows you to manage email groups using Work Group Manager.

# If you create an executive group in WGM, you then have a executive@ email address

# This is automatically maintained as you adjust the members


# The script searches your LDAP groups for the word 'mail' in the comment field

# You must add mail to the comment field for any group which should have an email address.

# The email address for that group will be the shortname of that group.

# If you miss this step (add 'mail' to the comment field), this script does nothing.


# Known issues

# 1. Only supports groups in LDAP, users can be in LDAP or Local

# 2. Does not support other groups within your email group (no nested groups)

# 3. Almost no error checking, so best to run it manually a few times to check results.


# Installation Instructions

# 1. Save this file as

# /usr/sbin/group_email.sh

# 2. Then adjust permissions

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

# 3. Modifiy alias_maps in /etc/postfix/main.cf

# You need to add this line to what you already have

# hash:/etc/postfix/group_aliases

# Example, you have:

# alias_maps = hash:/etc/aliases

# Change to:

# alias_maps = hash:/etc/aliases, hash:/etc/postfix/group_aliases

# 4. To run automatically every 5 minutes, I prefer a simple addition to /etc/crontab

# you may need to create /etc/crontab if it doesn't exist

# Add the following to /etc/crontab

# */5 * * * * root /usr/sbin/group_email.sh >> /dev/null 2>&1

#

# If you followed these instructions, within 5 minutes you will see an alias file at

# /etc/postfix/groupaliases

# you can inspect the file to confirm the results.



cd /etc/postfix


# clear current aliases

echo "" > group_aliases.tmp


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

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


for group in $gr

do

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

done


cmp -s group_aliases.tmp group_aliases > /dev/null

if [ $? -eq 1 ]; then

echo different

cp group_aliases.tmp group_aliases

/usr/sbin/postalias /etc/postfix/group_aliases

/usr/bin/newaliases

else

echo same

fi


exit



I've gone through it a few times and can't see any differences to the one you posted so am at a loss as to why its not working..


Thanks


Phil

Aug 22, 2012 6:08 AM in response to Getting Technical

Here is the script minus the line numbers just in case 🙂


#!/bin/bash



# Group EMail Enabler v0.2

# Jeff Johnson <jdj@mac.com>



# Tested with OS X Server 10.6 and 10.7

# Should also work with 10.5



# This script allows you to manage email groups using Work Group Manager.

# If you create an executive group in WGM, you then have a executive@ email address

# This is automatically maintained as you adjust the members



# The script searches your LDAP groups for the word 'mail' in the comment field

# You must add mail to the comment field for any group which should have an email address.

# The email address for that group will be the shortname of that group.

# If you miss this step (add 'mail' to the comment field), this script does nothing.



# Known issues

# 1. Only supports groups in LDAP, users can be in LDAP or Local

# 2. Does not support other groups within your email group (no nested groups)

# 3. Almost no error checking, so best to run it manually a few times to check results.



# Installation Instructions

# 1. Save this file as

# /usr/sbin/group_email.sh

# 2. Then adjust permissions

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

# 3. Modifiy alias_maps in /etc/postfix/main.cf

# You need to add this line to what you already have

# hash:/etc/postfix/group_aliases

# Example, you have:

# alias_maps = hash:/etc/aliases

# Change to:

# alias_maps = hash:/etc/aliases, hash:/etc/postfix/group_aliases

# 4. To run automatically every 5 minutes, I prefer a simple addition to /etc/crontab

# you may need to create /etc/crontab if it doesn't exist

# Add the following to /etc/crontab

# */5 * * * * root /usr/sbin/group_email.sh >> /dev/null 2>&1

#

# If you followed these instructions, within 5 minutes you will see an alias file at

# /etc/postfix/groupaliases

# you can inspect the file to confirm the results.





cd /etc/postfix



# clear current aliases

echo "" > group_aliases.tmp



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

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



for group in $gr

do

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

done



cmp -s group_aliases.tmp group_aliases > /dev/null

if [ $? -eq 1 ]; then

echo different

cp group_aliases.tmp group_aliases

/usr/sbin/postalias /etc/postfix/group_aliases

/usr/bin/newaliases

else

echo same

fi



exit

Aug 22, 2012 6:36 AM in response to phil.stone

Hi Phil,


If its the newalias command and the postfix reload command that's not working though that has little to do with the script. I hate to state the obvious but your account or the account your doing this with is someone that has administration rights? you are doing all this through sudo? the mail service/postfix is actually running? try sending mail between users locally maybe just to check? A reboot could be in order? Just some thoughts. My mainporblem I had when I did this was the main.cf part and once I worked that out everything worked out of the box..

Aug 22, 2012 8:24 AM in response to phil.stone

Ok so managed to get the group_mail to run correctly, created the group_aliases.tmp with the correct data, however it broke the email completely..


If I removed the changes to main.cf and deleted the group_aliases.tmp then restarted the mail server the emails resumed.


These errors on the mail server log kept repeating:


Aug 22 16:18:02 <servername> dovecot[96989]: master: Warning: Killed with signal 15 (by pid=1 uid=0 code=unknown 0)

Aug 22 16:18:02 <servername> dovecot[97010]: log: Warning: Killed with signal 15 (by pid=1 uid=0 code=unknown 0)

How to enable group email accounts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.