Results 1 to 4 of 4

Thread: my quick and dirty round robin style delivery for sales

  1. #1
    Join Date
    Mar 2007
    Rep Power

    Default my quick and dirty round robin style delivery for sales

    I wanted to do some post processing of email in a round robin manner where by all email going to sales@ would be evenly distributed among our sales team, in the past we had a line in /etc/aliases to process the sales@ messages as they arrived in, which I am aware we can still have. however I missed this during the initial migration, and had let the sales email queue pile up for a month. I had to come up with something quick for now, otherwise risk mutilation from the sales team. I had wanted to do a nifty ruby script which worked directly via SOAP, REST and or some other API however could not find anything which I could easily get working. So I started to dig into the utils and came up with the following shell script... it gets the inbox count size, builds a loop to process that inbox, and then evenly distributes those emails to whoever is in the agents array...

    preqs for this script were the creation sub-folders in the targets inbox for the msg to be moved into (this can easliy removed to just delete the msg, but we wanted to have some idea of what was going where), and specifying of the agents, and target user account... in the future we will be going back to the /etc/aliases | option, since my shell script would favor those at the beginning of the array as time goes on. Also it writes the msg's to a local file temporarily which the zimbra user must have write access to, this file also could be considered a security risk as it could be monitored, so use at your own risk.. However for now it gets the job done... albeit very slowly... takes a couple seconds to process each message, however we have a low enough inbound that I can run this via crontab every 15 minutes and it does not have any problems.

    See Next post for cleaner script.
    Also I am looking to do some agent stats such as inbound and outbound counts daily for the sales agents any ideas in that regard would be appreciated.

    Last edited by skout23; 07-17-2007 at 10:44 AM.

  2. #2
    Join Date
    Mar 2007
    Rep Power

    Default cleaner still slow round robin delivery

    Cleaned up the script, removed variables which could be determined, put in tests for empty msgids, and added some logic for cases where the current msg count is less than the agent count. Think I won't be adding any more to this.

    # Not so quick RoundRobin split of a target inbox
    # by Scott Stout
    # modify all targetInbox to the inbox you want to roundrobin
    # modify the agents array to your agents list
    # Current target inbox
    # current agents as per the former database.
    agents=( salesagent1 salesagent2 salesagent3 salesagent4 )
    # Current agent count
    # file used as temp scratch to copy/move the emails.
    # Get Current inbox size
    CurrentMsgCount=`zmmailbox -m $targetInbox -z gf /inbox | grep messageCount | awk '{ print $2 }' |  sed s/","$//`
    # divide the inbox size by the current number of sales agents to get the number of iterattions 
    if [ $CurrentMsgCount -le $agentCount ]; then
      COUNTER=$(( (CurrentMsgCount / agentCount) + 1 ))
    # set the main until loop to begin the countdown
    until [ $COUNTER -le 0 ]; do
    # RoundRobin itteration of the agents array
      for agent in ${agents[@]}
    # Zero out the last Msg ID
    # Get current inxbox message ID
    CurrentMsgID=`zmmailbox -m $targetInbox -z s -t message -l 1 "in:inbox" | grep "^1\." | awk '{ print $2 }'`
    if (( ${#CurrentMsgID} > 2 )); then
    # Copy Msg to local file
    zmmailbox -m $targetInbox -z gm $CurrentMsgID > $localfile
    # Add Msg to Current Agent
    zmmailbox -m $agent -z am "/inbox" $localfile
    # move Msg to Agent's Folder
    zmmailbox -m $targetInbox -z mm $CurrentMsgID /$agent
    # clear out the local file
    cp /dev/null $localfile 
    # close the inner for loop
    # decrement the counter for the main loop
    echo "Loop Count: $COUNTER"
    let COUNTER-=1
    # close the main loop and exit
    # print a quick summary
    echo "Emails Processed: $CurrentMsgCount"
    Last edited by skout23; 07-17-2007 at 10:52 AM.

  3. #3
    Join Date
    May 2006
    Rep Power


    -It would be smart to leave them in the inbox of the sales account, so you can go back and review all leads in one place if necessary. Don't want someone fumbling the ball...
    V5 will have shared mail folders so they could review them all
    Last edited by mmorse; 11-29-2007 at 09:54 AM. Reason: added link because the shared folders are now possible

  4. #4
    Join Date
    Mar 2007
    Rep Power

    Default issues arrise

    So I keep getting complaints from the sales team that a bunch of emails are coming up with "???????? ??????? ????????" all over the place. I initially thought it was just some form of spam, and ignore it. Well it turns out that the script (see above posts) gets the target message and dumps it to a file, however can't seem to handle non us formats. I assume the script will work if I change the locale settings to include a more robust character set in the shell, however am in the process of migrating away from this script to a real-time script that the mail is piped to in the /opt/zimbra/path/to/aliases file.

    I think if zmmailbox had an option to just forward messages or converations to other users or external addresses, it would save a lot of hassle. At least for me it would.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts