For an application I need to send personalized invitation emails to end-users every hour. Those users email-addresses, and the rest of their information are in the database.
Planned.IsPlannable
set to True
and
have a Planned.DateStart
and a
Planned.DateEnd
between a certain
period are available for receiving an
email message. There are at least two scenarios to choose from: retrieving the appropriate data via a
1:) View something like:
SELECT [Computer].ComputerName,
[User].UserEmail,
[Planned].DateAvailable,
[Planned].DatePlanned
FROM [Computer]
INNER JOIN
[Planned] ON [Computer.ComputerID] = [Planned.ComputerID]
INNER JOIN
[User] ON [Computer].UserID = [User].UserID
WHERE (DATEDIFF(dd, GETDATE(), [Planned.DateAvailable]) < 10)
AND Planned.IsPlannable = 1
and compose, based on the results of this view, the appropriate messages in the C# code of this application.
2:) Compose the entire message on the sql-server in the view and return something like
[EmailTo]
[Subject]
[Body]
Then only iterate trough the results and create MailMessage
Objects from it
in both cases I get the messages like:
foreach (vwGetInvitableComputer u in UserController.GetAllInvitableUsers())
{
// where the usercontroller wraps the Subsonic logic.
// the composition happens here
}
Iterate trough that in the C# code and just compose the mailmessage from that preformatted data.
What scenario is performance and resources wise to choose?
update: There is indeed text manipulation in the database in option 2. However, this is replacing three strings in the messagbody to the CompterName, DateStart and DateEnd.Perhaps, SQL-views are smart enough to spread the performance for this, while the c# code does it "when requested"?
First consideration: Can you envision a time when changing the emails format will become necessary? If not then it probably doesn't matter.
Second consideration: Can you envision a time when the emails will require more manipulation than SQL is easily capable of delivering? If so then you definitely should choose C#.
Third consideration: How problematic would a redeploy be for the environment?
And finally an alternative option: Use C# for the message composition, but use a database or file based Template that can easily be updated.