Counting lines and sending emails

What I am doing is running ps and search for any connection that is over a specified number, I set it to "1" for testing I want to send an email when any of them are over 50 I want them all in one email

Below is the code what I want is to display the output of ps and grepping for "httpd" to a single email what it does now is sends an email for each one

#!/bin/bash
ps aux |grep ftp| grep -v nobody|awk '{$1}  {++P[$1]} END {for(a in P) if (a !="USER") print a,P[a]}'| while read line;do
if [ $(echo "$line" | awk '{printf int($2)}') -gt 50 ];then
echo -e $line|mail -s "FTP Connections from Server Greater then 50" <email address>
fi
done

Can't you simply do:-

if [ $( ps aux | awk '/ftp/ && !/nobody/' | wc -l ) -gt 50 ]
then
      # Perform action
fi 

yes it will send an email but I won't know for which user

OK got it, then write to a file for instances that exceeded the defined threshold and send email in the end:-

rm -f mail.body
ps aux | awk '/ftp/ && !/nobody/ {++P[$1]} END {for(a in P) print a,P[a]}' OFS=, | while IFS=, read user inst
	if [ ${inst} -gt 50 ]
	then
		echo -e "User: $user Instances: $inst" >> mail.body
	done
do
cat mail.body | mail -s "FTP Connections from Server Greater then 50" <email address>