Intersoft Support Center

Using Mail Merge

This walkthrough shows you how to enable mail merge with data bound collection in WebTextEditor.

During this walkthrough, you will learn how to do the following:

  • Enable mail merge
  • Bound access data source to WebTextEditor for mail merge purpose.
  • Bound custom collection to WebTextEditor for mail merge purpose.

 Prerequisites

In order to complete this walkthrough, you will need the following:

  • Visual Studio 2008/2010 Application.
  • Mail server for sending the email.
  • Northwind_Extended.mdb.

 Step-By-Step Instructions

To enable mail merge with data bound collection

  1. Launch Visual Studio.NET 2008.
  2. Click on File menu, then select New and click Web Site.
  3. Select ASP.NET Web Site in the Template box and set Location to HTTP.
  4. Named the Web Site and click OK.
  5. Right-click on App_Data folder and select Add Existing Item. Then, select Northwind_Extended.mdb from the file explorer.
  6. Right-click on Project's name and select Add New Item.
  7. Select WebForm in the My Templates box and named it as Walkthrough.aspx.
  8. Drag AccessDataSource instance from ToolBar to WebForm.
  9. Set the access data file to Northwind_Extended.mdb located in App_Data folder and select all columns from the Employees table.
  10. Drag WebTextEditor instance from ToolBar to WebForm.
  11. Set the WebTextEditor DataSourceID property to AccessDataSource control.
  12. Enable the MailMerge feature and add the required label for the mail merge in the Labels collection. The EmailField property will bind Email field from the collection. The SubjectExpression property also accepts MailMerge labels.
    Set the following properties under MailMergeSettings:
    Property Value
    AutomaticSendMail True
    EmailField Email
    EnableMailMerge True
    From hrd@northwind.com
    SMTP mail.northwind.com
    SubjectExpression Invitation for {FirstName} {Last Name}



  13. Set the Content property of the WebTextEditor under the RootTextEditor section for the Mail Merge template. For example:
    <div>
       <span>Intersoft Solutions</span>
       <br />
       <span><em>cordially invites you, <span type="mailmerge">{FirstName}</span> <span type="mailmerge">{LastName}</span>, and your family to our</em></span>
    </div>                        
                            
    The <span type="mailmerge">{FirstName}</span> will be substitute by the labels declared in the MailMerge WebTextEditor section.
  14. Set EnablePreview to true under the ViewSetting section to enable Mail Merge preview.
  15. Run the sample in Web Browser. Click the [Preview] command to preview the mail.

To enable mail merge with custom collection

  1. Launch Visual Studio.NET 2008.
  2. Click on File menu, then select New and click Web Site.
  3. Select ASP.NET Web Site in the Template box and set Location to HTTP.
  4. Named the Web Site and click OK.
  5. Right-click on Project's name and select Add New Item.
  6. Select WebForm in the My Templates box and named it as Walkthrough.aspx.
  7. Drag WebTextEditor instance from ToolBar to WebForm.
  8. Create a custom object ISEmployee in the WebForm code page. Here is the snippet:
    C# Copy Code
    public class ISEmployee
    {   
       public int EmployeeID { get; set; }   
       public string FirstName { get; set; }   
       public string LastName { get; set; }   
       public string Address { get; set; }   
       public string City { get; set; }   
       public string Country { get; set; }   
       public string Email { get; set; }
    }

  9. Create BindCustomCollection() function to bind the custom collection to the WebTextEditor control which is called during page load server-side event. Here is the snippet:
    C# Copy Code
    private void BindCustomCollection()
    {   
       List<isemployee> employees = new List<isemployee>();    
       ISEmployee emp = new ISEmployee();   
       emp.EmployeeID = 1;   
       emp.FirstName = "Nancy";   
       emp.LastName = "Davolio";   
       emp.Address = "Bridge Street";   
       emp.City = "London";   
       emp.Country = "UK";   
       emp.Email = "ndavolio@employee.com";   
       employees.Add(emp);    
    
       emp = new ISEmployee();   
       emp.EmployeeID = 2;   
       emp.FirstName = "Andrew";   
       emp.LastName = "Fuller";   
       emp.Address = "Wood Street";   
       emp.City = "Washington";   
       emp.Country = "USA";   
       emp.Email = "afuller@employee.com";   
       employees.Add(emp);    
       WebTextEditor1.MailMergeSettings.Recipients = employees;
    }
    

  10. Enable the MailMerge feature and add the required label for the mail merge in the Labels collection. The EmailField property will bind Email field from the collection. The SubjectExpression property also accepts MailMerge labels.
    Property Value
    AutomaticSendMail True
    EmailField Email
    EnableMailMerge True
    From hrd@northwind.com
    SMTP mail.northwind.com
    SubjectExpression Invitation for {FirstName} {Last Name}



  11. Set the Content property of the WebTextEditor under the RootTextEditor section for the Mail Merge template. For example:
    <div>
       <span>Intersoft Solutions</span>
       <br />
       <span><em>cordially invites you, <span type="mailmerge">{FirstName}</span> <span type="mailmerge">{LastName}</span>, and your family to our</em></span>
    </div>
    
    The <span type="mailmerge">{FirstName}</span> will be substitute by the labels declared in the MailMerge WebTextEditor section.
  12. Set EnablePreview to true under the ViewSetting section to enable Mail Merge preview.

Previous Next