Beispiel #1
0
		/// <summary>
		/// Instanciante the merger and auto-fill it's properties with templater data.
		/// </summary>
		/// <param name="templater">The Templater object that contains the data.</param>
		public Merger(Templater templater)
		{
			this.Conditions = templater.Conditions;
			this.Regions = templater.Regions;
			this.FieldsFormats = templater.FieldsFormats;
			this.SmtpServers = templater.SmtpServers;
			this.Message = templater.Message;
			this.ListTemplates = templater.ListTemplates;
		}
Beispiel #2
0
 /// <summary>
 /// Instanciante the merger and auto-fill it's properties with templater data.
 /// </summary>
 /// <param name="templater">The Templater object that contains the data.</param>
 public Merger(Templater templater)
 {
     this.Conditions    = templater.Conditions;
     this.Regions       = templater.Regions;
     this.FieldsFormats = templater.FieldsFormats;
     this.SmtpServers   = templater.SmtpServers;
     this.Message       = templater.Message;
     this.ListTemplates = templater.ListTemplates;
 }
Beispiel #3
0
 /// <summary>
 /// Instanciante the merger and auto-fill it's properties with templater data.
 /// </summary>
 /// <param name="templater">The Templater object that contains the data.</param>
 public Merger(Templater templater)
 {
     Conditions    = templater.Conditions;
     Regions       = templater.Regions;
     FieldsFormats = templater.FieldsFormats;
     SmtpServers   = templater.SmtpServers;
     Message       = templater.Message;
     ListTemplates = templater.ListTemplates;
 }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {

            try
            {
                //Let us create a data source in this case Hastable that would 
                //used to demonstrate the merging
                // Take the form variables collection as the data source.
                Hashtable dataSource = new Hashtable();
                dataSource.Add("FIRSTNAME", _tbFirstName.Text);
                dataSource.Add("LASTNAME", _tbLastName.Text);
                dataSource.Add("EMAIL", _tbEmail.Text);
                dataSource.Add("ORDER_ID", _tbOrderId.Text);
                dataSource.Add("CUSTOMER_ID", "1");
                dataSource.Add("PRODUCTS_TEXT", (string)_comboProduct.SelectedItem);

                // We create the templater object.
                ActiveUp.Net.Mail.Templater templater = new Templater(@"MailTemplate_for_datasource.xml");

                // We instanciante the Merger object by passing the templater data.
                Merger merger = new Merger();

                // We merge our DataSource and send the mail.
                merger.MergeMessage(templater.Message, dataSource, false);

                this.AddLogEntry("Sending template message.");

                string smtp = string.Empty;

                if (_cbUseSmtpFromTemplate.Checked)
                {
                    smtp = templater.SmtpServers[0].Host;
                }
                else
                {
                    smtp = smtpServerAddressTextbox.Text;
                }

                templater.Message.Send(smtp);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            this.AddLogEntry("Creating templater.");

            // We create the templater objet.
            try
            {
                ActiveUp.Net.Mail.Templater templater = new Templater(@"MailFormat.xml");

                this.AddLogEntry("Sending template message.");

                string smtp = string.Empty;

                if (_cbUseSmtpFromTemplate.Checked)
                {
                    smtp = templater.SmtpServers[0].Host;
                }
                else
                {
                    smtp = smtpServerAddressTextbox.Text;
                }

                templater.Message.Send(smtp);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            if (_lvDataItems.Items.Count > 0)
            {
                // We prepare the data.
                // We will create a offline datatable to demonstrate , this can veru well
                // be fetched from database.

                DataSet dsOrderData = new DataSet();

                #region Create Data
                //Create a datatable
                DataTable tb = new DataTable("ORDERS");

                tb.Columns.Add("FIRSTNAME");
                tb.Columns.Add("LASTNAME");
                tb.Columns.Add("EMAIL");
                tb.Columns.Add("ORDER_ID");
                tb.Columns.Add("CUSTOMER_ID");
                tb.Columns.Add("PRODUCT");
                tb.Columns.Add("QUANTITY");

                //Create Sample set of data
                for (int i = 0; i < _lvDataItems.Items.Count; i++)
                {
                    Utils.ListRowItem lri = (Utils.ListRowItem)_lvDataItems.Items[i].Tag;

                    DataRow dr = tb.NewRow();
                    dr["FIRSTNAME"]   = lri.FirstName;
                    dr["LASTNAME"]    = lri.LastName;
                    dr["EMAIL"]       = lri.Email;
                    dr["ORDER_ID"]    = lri.OrderId;
                    dr["CUSTOMER_ID"] = i;
                    dr["PRODUCT"]     = lri.Product;
                    dr["QUANTITY"]    = lri.Quantity;
                    tb.Rows.Add(dr);
                }

                #endregion

                this.AddLogEntry("Creating templater.");

                // We create the templater object.
                ActiveUp.Net.Mail.Templater templater = new ActiveUp.Net.Mail.Templater("mailFormat_working_with_list.xml");

                // We instanciante the Merger object by passing the templater data.
                Merger merger = new Merger(templater);

                // We merge the message templates.
                merger.MergeListTemplate("PRODUCTS_TEXT", dsOrderData.Tables["ORDERS"]);
                merger.MergeListTemplate("PRODUCTS_HTML", dsOrderData.Tables["ORDERS"]);


                // We merge our message with the data.
                merger.MergeMessage(dsOrderData.Tables["ORDERS"]);

                this.AddLogEntry("Sending template message.");

                try
                {
                    // We send the mail
                    SmtpClient.Send(merger.Message, smtpServerAddressTextbox.Text);

                    this.AddLogEntry("Message sent successfully.");
                }

                catch (SmtpException ex)
                {
                    this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
                }

                catch (Exception ex)
                {
                    this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
                }
            }

            else
            {
                this.AddLogEntry("No datas defined.");
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            // Prepare the data.
            //We will create a offline datatable to demonstrate , this can veru well
            //be fetched from database.

            this.AddLogEntry("Creating the data.");

            #region Create Data

            DataSet dsOrderData = new DataSet();

            #region Create Data
            // We create a datatable
            DataTable tb = new DataTable("ORDERS");

            tb.Columns.Add("FIRSTNAME");
            tb.Columns.Add("DATE", typeof(DateTime));
            tb.Columns.Add("CODEFORMATEDDATE", typeof(DateTime));
            tb.Columns.Add("CODEFORMATEDNUMBER", typeof(float));

            // We create sample set of data
            DataRow dr = tb.NewRow();
            dr["FIRSTNAME"]          = "John";
            dr["DATE"]               = DateTime.Now;
            dr["CODEFORMATEDDATE"]   = DateTime.Now;
            dr["CODEFORMATEDNUMBER"] = 0.58;
            tb.Rows.Add(dr);
            dsOrderData.Tables.Add(tb);

            #endregion

            #endregion

            this.AddLogEntry("Creating templater.");

            try
            {
                ActiveUp.Net.Mail.Templater templater =
                    new ActiveUp.Net.Mail.Templater("mailformat_working_with_field_format.xml");

                // We instanciante the Merger object by passing the templater data.
                Merger merger = new Merger(templater);


                //Either you can specifiy the field format in the XML using <fieldformat>
                //tags are you can add the field format in the code

                merger.FieldsFormats.Add("CODEFORMATEDDATE", "{0:dd mmm yy}");
                merger.FieldsFormats.Add("CODEFORMATEDNUMBER", "{0:0#.##0}");

                // We merge our message with the data.
                merger.MergeMessage(dsOrderData.Tables[0]);

                this.AddLogEntry("Sending template message.");

                //Handle the error in case any

                merger.Message.Send(smtpServerAddressTextbox.Text);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            if (_lvDataItems.Items.Count > 0)
            {
                // We prepare the data.
                // We will create a offline datatable to demonstrate , this can veru well
                // be fetched from database.

                DataSet dsOrderData = new DataSet();

                #region Create Data
                //Create a datatable
                DataTable tb = new DataTable("ORDERS");

                tb.Columns.Add("FIRSTNAME");
                tb.Columns.Add("LASTNAME");
                tb.Columns.Add("EMAIL");
                tb.Columns.Add("ORDER_ID");
                tb.Columns.Add("CUSTOMER_ID");
                tb.Columns.Add("PRODUCT");
                tb.Columns.Add("QUANTITY");

                //Create Sample set of data
                for (int i = 0; i < _lvDataItems.Items.Count; i++)
                {
                    Utils.ListRowItem lri = (Utils.ListRowItem)_lvDataItems.Items[i].Tag;

                    DataRow dr = tb.NewRow();
                    dr["FIRSTNAME"] = lri.FirstName;
                    dr["LASTNAME"] = lri.LastName;
                    dr["EMAIL"] = lri.Email;
                    dr["ORDER_ID"] = lri.OrderId;
                    dr["CUSTOMER_ID"] = i;
                    dr["PRODUCT"] = lri.Product;
                    dr["QUANTITY"] = lri.Quantity;
                    tb.Rows.Add(dr);
                }

                #endregion

                this.AddLogEntry("Creating templater.");

                // We create the templater object.
                ActiveUp.Net.Mail.Templater templater = new ActiveUp.Net.Mail.Templater("mailFormat_working_with_list.xml");

                // We instanciante the Merger object by passing the templater data.
                Merger merger = new Merger(templater);

                // We merge the message templates.
                merger.MergeListTemplate("PRODUCTS_TEXT", dsOrderData.Tables["ORDERS"]);
                merger.MergeListTemplate("PRODUCTS_HTML", dsOrderData.Tables["ORDERS"]);


                // We merge our message with the data.
                merger.MergeMessage(dsOrderData.Tables["ORDERS"]);

                this.AddLogEntry("Sending template message.");

                try
                {
                    // We send the mail
                    merger.Message.Send(smtpServerAddressTextbox.Text);

                    this.AddLogEntry("Message sent successfully.");
                }

                catch (SmtpException ex)
                {
                    this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
                }

                catch (Exception ex)
                {
                    this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
                }
            }

            else
            {
                this.AddLogEntry("No datas defined.");
            }
        }
        private void sendMessageButton_Click(object sender, EventArgs e)
        {

            // Prepare the data.
            //We will create a offline datatable to demonstrate , this can veru well
            //be fetched from database.

            this.AddLogEntry("Creating the data.");

            #region Create Data

            DataSet dsOrderData = new DataSet();

            #region Create Data
            // We create a datatable
            DataTable tb = new DataTable("ORDERS");

            tb.Columns.Add("FIRSTNAME");
            tb.Columns.Add("DATE", typeof(DateTime));
            tb.Columns.Add("CODEFORMATEDDATE", typeof(DateTime));
            tb.Columns.Add("CODEFORMATEDNUMBER", typeof(float));

            // We create sample set of data
            DataRow dr = tb.NewRow();
            dr["FIRSTNAME"] = "John";
            dr["DATE"] = DateTime.Now;
            dr["CODEFORMATEDDATE"] = DateTime.Now;
            dr["CODEFORMATEDNUMBER"] = 0.58;
            tb.Rows.Add(dr);
            dsOrderData.Tables.Add(tb);

            #endregion

            #endregion

            this.AddLogEntry("Creating templater.");

            try
            {
                ActiveUp.Net.Mail.Templater templater =
                    new ActiveUp.Net.Mail.Templater("mailformat_working_with_field_format.xml");

                // We instanciante the Merger object by passing the templater data.
                Merger merger = new Merger(templater);


                //Either you can specifiy the field format in the XML using <fieldformat>
                //tags are you can add the field format in the code

                merger.FieldsFormats.Add("CODEFORMATEDDATE", "{0:dd mmm yy}");
                merger.FieldsFormats.Add("CODEFORMATEDNUMBER", "{0:0#.##0}");

                // We merge our message with the data.
                merger.MergeMessage(dsOrderData.Tables[0]);
                
                this.AddLogEntry("Sending template message.");

                //Handle the error in case any
            
                merger.Message.Send(smtpServerAddressTextbox.Text);

                this.AddLogEntry("Message sent successfully.");
            }

            catch (SmtpException ex)
            {
                this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
            }

            catch (Exception ex)
            {
                this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
            }
        }