How can I send up to 5 people and email alert that a contract is about to expire?
Posted on 2016-07-14
Our company has many, many contracts, with responsible persons in multiple departments of our company.
I'm tasked with developing a database of these contracts and their expiration dates and a system where alerts are sent to up to 5 people when a contract is within 90 days, 60 days, 30 days and 15 days of expiring. (The db and input form are done.)
So for a given contract, when its expiration date is exactly 90 days from expiration, one email is sent to the email addresses listed in the database. Then at 60 days prior to expiration another email is sent to them. Etc...
I've tried many solutions using sp_send_dbmail (T-SQL) and just can't find one that works for this scenario.
The first issue, I can't get multiple email addresses into the @recipients parameter from multiple table columns (email01, email02, email03, etc.)
Another issue I foresee is when more than one different contract expires on the same day, sending the appropriate messages to the appropriate recipient(s).
I'm wondering if there's a better approach, entirely; not using sp_send_dbmail. The data input form for the table for this thing is in ASP.Net 4.0 and C# codebehind. I could put the system in the codebehind of the input form, but that would require someone opening the form in order to trigger the check for expiring contracts. I need the check to happen every single day. The form may not be used for weeks at a time.
The single table has the following columns:
Company VARCHAR (100)
ExpirationDate (date, null)
This is a huge thing for my company. I really want to find a good solution. It seems pretty simple, but I'm stumbling terribly on it. Thanks in advance.