Know this has been asked before, however my question is slightly different.
I have an interface:
IEmailDispatcher
It looks like this:
public interface IEmailDispatcher
{
void SendEmail(string[] to, string fromName, string fromAddress, string subject, string body, bool bodyIsHTML, Dictionary<string, byte[]> Attachments);
}
As a bit of background:
I have a static EmailDispatcher class that has the method: SendEmail(string[] to, string fromName, string fromAddress, string subject, string body, bool bodyIsHTML, Dictionary Attachments);
This, throught IoC, then loads the relevant IEmailDispatcher implementation, and calls that method.
My applications can then simply call EmailDispatcher.SendEmail(.........
I want to add events to it, for example OnEmailSent, OnEmailFail etc... So that each implementation can handle successes and failures of sending emails, and log them accordingly.
How would I go about doing this?
Or, is there a better way?
At the moment, I'm using a "BasicEmailDispatcher" that basically uses the System.Net namespaces, creates a MailMessage, and sends it.
In the future, I will create another class, that handles mail differently... adds it to a sql db table for reporting etc.... and so will handle the OnEmailSent events differently to the BasicEmailDispatcher