Email and Event Factory classes

Rating: No reviews yet
Downloads: 35
Released: Aug 9, 2009
Updated: Aug 10, 2009 by paxer
Dev status: Beta Help Icon

Recommended Download

Source Code Source And Example
source code, 11K, uploaded Aug 10, 2009 - 35 downloads

Release Notes

Below you can find two classes which will be included in .Net Factory Framework. Both are easy but helpful for sending emails and writing event log.

Email Factory Features
  • Unlimited email group settings (Mode). It could be for example number of settings for Test and Production environments.
  • Working with predefined email templates with placeholders.
  • Ability to save email content to hdd after sending.


Event Factory Features
  • Flexibble and easy to use.
  • Colors for each event for easy implementation UI in html.
  • Several notification modes like Save event on HDD or Email event or Both.
  • XML based



Email Factory usage example

    #region Email Factory Using Example

    protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        //create key value dictionary for parse and replace placeholders in email template
        Dictionary<string, string> templateKeyValues = new Dictionary<string, string>();

        //this is example for existing placeholders in EmailTemplates/test.template
        templateKeyValues.Add("{%FIRST_NAME%}", "Jack");
        templateKeyValues.Add("{%LAST_NAME%}", "Sparrow");

        EmailFactory email =  new EmailFactory(); // this will fire with the default mode which is setup in Email.Config
        //EmailFactory email = new EmailFactory("production"); // We can also set mode manualy 
        //EmailFactory email = new EmailFactory("test");
        
        bool sendingStatus = false;
        try
        {
            //you can send mail to multiple addresses
            //email.SendMail(new string[] { "username@domain.com","username2@somedomain.com" }, "test.template", templateKeyValues);

            string[] toEmails = new string[] { tbxSendToEmail.Text };
            string[] attachedFilesPath = null;
            if (FileUpload1.FileName != string.Empty)
            {
                attachedFilesPath = new string[] { this.UploadFiles() };
            }
            sendingStatus = email.SendMail(toEmails, "test.template", templateKeyValues, attachedFilesPath);
        }
        catch (Exception ex)
        {
            //log error
        }
       
       if (sendingStatus)
           lblStatus.Text = "Mail sending successfull";
       else
           lblStatus.Text = "Mail was not sent, becouse of email mode is disabled";
       
        
    }





Event Factory usage example

    #region Event Factory Using Example

    protected void btnAddEvent_Click(object sender, EventArgs e)
    {
        
        EventType eventType = EventType.Information;//default 

        switch (cbxErrorTypes.SelectedValue)
        {
            case "Information":
                eventType = EventType.Information;
                break;
            case "Warning":
                eventType = EventType.Warning;
                break;

            case "Error":
                eventType = EventType.Error;
                break;                

        }

        EventFactory.AddEvent(eventType, tbxEventDescription.Text, EventNotificationType.Save);
        
       //EventFactory.AddEvent(EventType.Error, "Problem Descritpion", EventNotificationType.Save);
        //EventFactory.AddEvent(EventType.Error, "Problem Descritpion", EventNotificationType.Email);
       //EventFactory.AddEvent(EventType.Error, "Problem Descritpion", EventNotificationType.EmailAndSave);
       //EventFactory.AddEvent(EventType.Error, EventColor.Red, " Some Description", EventNotificationType.Save);
        Response.Redirect("~/Default.aspx");
    }

    #endregion

Reviews for this release

No reviews yet for this release.