Our Approach to email handling email in one of our Multi Client SaaS products.
Ok, so to start off with... We have the following Objects
Company (Top Level)
ApplicationUsers
EmailAddress
ParsedEmailAddress
OutgoingEmail
ReceivedEmail
Relationships Are As Follows:
Company --0< ApplicationUsers
Company --0< EmailAddresses
Company --0< OutgoingEmails
Company --0< ReceivedEmails
ReceivedEmail |--<0 ParsedEmailAddresses
So Basically, we setup rules on ApplicationUser that register a new email address
and link it to the company of that administrator. If he chooses an email that
already belongs to another company, we report error and he must choose another.
Thus an ApplicationUser can Choose any emailaddress already linked to His company,
or if he selects a new one not already xisting and being used by another company then
we register that emailaddress and link it to his company.
We also have a regular expression on the ApplicationUser.EmailAddress Field making
sure that He can ONLY select an email address for the domain that we have chosen.
For example '@mysaasproduct.net'. So the email a customer select might be something
like mycompany123@mysaasproduct.net and all emails he sends from the system will then
have that as the FROM address in the outgoing email.
Ok so for sending emails it is then very simple... Wherever you do a ENTER NEW OutgoingEmail
you just do a WITH OutgoingEmail.FromAddress=LoggedInApplicationUser.EmailAddress.
Then, same as you we have setup a Catchall email box for our domain. So all email
replies will then go to that email box which gets polled from AwareIM.
So when a new Email Notification Comes In We Create a ReceivedEmail Record as you would normally.
However we have an attribute on ReceivedEmail Called 'StringToParse'. So Whenever a new
Received Email Is Registered We Do:
// If ReceivedEmail IS NEW Then
// ReceivedEmail.StringToParse=ReceivedEmail.ToAddress+' '+ReceivedEmail.CC+' '+ReceivedEmail.BCC
Then we have another Rule:
// If ReceivedEmail IS NEW AND ReceivedEmail.StringToParse WAS CHANGED Then
// ParseEmailsFromReceivedMail
'ParseEmailsFromReceivedMail' is a Custom Process Which my brother wrote for us in Java which basically
takes the StringToParse Attribute, and creates ParsedEmailAdress Objects for each email address in that
string and then links those ParsedEmailAddresses to the ReceivedEmail.
Then on the ParsedEmailAddress We have the Following Rules to see if any of the parsed emails already
Exisit in the system as EmailAddresses Registered by users. It there is then we find the company that
Email Address Belongs to and make the link:
// If ParsedEmailAddresses IS NEW AND EXISTS EmailAddress WHERE
(EmailAddress.EmailAddress=ParsedEmailAddresses.EmailAddress) Then
// FIND ReceivedEmail WHERE ParsedEmailAddresses.ReceivedEmail=ReceivedEmail
// FIND EmailAddress WHERE EmailAddress.EmailAddress=ParsedEmailAddresses.EmailAddress
// FIND Company WHERE EmailAddress IN Company.EmailAddresses
// INSERT ReceivedEmail IN Company.ReceivedEmail
And that is that. π
I Must say though that we do have hick ups here and there with the email Poller That stops so we have to
monitor that on a daily basis, but I have set it up now as a Process to connect to email Account and not
on system Settings. This way if it does stop I can manually disconnect and reconnect without bringing
the server down.
Also I find that if someone Sends email to the CatchAll@mysaasproduct.net box with a lot of attachments
AwareIM does not process that and it gets left on the server. So ideally you should tell your clients
to tell their clients not to send 10 attachments in 1 Email. π Or Support should maybe investigate
and optimise this process a bit further.
We Use Rackspace for the hosting of our Catchall email account.
Hope that helps and can maybe inspire some Aware Users who are struggling with the emails. I know it took
us Darn long to get it working the way it does now. But I'm pretty happy with how it works at the end of the day.
The only thing I would recommend from day one is to do all your Attachments for outgoing and incoming in a
File System and not the Data Base. I am currently working on a process to Export all the existing attachments
and then switch over as I can see those tables are growing VERY quickly so one would definitely not want to
store all the attachments as blobs if you are going to have a lot of incoming and outgoing emails.
Kindest Regards & I Hope this helps some peeps!
Hein